def genstr(otypes,source,listh,thing): strs=[] for line in open(source).read().splitlines(): if not '#' in line: if otypes in line: strs.append(line) strsf=open(listh+".txt",'w') strsf.write(config.words(thing).get('word02')) strsf.write(nonselectstate+nss.join(strs)+'\n') strsf.close()
def gensl(otypes,source,listh,thing): status=os.system("ls -1 "+source+" > "+temp) types=otypes.split(".") songs=[] ## ---------------------Initial Library------------------------- library={} for letters in letterset[0:len(letterset)]: if letters[0] == '0': library.update({'Numbers':[]}) else: library.update({letters[0]:[]}) library.update({'Other':[]}) ## ---------------------Filter Songs------------------------- for line in open(temp).read().splitlines(): for type in types: if '#' not in line: if type in line: songs.append(line) ## ---------------------Arrange Songs------------------------- for song in songs: for letters in letterset[0:len(letterset)]: for letter in letters: if letters[0] == '0': if song[0] == letter: library.get('Numbers').append(song) elif song[0] == letter: library.get(letters[0]).append(song) if song[0] not in purels: library.get('Other').append(song) ## ---------------Calculate and Create Filelists--------------------- filelib={} ## Start create selection of media which file name start with Numbers pagenum=1 linenum=len(library.get("Numbers")) listf=open(listh+'-Part'+str(pagenum)+"-Num.txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get("Numbers"))+'\n') ## Start create selection of media which file name start with alphabet for letters in letterset[1:len(letterset)-1]: tempnum=len(library.get(letters[0])) if library.get(letters[0])==[]: continue elif linenum+tempnum<splitnum: linenum=linenum+tempnum listf.write(nonselectstate+nss.join(library.get(letters[0]))+'\n') elif linenum+tempnum>=splitnum: if tempnum<=splitnum: pagenum=pagenum+1 linenum=tempnum listf.close() listf=open(listh+'-Part'+str(pagenum)+"-"+letters[0]+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get(letters[0]))+'\n') elif tempnum>splitnum: ## Start seperate list when the number of items more then splitnum templistnum=0 for ra in range(0,10000): if templistnum+splitnum<=tempnum: pagenum=pagenum+1 listf.close() listf=open(listh+'-Part'+str(pagenum)+"-"+letters[0]+library.get(letters[0])[templistnum][1]+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get(letters[0])[templistnum:(templistnum+splitnum+1)])+'\n') templistnum=templistnum+splitnum elif templistnum+splitnum>tempnum: pagenum=pagenum+1 listf.close() listf=open(listh+'-Part'+str(pagenum)+"-"+letters[0]+library.get(letters[0])[templistnum][1]+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get(letters[0])[templistnum:(tempnum+1)])+'\n') linenum=tempnum-templistnum break ## Start create selection of media which file name start with non-latin characters tempnum=len(library.get("Other")) if linenum+tempnum<splitnum: linenum=linenum+tempnum listf.write(nonselectstate+nss.join(library.get("Other"))+'\n') listf.close() elif linenum+tempnum>=splitnum: if tempnum<=splitnum: pagenum=pagenum+1 listf.close() listf=open(listh+'-Part'+str(pagenum)+"-Oth"+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get("Other"))+'\n') listf.close() elif tempnum>splitnum: ## Start seperate list when the number of items more then splitnum templistnum=0 for ra in range(1,10001): if templistnum+splitnum<=tempnum: pagenum=pagenum+1 listf.close() listf=open(listh+'-Part'+str(pagenum)+"-Oth"+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get("Other")[templistnum:(templistnum+splitnum+1)])+'\n') templistnum=templistnum+splitnum elif templistnum+splitnum>tempnum: pagenum=pagenum+1 listf.close() listf=open(listh+'-Part'+str(pagenum)+"-Oth"+".txt",'w') listf.write(config.words(thing).get('word02')) listf.write(nonselectstate+nss.join(library.get("Other")[templistnum:(tempnum+1)])+'\n') listf.close() break status=os.system("rm "+temp)
#!/mnt/us/python/bin/python2.6 import sys import os import config ## -----------Change it if different--------- global notepaddir,nonselectstate,nss,temp,playlist,splitnum notepaddir=config.mpenv().get('notepaddir') nonselectstate=config.mpenv().get('nonselectstate') nss=config.mpenv().get('nss') temp=config.temp playlist=config.playlist splitnum=config.mpenv().get('splitnum') ## ---------------words------------------------------- global word01,selword01,word02,word03 word01=config.words('').get('word01') selword01=config.words('').get('selword01') #word02=config.words(thing).get('word02') #Please use 'Find' to find the command word03=config.words('').get('word03') ## ---------------source folder------------------------------- global musicdir,recorddir,strlist musicdir=config.musicdir recorddir=config.recorddir strlist=config.strlist ## ---------------list file head------------------------------- global forpledit,forrecdit,forstrdit forpledit=config.forpledit forrecdit=config.forrecdit forstrdit=config.forstrdit ## ---------------temporary method------------------------------- global letterset,purels letterset=[['0','1','2','3','4','5','6','7','8','9'],['A','a'],['B','b'],['C','c'],['D','d'],['E','e'],['F','f'],['G','g'],['H','h'],['I','i'],['J','j'],['K','k'],['L','l'],['M','m'],['N','n'],['O','o'],['P','p'],['Q','q'],['R','r'],['S','s'],['T','t'],['U','u'],['V','v'],['W','w'],['X','x'],['Y','y'],['Z']]