Browse Source

init

threaded
dkm 14 years ago
commit
875c161d1d
  1. 7
      initdb.sql
  2. 0
      plopifier/__init__.py
  3. 65
      plopifier/import.py

7
initdb.sql

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS images;
DROP TABLE IF EXISTS repository;
CREATE TABLE repository (id INTEGER PRIMARY KEY AUTOINCREMENT, rootfs VARCHAR(100));
CREATE TABLE images (id INTEGER PRIMARY KEY AUTOINCREMENT, relpath VARCHAR(50), ddate DATETIME, rootid INTEGER);

0
plopifier/__init__.py

65
plopifier/import.py

@ -0,0 +1,65 @@
#!/usr/bin/env python
from pysqlite2 import dbapi2 as sqlite
import re
import sys
import os
from datetime import datetime
file_pattern = re.compile("video@(?P<year>\d\d\d\d)(?P<month>\d\d)(?P<day>\d\d)(?P<hour>\d\d)(?P<min>\d\d)(?P<sec>\d\d)\.jpg")
sqfile = sys.argv[1]
root = sys.argv[2]
conn = sqlite.connect(sqfile)
cur = conn.cursor()
conn.row_factory = sqlite.Row
count = 0
curdir = root
q = "INSERT into repository (rootfs) VALUES('%s')" %root
cur.execute(q)
conn.commit()
q = "SELECT id FROM repository WHERE rootfs = '%s'" %root
cur.execute(q)
root_idx = int(cur.fetchall()[0][0])
print "root_idx: %d" %root_idx
insert_str="INSERT INTO images (relpath,ddate,rootid) VALUES ('%s', '%s', %s)"
def add_image(year,month,day,file):
pass
for dirpath1,year_dirs,files1 in os.walk(curdir):
for year in year_dirs:
for dirpath2,month_dirs,files2 in os.walk(os.path.join(dirpath1,year)):
for month in month_dirs:
for dirpath3,day_dirs,files3 in os.walk(os.path.join(dirpath2,month)):
for day in day_dirs:
for dirpath4,dirs4,image_files in os.walk(os.path.join(dirpath3,day)):
for file in image_files:
m = file_pattern.match(file)
if m == None:
continue
y,mt,d = int(year), int(month), int(day)
h,m,s = int(m.group('hour')),int(m.group('min')),int(m.group('sec'))
dt = datetime(y, mt, d, h, m, s)
q = insert_str %(os.path.join(year,month,day,file),
str(dt),
str(root_idx))
count+=1
cur.execute(q)
if count%100==0:
print "Count: %.10d\r" %count,
conn.commit()
conn.close()
Loading…
Cancel
Save