summaryrefslogtreecommitdiffstats
path: root/report/code/combox-2to3.diff
blob: 1004037283161aa7875929222411f5c1994de946 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
--- combox/_version.py	(original)
+++ combox/_version.py	(refactored)
@@ -18,8 +18,8 @@
 #   along with Combox (see COPYING).  If not, see
 #   <http://www.gnu.org/licenses/>.
 
-__version__ = u"0.2"
-__release__ = u"2"
+__version__ = "0.2"
+__release__ = "2"
 
 
 def get_version():
--- combox/config.py	(original)
+++ combox/config.py	(refactored)
@@ -84,7 +84,7 @@
 
     prompt = "%s: "  % (prompt)
 
-    return raw_input(prompt)
+    return input(prompt)
 
 
 def config_cb(config_dir = path.join(expanduser("~"), '.combox'),
@@ -143,7 +143,7 @@
 
     if not path.exists(config_dir):
         # Create combox config directory.
-        os.mkdir(config_dir, 0700)
+        os.mkdir(config_dir, 0o700)
 
     if not path.exists(config_info['combox_dir']):
         # Create combox directory.
@@ -171,7 +171,7 @@
     """
     nodes = []
 
-    for node in config['nodes_info'].itervalues():
+    for node in config['nodes_info'].values():
         node_path = path.abspath(node['path'])
         nodes.append(node_path)
 
--- combox/crypto.py	(original)
+++ combox/crypto.py	(refactored)
@@ -178,7 +178,7 @@
     rel_path = relative_path(fpath, config)
 
     # no. of shards = no. of nodes.
-    SHARDS = len(config['nodes_info'].keys())
+    SHARDS = len(list(config['nodes_info'].keys()))
 
     f = path.join(config['combox_dir'], rel_path)
 
--- combox/events.py	(original)
+++ combox/events.py	(refactored)
@@ -135,7 +135,7 @@
 
         # Remove information about files that were deleted.
         fpath_filter = lambda x: x not in self.silo.nodedicts()
-        fpaths = filter(fpath_filter, self.silo.keys())
+        fpaths = list(filter(fpath_filter, list(self.silo.keys())))
 
         for fpath in fpaths:
             if not path.exists(fpath):
@@ -336,7 +336,7 @@
                 # event; we're tracking this behaviour and ignoring
                 # the 'file modified' event.
                 #
-                if (self.just_created.has_key(event.src_path) and
+                if (event.src_path in self.just_created and
                     self.just_created[event.src_path] and
                     platform.system() == 'Linux'):
                     self.just_created[event.src_path] = False
@@ -476,7 +476,7 @@
         # deleted.
         # Remove information about files that were deleted.
         fpath_filter = lambda x: x not in self.silo.nodedicts()
-        fpaths = filter(fpath_filter, self.silo.keys())
+        fpaths = list(filter(fpath_filter, list(self.silo.keys())))
 
         for fpath in fpaths:
             del_num = 0
@@ -522,7 +522,7 @@
                         else:
                             files_created[file_cb_path] += 1
 
-        for f_cb_path, crt_num in files_created.items():
+        for f_cb_path, crt_num in list(files_created.items()):
             if crt_num == self.num_nodes:
                 log_i("%s was created remotely. Creating it locally now..." %
                       f_cb_path)
@@ -663,7 +663,7 @@
                 else:
                     try:
                         os.renames(src_cb_path, dest_cb_path)
-                    except OSError, e:
+                    except OSError as e:
                         log_e("Jeez, failed to rename path. %r" % e)
                     self.silo.node_rem(silo_node_dict, src_cb_path)
 
@@ -859,7 +859,7 @@
             # tracking this behaviour and ignoring the 'file modified'
             # event.
             #
-            if (self.just_created.has_key(event.src_path) and
+            if (event.src_path in self.just_created and
                 self.just_created[event.src_path] and
                 platform.system() == 'Linux'):
                 self.just_created[event.src_path] = False
--- combox/file.py	(original)
+++ combox/file.py	(refactored)
@@ -58,7 +58,7 @@
 
     if directory is None:
         err_msg = "invalid path %s" % p
-        raise ValueError, err_msg
+        raise ValueError(err_msg)
 
     return p.partition(directory)[2]
 
@@ -192,7 +192,7 @@
     """
     try:
         os.mkdir(directory)
-    except OSError, e:
+    except OSError as e:
         log_e("Error when trying to make directory %s" % directory)
 
 
@@ -227,7 +227,7 @@
         elif path.isdir(fpath):
             purge_dir(fpath)
             os.rmdir(fpath)
-    except OSError, e:
+    except OSError as e:
         log_e("Error when trying to remove path %s" % fpath)
 
 
@@ -253,7 +253,7 @@
         dest_dir_path = path.join(node, dest_rel_path)
         try:
             os.renames(src_dir_path, dest_dir_path)
-        except OSError, e:
+        except OSError as e:
             log_e("Error when trying to rename %s -> %s" % (src_dir_path, dest_dir_path))
 
 
@@ -284,7 +284,7 @@
         shard = shard_glob[0]
         try:
             os.remove(shard)
-        except OSError, e:
+        except OSError as e:
             log_e("Error when trying to remove shard %s" % shard)
 
 
@@ -325,7 +325,7 @@
                                      shard_no)
         try:
             os.renames(src_shard, dest_shard)
