7 def __init__(self, verboseFlag):
8 self.db_name = "timeline.db"
11 self.verbose = verboseFlag
13 def connect_to_db(self):
14 self.conn = sqlite3.connect(self.db_name)
15 self.cursor = self.conn.cursor()
16 self.conn.text_factory = str
18 def clear_tables(self):
21 self.cursor.execute("DROP TABLE tl")
22 except sqlite3.OperationalError:
23 print "Warning >>> Nothing to clean."
24 # Date,Size,Type,Mode,UID,GID,Meta,File Name
25 self.cursor.execute("""CREATE TABLE tl (
37 print "Info >>> Initalized table(s)"
39 def parse_csv(self, fileName):
43 print ">>> Cannot open file %s" % fileName
52 # Comma delimited mactime file has always 8 entries. If we detect
53 # more than 8, we have commas in the filename
55 sl[7] = "".join(sl[7:])
57 print ">>> Found bogus entry with length %d, shorten it to 8: %s" % (len(sl), sl[7])
68 except IndexError as e:
69 print ">>> Parsing error: %s" % str(e)
72 query = "INSERT INTO tl VALUES (?,?,?,?,?,?,?,?)"
73 values = (date,size,ftype,mode,uid,gid,meta,fname)
74 self.cursor.execute(query, values)
82 print " --initdb - Initialize SQLite database (destroys all data!)"
83 print " --import <csv-file> - Import timeline from CSV file (comma separated)"
85 print " -v - Be more verbose"
92 opts, args = getopt.getopt(sys.argv[1:], 'hv',
93 ["import=", "initdb"])
94 except getopt.GetoptError as err:
105 for opt, arg in opts:
108 elif opt == '--import':
111 elif opt == '--initdb':
116 usage("Unrecognized Option")
118 p = ParseMactime(verboseFlag)
124 p.parse_csv(importCsv)