python-adfs
changeset 41:1e7b537eb567
Moved the disc/directory name check into the create_directory method of
the ADFSdisc class. Directories are now created before files are written
at a given level in the directory structure rather than upon discovery of a
lower level.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Tue Apr 15 23:40:58 2003 +0200 |
| parents | edbb8aea6b29 |
| children | 4f59a14ed25b |
| files | ADFSlib.py |
| diffstat | 1 files changed, 41 insertions(+), 28 deletions(-) [+] |
line diff
1.1 --- a/ADFSlib.py Tue Apr 15 23:39:36 2003 +0200 1.2 +++ b/ADFSlib.py Tue Apr 15 23:40:58 2003 +0200 1.3 @@ -1034,9 +1034,20 @@ 1.4 1.5 def extract_old_files(self, l, path, filetypes = 0, separator = ","): 1.6 1.7 + new_path = self.create_directory(path) 1.8 + 1.9 + if new_path != "": 1.10 + 1.11 + path = new_path 1.12 + 1.13 + else: 1.14 + 1.15 + return 1.16 + 1.17 for i in l: 1.18 1.19 name = i[0] 1.20 + 1.21 if type(i[1]) != type([]): 1.22 1.23 # A file. 1.24 @@ -1055,7 +1066,7 @@ 1.25 out.write(i[1]) 1.26 out.close() 1.27 except IOError: 1.28 - print "Couldn't open the file, %s" % out_file 1.29 + print "Couldn't open the file: %s" % out_file 1.30 1.31 try: 1.32 inf = open(inf_file, "w") 1.33 @@ -1064,7 +1075,7 @@ 1.34 ( name, load, exec_addr, length ) ) 1.35 inf.close() 1.36 except IOError: 1.37 - print "Couldn't open the file, %s" % inf_file 1.38 + print "Couldn't open the file: %s" % inf_file 1.39 1.40 else: 1.41 1.42 @@ -1077,26 +1088,30 @@ 1.43 out.write(i[1]) 1.44 out.close() 1.45 except IOError: 1.46 - print "Couldn't open the file, %s" % out_file 1.47 + print "Couldn't open the file: %s" % out_file 1.48 else: 1.49 1.50 - if name != '$': 1.51 + new_path = os.path.join(path, name) 1.52 1.53 - new_path = self.create_directory(path, name) 1.54 - 1.55 - if new_path != "": 1.56 - 1.57 - self.extract_old_files(i[1], new_path, filetypes) 1.58 - 1.59 - else: 1.60 - self.extract_old_files(i[1], path, filetypes) 1.61 + self.extract_old_files(i[1], new_path, filetypes) 1.62 1.63 1.64 def extract_new_files(self, l, path, filetypes = 0, separator = ","): 1.65 1.66 + new_path = self.create_directory(path) 1.67 + 1.68 + if new_path != "": 1.69 + 1.70 + path = new_path 1.71 + 1.72 + else: 1.73 + 1.74 + return 1.75 + 1.76 for i in l: 1.77 1.78 name = i[0] 1.79 + 1.80 if type(i[1]) != type([]): 1.81 1.82 # A file. 1.83 @@ -1115,7 +1130,7 @@ 1.84 out.write(i[1]) 1.85 out.close() 1.86 except IOError: 1.87 - print "Couldn't open the file, %s" % out_file 1.88 + print "Couldn't open the file: %s" % out_file 1.89 1.90 try: 1.91 inf = open(inf_file, "w") 1.92 @@ -1124,7 +1139,7 @@ 1.93 ( name, load, exec_addr, length ) ) 1.94 inf.close() 1.95 except IOError: 1.96 - print "Couldn't open the file, %s" % inf_file 1.97 + print "Couldn't open the file: %s" % inf_file 1.98 else: 1.99 1.100 # Interpret the load address as a filetype. 1.101 @@ -1136,19 +1151,13 @@ 1.102 out.write(i[1]) 1.103 out.close() 1.104 except IOError: 1.105 - print "Couldn't open the file, %s" % out_file 1.106 + print "Couldn't open the file: %s" % out_file 1.107 else: 1.108 1.109 - if name != '$': 1.110 + new_path = os.path.join(path, name) 1.111 1.112 - new_path = self.create_directory(path, name) 1.113 - 1.114 - if new_path != "": 1.115 - 1.116 - self.extract_new_files(i[1], new_path, filetypes) 1.117 - 1.118 - else: 1.119 - self.extract_new_files(i[1], path, filetypes) 1.120 + self.extract_new_files(i[1], new_path, filetypes) 1.121 + 1.122 1.123 def extract_files(self, out_path, files = None, filetypes = 0, 1.124 separator = ","): 1.125 @@ -1173,12 +1182,16 @@ 1.126 1.127 self.extract_old_files(files, out_path, filetypes) 1.128 1.129 - def create_directory(self, path, name): 1.130 + def create_directory(self, path, name = None): 1.131 1.132 - elements = list(os.path.split(path)) + [name] 1.133 + elements = list(os.path.split(path)) 1.134 1.135 - # Remove any empty list elements. 1.136 - elements = filter(lambda x: x != '', elements) 1.137 + if name is not None: 1.138 + 1.139 + elements.append(name) 1.140 + 1.141 + # Remove any empty list elements or those containing a $ character. 1.142 + elements = filter(lambda x: x != '' and x != "$", elements) 1.143 1.144 try: 1.145
