예제 #1
0
파일: import.py 프로젝트: ejrh/filesys
 def get_list(self, path):
     list = []
     
     if path in ['']:
         item = Item()
         item.name = self.hostname
         item.path = '/' + self.hostname
         item.actual_path = '/'
         item.is_dir = True
         item.is_drive = True
         item.total_space,item.free_space = None,None
         list.append(item)
         return list
     
     if  WINDOWS and path == '/' + self.hostname:
         for i in range(ord('A'), ord('Z')+1):
             item = Item()
             item.name = chr(i) + ':'
             item.path = '/' + self.hostname + '/' + chr(i) + ':'
             item.actual_path = chr(i) + ':' + '/'
             item.is_dir = True
             item.is_drive = True
             
             # If it's a drive, try to get drive info.
             if item.is_drive:
                 try:
                     import win32file
                     dummy,item.total_space,item.free_space = win32file.GetDiskFreeSpaceEx(item.actual_path)
                 except:
                     item.total_space,item.free_space = None,None
             
             list.append(item)
         return list
     
     actual_path = path[len('/' + self.hostname):]
     if WINDOWS:
         if self.drive_re.search(actual_path):
             actual_path = actual_path + '/'
         if self.leading_slash_re.search(actual_path):
             actual_path = actual_path[1:]
     
     if actual_path == '':
         actual_path = '/'
     
     try:
         l = os.listdir(actual_path)
     except OSError, inst:
         exception_info("Couldn't list directory '%s'" % actual_path, inst)
         return []
예제 #2
0
파일: import.py 프로젝트: ejrh/filesys
 def get_file_md5(self, path):
     try:
         fd = open(path, 'rb')
         m = hashlib.md5()
         BUFSIZE = 65536
         while True:
             buf = fd.read(BUFSIZE)
             m.update(buf)
             if len(buf) == 0:
                 break
         fd.close()
         return m.hexdigest()
     except Exception, inst:
         exception_info("Failed getting MD5 of %s" % path, inst)
         return None