Skip to content

Commit 9e22d4c

Browse files
committed
Add config file to define formats
1 parent 31c808f commit 9e22d4c

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

classifier/classifier.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import six
66
import sys
7+
import yaml
78

89
from six.moves import getcwd
910

@@ -92,20 +93,34 @@ def main():
9293
parser.add_argument("-dt", "--date", action='store_true',
9394
help="Organize files by creation date")
9495

96+
parser.add_argument("-c", "--config", type=str,
97+
help="Config file")
98+
9599
args = parser.parse_args()
96100

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',
103116
'.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)
109124

110125
if bool(args.specific_folder) ^ bool(args.specific_types):
111126
print(
@@ -126,7 +141,7 @@ def main():
126141
else:
127142
directory = _format_arg(args.directory)
128143
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
130145
in the -d path only after classifying '''
131146
output = directory
132147

0 commit comments

Comments
 (0)