@@ -60,10 +60,15 @@ def __init__(self):
60
60
self .parser .add_argument ("-t" , "--types" , action = 'store_true' ,
61
61
help = "Show the current list of types and formats" )
62
62
63
+ self .parser .add_argument ("-rst" , "--reset" , action = 'store_true' ,
64
+ help = "Reset the default Config file" )
65
+
66
+ """
63
67
self.parser.add_argument("-r", "--recursive", action='store_true',
64
68
help="Recursively search your source directory. " +
65
69
"WARNING: Ensure you use the correct path as this " +
66
70
"WILL move all files from your selected types.")
71
+ """
67
72
68
73
self .parser .add_argument ("-st" , "--specific-types" , type = str , nargs = '+' ,
69
74
help = "Move all file extensions, given in the args list, " +
@@ -91,27 +96,33 @@ def __init__(self):
91
96
self .checkconfig ()
92
97
self .run ()
93
98
99
+ def create_default_config (self ):
100
+ with open (CONFIG , "w" ) as conffile :
101
+ conffile .write ("IGNORE: part, desktop\n " +
102
+ "Music: mp3, aac, flac, ogg, wma, m4a, aiff, wav, amr\n " +
103
+ "Videos: flv, ogv, avi, mp4, mpg, mpeg, 3gp, mkv, ts, webm, vob, wmv\n " +
104
+ "Pictures: png, jpeg, gif, jpg, bmp, svg, webp, psd, tiff\n " +
105
+ "Archives: rar, zip, 7z, gz, bz2, tar, dmg, tgz, xz, iso, cpio\n " +
106
+ "Documents: txt, pdf, doc, docx, odf, xls, xlsv, xlsx, " +
107
+ "ppt, pptx, ppsx, odp, odt, ods, md, json, csv\n " +
108
+ "Books: mobi, epub, chm\n " +
109
+ "DEBPackages: deb\n " +
110
+ "Programs: exe, msi\n " +
111
+ "RPMPackages: rpm" )
112
+ print ("CONFIG file created at: " + CONFIG )
113
+
94
114
def checkconfig (self ):
95
115
""" create a default config if not available """
96
116
if not os .path .isdir (os .path .dirname (CONFIG )):
97
117
os .makedirs (os .path .dirname (CONFIG ))
98
118
if not os .path .isfile (CONFIG ):
99
- conffile = open (CONFIG , "w" )
100
- conffile .write ("IGNORE:.part,.desktop\n " +
101
- "Music:.mp3,.aac,.flac,.ogg,.wma,.m4a,.aiff,.wav,.amr\n " +
102
- "Videos:.flv,.ogv,.avi,.mp4,.mpg,.mpeg,.3gp,.mkv,.ts,.webm,.vob,.wmv\n " +
103
- "Pictures:.png,.jpeg,.gif,.jpg,.bmp,.svg,.webp,.psd,.tiff\n " +
104
- "Archives:.rar,.zip,.7z,.gz,.bz2,.tar,.dmg,.tgz,.xz,.iso,.cpio\n " +
105
- "Documents:.txt,.pdf,.doc,.docx,.odf,.xls,.xlsv,.xlsx," +
106
- ".ppt,.pptx,.ppsx,.odp,.odt,.ods,.md,.json,.csv\n " +
107
- "Books:.mobi,.epub,.chm\n " +
108
- "DEBPackages:.deb\n " +
109
- "Programs:.exe,.msi\n " +
110
- "RPMPackages:.rpm" )
111
- conffile .close ()
119
+ self .create_default_config ()
120
+
112
121
with open (CONFIG , 'r' ) as file :
113
122
for items in file :
114
- (key , val ) = items .replace ('\n ' , '' ).split (':' )
123
+ spl = items .replace ('\n ' , '' ).split (':' )
124
+ key = spl [0 ].replace (" " ,"" )
125
+ val = spl [1 ].replace (" " ,"" )
115
126
self .formats [key ] = val
116
127
return
117
128
@@ -120,7 +131,7 @@ def moveto(self, filename, from_folder, to_folder):
120
131
to_file = os .path .join (to_folder , filename )
121
132
# to move only files, not folders
122
133
if not to_file == from_file :
123
- print (' moving:' , to_file )
134
+ print ('moved: ' + str ( to_file ) )
124
135
if os .path .isfile (from_file ):
125
136
if not os .path .exists (to_folder ):
126
137
os .makedirs (to_folder )
@@ -133,7 +144,7 @@ def classify(self, formats, output, directory):
133
144
# set up a config per folder
134
145
if not file == DIRCONFFILE and os .path .isfile (os .path .join (directory , file )):
135
146
filename , file_ext = os .path .splitext (file )
136
- file_ext = file_ext .lower ()
147
+ file_ext = file_ext .lower (). replace ( '.' , '' )
137
148
if 'IGNORE' in self .formats :
138
149
for ignored in self .formats ['IGNORE' ].replace ('\n ' , '' ).split (',' ):
139
150
if file_ext == ignored :
@@ -152,9 +163,10 @@ def classify(self, formats, output, directory):
152
163
self .moveto (file , directory , folder )
153
164
except Exception as e :
154
165
print ('Cannot move file - {} - {}' .format (file , str (e )))
166
+ """
155
167
elif os.path.isdir(os.path.join(directory, file)) and self.args.recursive:
156
168
self.classify(self.formats, output, os.path.join(directory, file))
157
-
169
+ """
158
170
return
159
171
160
172
def classify_by_date (self , date_format , output , directory ):
@@ -169,7 +181,6 @@ def classify_by_date(self, date_format, output, directory):
169
181
folder = os .path .join (output , folder )
170
182
self .moveto (file , directory , folder )
171
183
172
- print ("Done!" )
173
184
return
174
185
175
186
def _format_text_arg (self , arg ):
@@ -186,13 +197,15 @@ def _format_arg(self, arg):
186
197
def run (self ):
187
198
if self .args .version :
188
199
# Show version information and quit
189
- print (VERSION + ' \n ' + os . path . realpath ( __file__ ) )
200
+ print (VERSION )
190
201
return False
202
+
191
203
if self .args .types :
192
204
# Show file format information then quit
193
205
for key , value in self .formats .items ():
194
- print (key , ' \n ' , value )
206
+ print (key + ': ' + value )
195
207
return False
208
+
196
209
if self .args .edittypes :
197
210
if PLATFORM == 'darwin' :
198
211
subprocess .call (('open' , CONFIG ))
@@ -201,6 +214,11 @@ def run(self):
201
214
elif PLATFORM == 'linux' or PLATFORM == 'linux2' or OS == 'posix' :
202
215
subprocess .Popen (['xdg-open' , CONFIG ])
203
216
return False
217
+
218
+ if self .args .reset :
219
+ self .create_default_config ()
220
+ return
221
+
204
222
if bool (self .args .specific_folder ) ^ bool (self .args .specific_types ):
205
223
print (
206
224
'Specific Folder and Specific Types need to be specified together' )
@@ -231,6 +249,12 @@ def run(self):
231
249
elif os .path .isfile (os .path .join (os .getcwd (), DIRCONFFILE )):
232
250
self .dirconf = os .path .join (os .getcwd (), DIRCONFFILE )
233
251
252
+ if self .args .dateformat :
253
+ if not self .args .date :
254
+ print (
255
+ 'Dateformat -df must be given alongwith date -dt option' )
256
+ sys .exit ()
257
+
234
258
if self .args .date :
235
259
if self .args .dateformat :
236
260
self .classify_by_date (self .args .dateformat , output , directory )
@@ -256,8 +280,7 @@ def run(self):
256
280
return False
257
281
else :
258
282
print ("\n Scanning Folder: " + directory +
259
- "\n For: " + str (self .formats .items ()) +
260
- '\n Recursive: ' + str (self .args .recursive ))
283
+ "\n For: " + str (self .formats .items ()))
261
284
self .classify (self .formats , output , directory )
262
285
263
286
print ("Done!\n " )
0 commit comments