Advertisement
pblnrao

GetUNC

Jan 10th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Jan 10 12:45:14 2013
  4.  
  5. @author: narasimhapbl.1863
  6. """
  7.  
  8. import os
  9. import sys
  10. import subprocess
  11.  
  12. from PyQt4 import QtGui
  13.  
  14. class test(QtGui.QMainWindow):
  15.    
  16.     def __init__(self):
  17.        
  18.         super(test,self).__init__()
  19.         self.but = QtGui.QPushButton(self)
  20.         self.but.clicked.connect(self.GetUnc)
  21.  
  22.     def GetUnc(self):
  23.        
  24.         exist,path = self.GetUncSourcePath('z')
  25.         print exist,path
  26.  
  27.     def GetUncSourcePath(self,driveLetter):
  28.        
  29.         """
  30.        
  31.        This will return the UNC () path of the network drive    
  32.        
  33.        Usage GetUncSourcePath('P:')
  34.        
  35.        """
  36.    
  37.         UNC_Path = ''
  38.        
  39.         try:
  40.  
  41.             DriveToCheck = driveLetter[:1]
  42.            
  43.             if os.path.exists('%s:' % DriveToCheck):
  44.                 print 'checking %s: drive' % DriveToCheck
  45.                 process = subprocess.Popen(["net use","%s:" % DriveToCheck],stdout=subprocess.PIPE,shell=True)
  46.                 out,err = process.communicate()
  47.                 splitLines = out.splitlines()
  48.                 LineSplit = splitLines[1].split()          
  49.                 UNC_Path = LineSplit[2]
  50.                
  51.                 return (True,UNC_Path)
  52.                
  53.             else:
  54.    
  55.                 QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Drive Error','Drive Not Exists')
  56.                 return (False,None)
  57.                            
  58.         except Exception as ex:
  59.            
  60.             QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Drive Error',ex.message)
  61.             return (False,None)
  62.  
  63. if __name__=='__main__':
  64.     app = QtGui.QApplication(sys.argv)
  65.     win = test()
  66.     win.show()
  67.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement