Changeset 64 for trunk


Ignore:
Timestamp:
13/09/07 03:59:17 (4 years ago)
Author:
nigel.sim
Message:
  • added cli option parsing
  • added directory exclusion
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/spl-editor/main.py

    r63 r64  
    33import os, os.path 
    44import sys 
     5import getopt 
    56 
    67byArtist = {} 
     
    1011#playlists = '/home/nigel/misc/Music/playlists' 
    1112def showUsage(): 
    12         print "main.py <Root directory> <Playlist directory>" 
     13        print "main.py [-e <excluded directory> ...] <Root directory> <Playlist directory>" 
    1314 
    1415 
    1516if __name__ == '__main__': 
    16         if len(sys.argv) != 3: 
     17        optlist, args = getopt.getopt(sys.argv[1:],'e:') 
     18        if len(args) != 2: 
    1719                showUsage() 
    1820                sys.exit(1) 
    1921        else: 
    20                 start = sys.argv[1] 
    21                 playlists = sys.argv[2] 
     22                start = args[0] 
     23                playlists = args[1] 
     24                excludeList = [] 
     25                for tag, exdir in optlist: 
     26                        if tag == '-e': 
     27                                excludeList.append(exdir) 
     28        # Iterate through the dirs below the start dir 
    2229        for root, dirs, files in os.walk(start): 
     30                # Check the dir isn't excluded 
     31                skip = False 
     32                for ex in excludeList: 
     33                        if root.startswith(ex): 
     34                                print "skipping", root 
     35                                skip = True 
     36                                continue 
     37                if skip: 
     38                        continue 
     39 
    2340                for f in files: 
    2441                        md = kaa.metadata.parse(os.path.join(root, f)) 
     
    3653 
    3754        for a in byArtist: 
    38                 files = [md.fileName.replace(start,'') for md in byArtist[a] ] 
     55                files = [md.fileName.replace(start,'').replace('/','\\') for md in byArtist[a] ] 
    3956                pl = spl.SPL() 
    4057                pl.list = files 
Note: See TracChangeset for help on using the changeset viewer.