Пример #1
0
 def encode_name(self, name):
     if not self.has_attr(DirEntry.ATTR_DIR):
         mo = re.match(r'^(.*)\.(\w{3})$', name)
         if mo:
             n, e = mo.groups()
             self.shortname = encode_path(n[:8].ljust(8))
             self.shortext = encode_path(e)
     else:
         self.set_name(encode_path(name))
Пример #2
0
 def add_directory(self,path):
     cut = len(path)
     mdate, mtime = time_conv_from_local(os.path.getmtime(path))
     self.set_voldate(mdate)
     self.set_voltime(mtime)
     for root, dirs, files in os.walk(path):
         newroot = root[cut:].replace('/','\\')
         for orig,dn in [ (d,newroot + '\\' + d)
                          for d in sorted(dirs,reverse=True) ]:
             path  = os.path.join(root,orig)
             mdate, mtime = time_conv_from_local(os.path.getmtime(path))
             if self.debug: print("Adding dir  '%s'" % dn)
             self.mkdir(encode_path(dn),mdate=mdate,mtime=mtime)
         for orig,fn in [ (f,newroot + '\\' + f)
                          for f in sorted(files,reverse=True) ]:
             path = os.path.join(root,orig)
             mdate, mtime = time_conv_from_local(os.path.getmtime(path))
             with open(path,'rb') as f:
                 if self.debug: print("Adding file '%s'" % fn)
                 self.copy(encode_path(fn),f.read(),mdate=mdate,mtime=mtime)
Пример #3
0
 def find_file(self,path):
     path = encode_path(path)
     segments = path.split('\\')
     if len(segments) and segments[0] == 'A:': segments = segments[1:]
     if not len(segments):
         raise S3Exception("findFile: malformed file path '%s'" % path)
     dircluster = None
     while True:
         dirs, files = self.read_dir(dircluster)
         if len(segments) > 1:
             for d in dirs:
                 if d.decoded_name() == segments[0]:
                     segments = segments[1:]
                     dircluster = d.start
                     break
             else: return None
         else:
             for f in files:
                 if f.decoded_name() == segments[0]:
                     return f
             else: return None