Changeset - 1fe54442db38
[Not reviewed]
default
0 1 0
drewp - 22 years ago 2003-07-08 09:18:47

get_all_subs sorts, and puts some elements at the end
1 file changed with 12 insertions and 1 deletions:
0 comments (0 inline, 0 general)
flax/Submaster.py
Show inline comments
 
@@ -71,40 +71,51 @@ class Submaster:
 
    def normalize_patch_names(self):
 
        # possibly busted -- don't use unless you know what you're doing
 
        self.set_all_levels(self.levels.copy())
 

	
 
def sub_maxes(*subs):
 
    return Submaster("max(%r)" % (subs,),
 
        dict_max(*[sub.levels for sub in subs]))
 

	
 
class Submasters:
 
    "Collection o' Submaster objects"
 
    def __init__(self):
 
        self.submasters = {}
 

	
 
        import os
 
        files = os.listdir('subs')
 

	
 
        for filename in files:
 
            # we don't want these files
 
            if filename.startswith('.') or filename.endswith('~') or \
 
               filename.startswith('CVS'):
 
                continue
 
            self.submasters[filename] = Submaster(filename)
 
    def get_all_subs(self):
 
        "All Submaster objects"
 
        return self.submasters.values()
 
        l = self.submasters.items()
 
        l.sort()
 
        l = [x[1] for x in l]
 
        songs = []
 
        notsongs = []
 
        for s in l:
 
            if s.name.startswith('song'):
 
                songs.append(s)
 
            else:
 
                notsongs.append(s)
 
        combined = notsongs + songs
 
        return combined
 
    def get_sub_by_name(self, name):
 
        "Makes a new sub if there isn't one."
 
        return self.submasters.get(name, Submaster(name))
 
    __getitem__ = get_sub_by_name
 

	
 
if __name__ == "__main__":
 
    Patch.reload_data()
 
    s = Submasters()
 
    print s.get_all_subs()
 
    if 0: # turn this on to normalize all subs
 
        for sub in s.get_all_subs():
 
            print "before", sub
 
            sub.normalize_patch_names()
 
            sub.save()
 
            print "after", sub
0 comments (0 inline, 0 general)