Commits

razzmataz  committed 3c564d8

ran pylint a bunch more times to clean up this mess.

  • Participants
  • Parent commits 462ef1f

Comments (0)

Files changed (4)

File utils/archive.py

 #!/usr/bin/env python
 
 import sys
-import os
 #import optparse
 import bz2
 import datetime, time
 import cmdln
 import zipfile
 
-def bundle_files(filelist,outputbase = None):
+def bundle_files(filelist, outputbase = None):
+    '''bundle_files zips everything together with timestamp'''
     now_date = datetime.datetime.today()
-#    now_time = datetime.time.today()
-    datestamp = "%d%d%.02d_%.02d%.02d%.02d" % (now_date.year, now_date.month, now_date.day,  now_date.hour, now_date.minute, now_date.second)
+    #now_time = datetime.time.today()
+    datestamp = "%d%d%.02d_%.02d%.02d%.02d" % (now_date.year, 
+                                               now_date.month, 
+                                               now_date.day,  
+                                               now_date.hour, 
+                                               now_date.minute, 
+                                               now_date.second)
     # this should be something else?
     destzipfile = ""
     if outputbase is not None:
         destzipfile = outputbase +"." + datestamp + ".zip"
     else:
         destzipfile = datestamp + ".zip"
-    z = zipfile.ZipFile(destzipfile, mode="w") 
-    for file in filelist:
-        z.write(file)
+    zfile = zipfile.ZipFile(destzipfile, mode="w") 
+    for file2archive in filelist:
+        zfile.write(file2archive)
     # would this be enough
 
-def single_file(filename,keepfile=False):
+def single_file(filename, keepfile=False):
+    '''single_file archives everything up into a bzip file'''
     now_date = datetime.date.today()
     datestamp = "%d%d%.02d" % (now_date.year, now_date.month, now_date.day)
     destination_file = filename + "." + datestamp + ".bz2"
     tmp_dest = filename + "." + datestamp
     subprocess.Popen(['cp', filename, tmp_dest])
     time.sleep(1)
+    fhandle = None
     try:
-        f = open(tmp_dest)
+        fhandle = open(tmp_dest)
     except Exception :
         print "problem opening %s" % (filename)
         sys.exit(1) 
-    archive = bz2.BZ2File(destination_file, 'w', compresslevel=9)
-    source_lines = f.readlines()
-    archive.writelines(source_lines)
-    archive.close()
-    f.close()
+    bzarchive = bz2.BZ2File(destination_file, 'w', compresslevel=9)
+    source_lines = fhandle.readlines()
+    bzarchive.writelines(source_lines)
+    bzarchive.close()
+    fhandle.close()
     # should remove tmp_dest
     if not keepfile:
-        subprocess.Popen(['rm',tmp_dest])
+        subprocess.Popen(['rm', tmp_dest])
     else:
         print "keeping file %s" % ( tmp_dest)
 
 # archive the file
 
 class Archive(cmdln.Cmdln):
+    '''archive bundles a bunch of files together in a zip file or bzipfile'''
     name = 'archive'
-    def do_archive_file(self,subcmd,opts, sourcefile):
+    def do_archive_file(self, subcmd, opts, sourcefile):
         """archives file in bz format with datestamp in filename"""
         #print("file archive")
         single_file(sourcefile)
 
     @cmdln.option("-o","--output", help="optional outputfile basename" )
-    def do_bundle_files(self,subcmd,opts, *sourcefiles):
+    def do_bundle_files(self, subcmd, opts, *sourcefiles):
         """archives large numbers of files in a zipfile """
         #print "bundle files"
-        bundle_files(sourcefiles,opts.output)
+        bundle_files(sourcefiles, opts.output)
 
 #if options.filename and (len(args) == 0):
 #    single_file(options.filename)

File utils/couch-scripts/csv2couch.py

 if len(args) == 0:
     parser.error("must specify a csv file to upload")
 
-#csv_filename = sys.argv[1]
 csv_filename = args[0]
 couchdb_host = options.url
 couchdb_name = options.database
         #print headerLine
     else:
         new_dict = { }
-        for col in range(0,len(headerLine)):
+        for col in range(0, len(headerLine)):
             if len(row[col]) > 0:
                 new_dict[headerLine[col]] = row[col]
         #new_dict['type'] = 'area_code'
 
 print len(listOfDicts)
 
-server = couchdb.client.Server(couchdb_host,full_commit=False)
+server = couchdb.client.Server(couchdb_host, full_commit=False)
 db = server[couchdb_name]
 put_count = 0
 for record in listOfDicts:

File utils/couch-scripts/delp.py

 #!/usr/bin/env python
 
-# for loading delicious xml dump into couchdb
+''' for loading delicious xml dump into couchdb'''
 
 import xml.etree.ElementTree as etree
-import sys
 import couchdb
 from uuid import uuid4
 from optparse import OptionParser
 
 parser = OptionParser()
-parser.add_option("-u","--url", dest="url", help="couchdb server url", metavar="URL")
-parser.add_option("-d","--db-name", dest="dbname", help="couchdb name",
+parser.add_option("-u", "--url", dest="url", help="couchdb server url", 
+                  metavar="URL")
+parser.add_option("-d", "--db-name", dest="dbname", help="couchdb name",
                   metavar="DBNAME", default='bookmarks')
 
 (options, args) = parser.parse_args()
     print item
     doc_id = uuid4().hex
     bookmark = dict()
-    for k,v in item.items():
+    for k, v in item.items():
         print "key %s : %s" % (k, v)
         bookmark[k] = v
     db[doc_id] =  bookmark

File utils/couch-scripts/purge-couch.py

 #!/usr/bin/env python
+'''wipes out all entries in couchdb instance. use with great caution'''
+#import csv
+import sys
+#import string
+#import re
+#import os
+import couchdb
+#from uuid import uuid4
 
-import csv
-import sys
-import string
-import re
-import os
-import couchdb
-from uuid import uuid4
+Couchdb_host = sys.argv[1]
+Couchdb_name = sys.argv[2]
 
-couchdb_host = sys.argv[1]
-couchdb_name = sys.argv[2]
 
-
-server = couchdb.client.Server(couchdb_host,full_commit=False)
-db = server[couchdb_name]
+Server = couchdb.client.Server(Couchdb_host, full_commit=False)
+Db = Server[Couchdb_name]
 put_count = 0
 
-for row in db.view('_all_docs'):
+for row in Db.view('_all_docs'):
     #db.delete(row.id)
-    doc = db.get(row.id)
-    db.delete(doc)
-db.commit()
+    Doc = Db.get(row.id)
+    Db.delete(Doc)
+Db.commit()