4
4
import os
5
5
import six
6
6
import sys
7
+ import yaml
7
8
8
9
from six .moves import getcwd
9
10
@@ -92,20 +93,34 @@ def main():
92
93
parser .add_argument ("-dt" , "--date" , action = 'store_true' ,
93
94
help = "Organize files by creation date" )
94
95
96
+ parser .add_argument ("-c" , "--config" , type = str ,
97
+ help = "Config file" )
98
+
95
99
args = parser .parse_args ()
96
100
97
- formats = {
98
- 'Music' : ['.mp3' , '.aac' , '.flac' , '.ogg' , '.wma' , '.m4a' , '.aiff' , '.wav' , '.amr' ],
99
- 'Videos' : ['.flv' , '.ogv' , '.avi' , '.mp4' , '.mpg' , '.mpeg' , '.3gp' , '.mkv' , '.ts' , '.webm' , '.vob' , '.wmv' ],
100
- 'Pictures' : ['.png' , '.jpeg' , '.gif' , '.jpg' , '.bmp' , '.svg' , '.webp' , '.psd' , '.tiff' ],
101
- 'Archives' : ['.rar' , '.zip' , '.7z' , '.gz' , '.bz2' , '.tar' , '.dmg' , '.tgz' , '.xz' , '.iso' , '.cpio' ],
102
- 'Documents' : ['.txt' , '.pdf' , '.doc' , '.docx' ,'.odf' , '.xls' , '.xlsv' , '.xlsx' ,
101
+ if args .config :
102
+ conf_file_name = os .path .expanduser (args .config )
103
+ else :
104
+ conf_file_name = os .getenv ("HOME" ) + "/.config/.classify.conf"
105
+
106
+ if os .path .exists (conf_file_name ):
107
+ with open (conf_file_name , "r" ) as conf_file :
108
+ formats = yaml .load (conf_file )
109
+ else :
110
+ formats = {
111
+ 'Music' : ['.mp3' , '.aac' , '.flac' , '.ogg' , '.wma' , '.m4a' , '.aiff' , '.wav' , '.amr' ],
112
+ 'Videos' : ['.flv' , '.ogv' , '.avi' , '.mp4' , '.mpg' , '.mpeg' , '.3gp' , '.mkv' , '.ts' , '.webm' , '.vob' , '.wmv' ],
113
+ 'Pictures' : ['.png' , '.jpeg' , '.gif' , '.jpg' , '.bmp' , '.svg' , '.webp' , '.psd' , '.tiff' ],
114
+ 'Archives' : ['.rar' , '.zip' , '.7z' , '.gz' , '.bz2' , '.tar' , '.dmg' , '.tgz' , '.xz' , '.iso' , '.cpio' ],
115
+ 'Documents' : ['.txt' , '.pdf' , '.doc' , '.docx' ,'.odf' , '.xls' , '.xlsv' , '.xlsx' ,
103
116
'.ppt' , '.pptx' , '.ppsx' , '.odp' , '.odt' , '.ods' , '.md' , '.json' , '.csv' ],
104
- 'Books' : ['.mobi' , '.epub' , '.chm' ],
105
- 'DEBPackages' : ['.deb' ],
106
- 'Programs' : ['.exe' , '.msi' ],
107
- 'RPMPackages' : ['.rpm' ]
108
- }
117
+ 'Books' : ['.mobi' , '.epub' , '.chm' ],
118
+ 'DEBPackages' : ['.deb' ],
119
+ 'Programs' : ['.exe' , '.msi' ],
120
+ 'RPMPackages' : ['.rpm' ]
121
+ }
122
+ with open (conf_file_name , 'w' ) as conf_file :
123
+ yaml .safe_dump (formats , conf_file )
109
124
110
125
if bool (args .specific_folder ) ^ bool (args .specific_types ):
111
126
print (
@@ -126,7 +141,7 @@ def main():
126
141
else :
127
142
directory = _format_arg (args .directory )
128
143
if args .output is None :
129
- ''' if -d arg given without the -o arg, keeping the files of -d
144
+ ''' if -d arg given without the -o arg, keeping the files of -d
130
145
in the -d path only after classifying '''
131
146
output = directory
132
147
0 commit comments