-        except OSError, e:
+        except OSError as e:
             log_e("Error when trying to rename shard %s -> %s" % (src_shard, dest_shard))
 
 
--- combox/gui.py	(original)
+++ combox/gui.py	(refactored)
@@ -20,12 +20,12 @@
 
 import os
 
-import tkFileDialog
+import tkinter.filedialog
 
 from os import path
 from os.path import expanduser
 
-from Tkinter import *
+from tkinter import *
 
 from combox.config import config_cb
 
@@ -165,7 +165,7 @@
 
         .. _Formatted string: https://docs.python.org/2/library/stdtypes.html#string-formatting
         """
-        print type(args), args
+        print(type(args), args)
         self.status_bar.config(text=format % args)
         self.status_bar.update_idletasks()
 
@@ -284,14 +284,14 @@
             return False
 
         # validate node paths
-        for i in xrange(len(self.node_path_entries)):
+        for i in range(len(self.node_path_entries)):
             if not self.node_path_entries[i].get():
                 self.status_bar_set("%s %d", "give the path for node", i)
                 self.node_path_entries[i].focus_set()
                 return False
 
         # validate node sizes
-        for i in xrange(len(self.node_size_entries)):
+        for i in range(len(self.node_size_entries)):
             if not self.node_size_entries[i].get():
                 self.status_bar_set("%s %d", "give the size of node", i)
                 self.node_size_entries[i].focus_set()
@@ -323,13 +323,13 @@
         config_info = [combox_name, combox_dir, '',  no_nodes]
 
         # get info about nodes.
-        for i in xrange(len(self.node_path_entries)):
+        for i in range(len(self.node_path_entries)):
             config_info.append("node_%d" % i)
             config_info.append(self.node_path_entries[i].get())
             config_info.append(self.node_size_entries[i].get())
 
         config_info_iter = iter(config_info)
-        def_input = lambda(x): next(config_info_iter)
+        def_input = lambda x: next(config_info_iter)
         def_pass = lambda: passp
 
         config_cb(config_dir=self.config_dir,
@@ -367,7 +367,7 @@
         entry.delete(0, 'end')
 
         # spawn dialog to choose directory.
-        dir_path = tkFileDialog.askdirectory()
+        dir_path = tkinter.filedialog.askdirectory()
         entry.insert(0, dir_path)
 
 
@@ -376,7 +376,7 @@
 
         """
 
-        for i in xrange(len(self.node_path_labels)):
+        for i in range(len(self.node_path_labels)):
            self.node_path_labels[i].destroy()
            self.node_path_entries[i].destroy()
            self.node_size_labels[i].destroy()
@@ -416,7 +416,7 @@
             # information" before; get rid of 'em.
             self.clear_node_info_fields()
 
-        for i in xrange(no_nodes):
+        for i in range(no_nodes):
             node_path_str = 'node %d path' % i
             node_size_str = 'node %d size (in mega bytes)' % i
             
--- combox/silo.py	(original)
+++ combox/silo.py	(refactored)
@@ -109,7 +109,7 @@
         # instead of PickleDB
         self.reload()
         with self.lock:
-            return self.db.db.keys()
+            return list(self.db.db.keys())
 
 
     def remove(self, filep):
@@ -128,7 +128,7 @@
             self.reload()
             with self.lock:
                 return self.db.rem(filep)
-        except KeyError, e:
+        except KeyError as e:
             # means `filep' not present in db.
             return False
 
@@ -209,7 +209,7 @@
             try:
                 num = self.db.dget(type_, file_)
                 num += 1
-            except KeyError, e:
+            except KeyError as e:
                 # I don't think this is the right way to do this. :|
                 #
                 # If we are here it means file_ is not already there,
@@ -252,7 +252,7 @@
         with self.lock:
             try:
                 return self.db.dget(type_, file_)
-            except KeyError, e:
+            except KeyError as e:
                 # file_ info not there under type_ dict.
                 return None
 
@@ -272,7 +272,7 @@
         with self.lock:
             try:
                 return self.db.dpop(type_, file_)
-            except KeyError, e:
+            except KeyError as e:
                 # means file_'s info was already removed.
                 # do nothing
                 pass