Ejemplo n.º 1
0
      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
      elif choice == 'rm':
         errcode = [0]*len(itemlist)

      if choice in ('mv','rm'):
         header.remove_database(itemlist,SHELFDATA,errcode)
   else: # add file to shelf
      data = header.read_database(SHELFDATA)
      data2 = [a['fullpath'] for a in data]

      docs = header.read_cmdline(sys.argv[1:])
      junk = list(set(docs) - set(data2))
      junk.sort(header.smart_sort)
      header.write_database(junk,SHELFDATA)
Ejemplo n.º 2
0
            newlist.append(asource.copy())
      header.write_database(newlist,syncFile)
   elif flag in ('d','u','x'):
      if len(sys.argv) < 3:
         docs = list_syncs(data)
      else:
         tmp = [header.to_lower(f) for f in sys.argv[2:]]
         for f in tmp:
            if tmp[-1] == '/':
               tmp = tmp[:-1] # strip off any trailing forward slash
         docs = grep_data(tmp,data)
      if flag == 'x': # delete
         deletelist = [s['name'] for s in docs] # names of documents to delete
         namelist   = [s['name'] for s in data] # names of all documents
         idxlist  = [namelist.index(a) for a in deletelist] # indexes to delete
         if len(idxlist) == 0:
            print "No locations deleted"
         else:         
            header.remove_database(idxlist,syncFile)
      else:
         for s in docs:
            if flag == 'u': # upload
               if os.path.exists(s['name']):
                  print 'Uploading "%s"...' %s['name']
                  os.system('rsync -avPz --delete %s %s' %(s['name'],s['path']))
               else:
                  print '"%s" does not exist.  Skipping.' %s['name']
            elif flag == 'd': # download
               print 'Downloading "%s"...' %s['name']
               os.system('rsync -avPz --delete %s/%s .' %(s['path'],s['name']))