def list_syncs(data): """Prints the stored sync locations and lets the user choose one or more to synchronize. It returns a list of the full file path names""" header.print_database(data,shownum=False) choice=raw_input("Choose: ") if choice != "": choicelist = [header.to_lower(f) for f in choice.split()] docs = grep_data(choicelist,data) return docs
# Begin Main program if __name__ == '__main__': if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: print __doc__ raise SystemExit alldata = header.read_database(RECENTDATA) alldata.reverse() # most recent (last entry) is first if len(sys.argv) == 1 or sys.argv[1] == 'h': if len(alldata) == 0: print "No recent files!" sys.exit() header.print_database(alldata) choice=raw_input("Choose: ") docs = [] if choice != "": filelist = header.read_range(choice.split(),len(alldata)) docs = [alldata[i]['fullpath'] for i in filelist] if len(docs) == 0: # User did not select any recent documents os.system('$GODIR/lf.py') else: mimetypes,docs = find_mimetypes(docs) open_files(mimetypes,docs) else: if sys.argv[1] == '-': # read filenames from a pipe junk = [a.strip() for a in sys.stdin.readlines()] # strip of \n chars
sys.exit() if len(sys.argv) > 1: choice = sys.argv[1] else: choice = "" if choice in ['mv','cp','rm','ck','ln','','h']: #i.e. not a file data = header.read_database(SHELFDATA) if len(data) == 0: print "No items on the shelf." sys.exit() if len(sys.argv) > 2: #arguments already given itemlist = header.read_range(sys.argv[2:],len(data)) else: #no arguments given header.print_database(data) if choice not in ["","h"]: #unless we just wanted list, get args line=raw_input("Choose: ") if line!="": itemlist = header.read_range(line.split(),len(data)) if choice in ('cp','mv','ck','ln'): newitemlist = [] # list of items that exist errcode = [] # list of files that failed to move/copy/link for idx in itemlist: if os.path.exists(data[idx]['fullpath']): newitemlist.append(idx) errcode.append(dostuff(data[idx],choice)) else: print 'Item "%s" does not exist. Skipping' %data[idx]['fullpath'] itemlist = newitemlist
choicelist = [header.to_lower(f) for f in choice.split()] docs = grep_data(choicelist,data) return docs if __name__ == "__main__": if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: print __doc__ sys.exit() data = header.read_database(syncFile) if len(data) == 0: print "No sync locations" sys.exit() if len(sys.argv) == 1: header.print_database(data,shownum=False) sys.exit() flag = sys.argv[1] if flag == 'h': header.print_database(data,shownum=False) sys.exit() elif flag == 'a': # add namelist = [s['name'] for s in data] location = sys.argv[-1] docs = header.read_cmdline(sys.argv[2:-1]) newlist = [] asource = {'name' : '', 'path' : ''} for f in docs: