freemyipod r406 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r405‎ | r406 | r407 >
Date:04:29, 2 January 2011
Author:theseven
Status:new
Tags:
Comment:
embios.py: Add recursive file system access functions
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -947,6 +947,24 @@
948948 self.logger.info(" done\n")
949949
950950 @command
 951+ def rmtree(self, path):
 952+ """
 953+ Recursively removes a folder
 954+ <path>: the folder to be removed
 955+ """
 956+ handle = self.embios.dir_open(path)
 957+ while True:
 958+ try:
 959+ entry = self.embios.dir_read(handle)
 960+ if entry.name == "." or entry.name == "..": continue
 961+ elif entry.attributes & 0x10:
 962+ self.rmtree(path + "/" + entry.name)
 963+ else: self.rm(path + "/" + entry.name)
 964+ except: break
 965+ self.embios.dir_close(handle)
 966+ self.rmdir(path)
 967+
 968+ @command
951969 def mv(self, oldname, newname):
952970 """
953971 Renames or moves file or directory <oldname> to <newname>
@@ -983,11 +1001,37 @@
9841002 self.logger.info(" done\n")
9851003
9861004 @command
 1005+ def gettree(self, remotepath, localpath, buffer = False, buffsize = "10000"):
 1006+ """
 1007+ Downloads a directory tree
 1008+ <remotepath>: path on the device
 1009+ <localpath>: path on the computer
 1010+ [buffer]: buffer address (optional)
 1011+ [buffsize]: buffer size (optional)
 1012+ """
 1013+ if buffer == False: buffer = self.embios.lib.dev.usermem.lower
 1014+ else: buffer = self._hexint(buffer)
 1015+ buffsize = self._hexint(buffsize)
 1016+ try: os.mkdir(localpath)
 1017+ except: pass
 1018+
 1019+ handle = self.embios.dir_open(remotepath)
 1020+ while True:
 1021+ try:
 1022+ entry = self.embios.dir_read(handle)
 1023+ if entry.name == "." or entry.name == "..": continue
 1024+ elif entry.attributes & 0x10:
 1025+ self.gettree(remotepath + "/" + entry.name, localpath + "/" + entry.name, buffer, buffsize)
 1026+ else: self.get(remotepath + "/" + entry.name, localpath + "/" + entry.name, buffer, buffsize)
 1027+ except: break
 1028+ self.embios.dir_close(handle)
 1029+
 1030+ @command
9871031 def put(self, localname, remotename, buffer = False, buffsize = "10000"):
9881032 """
9891033 Uploads a file
 1034+ <localname>: filename on the computer
9901035 <remotename>: filename on the device
991 - <localname>: filename on the computer
9921036 [buffer]: buffer address (optional)
9931037 [buffsize]: buffer size (optional)
9941038 """
@@ -1012,6 +1056,31 @@
10131057 self.logger.info(" done\n")
10141058
10151059 @command
 1060+ def puttree(self, localpath, remotepath, buffer = False, buffsize = "10000"):
 1061+ """
 1062+ Uploads a directory tree
 1063+ <localpath>: path on the computer
 1064+ <remotepath>: path on the device
 1065+ [buffer]: buffer address (optional)
 1066+ [buffsize]: buffer size (optional)
 1067+ """
 1068+ if buffer == False: buffer = self.embios.lib.dev.usermem.lower
 1069+ else: buffer = self._hexint(buffer)
 1070+ buffsize = self._hexint(buffsize)
 1071+ try: self.mkdir(remotepath)
 1072+ except: pass
 1073+ pathlen = len(localpath)
 1074+ for d in os.walk(localpath):
 1075+ prefix = remotepath + "/" + d[0].replace("\\", "/")[pathlen:] + "/"
 1076+ for dir in d[1]:
 1077+ if dir != ".svn":
 1078+ try: self.mkdir(prefix + dir)
 1079+ except: pass
 1080+ for f in d[2]:
 1081+ if not prefix.find("/.svn/") > -1:
 1082+ self.put(d[0] + "/" + f, prefix + f, buffer, buffsize)
 1083+
 1084+ @command
10161085 def ls(self, path = "/"):
10171086 """
10181087 Lists all files in the specified path