Add metavar for targetpath
[ordnung.git] / ordnung.py
blobaa9d3e41cb1ec8b8ad974e8f9401287ffaaddfbe
1 from path import path
2 import fnmatch
3 import os, sys
5 from optparse import OptionParser
6 from tag_wrapper import tag
8 ACCEPTEXTS = [".ogg"] # Keep it simple for now
10 def issupportedfile(name):
11 for ext in ACCEPTEXTS:
12 if os.path.splitext(name)[1] == ext:
13 return True
14 return False
16 def newpath(file, target, pattern):
17 # Create the tokens dictionary
18 tokens = {}
19 tags = tag(file)
20 # TODO: add tracknumber, disknumber and possibily compilation
21 for t in ["title", "artist", "album artist", "album", "composer", "genre", "date"]:
22 try:
23 tokens[t] = tags[t]
24 except KeyError:
25 tokens[t] = None
26 # %album artist% is %artist% if nothing can be found in the tags
27 if tokens["album artist"] == None:
28 tokens["album artist"] = tokens["artist"]
30 # That appears in no tag
31 tokens["base"] = target
33 def main():
34 # Handle arguments
35 parser = OptionParser()
36 parser.add_option("-r", "--recursive", action="store_true",
37 parser.add_option("-t", "--target", dest="targetpath", metavar="TARGET",
38 dest="recursive", default=False)
39 help="create new directory structure in directory TARGET (default=directory)") #TODO: not implemented
40 (options, args) = parser.parse_args()
42 try:
43 base = args[0]
44 except IndexError:
45 print "You must specify a directory"
46 sys.exit()
48 basepath = path(base)
49 if options.recursive:
50 walkme = basepath.walkfiles()
51 else:
52 walkme = basepath.files()
53 for filepath in walkme:
54 if issupportedfile(filepath):
55 print filepath
57 if __name__ == "__main__":
58 main()