forked from rawler/bhindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.py
executable file
·52 lines (41 loc) · 1.39 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, os.path as path, sys, time
from ConfigParser import ConfigParser
from optparse import OptionParser
import subprocess
HERE = path.dirname(__file__)
sys.path.append(HERE)
import db, config
config = config.read()
TXTPATH = config.get('TXTSYNC', 'exportpath')
def timestamp_to_str(ts):
t = time.gmtime(ts)
return time.strftime("%Y-%m-%dT%H:%M:%S", t)
class DB:
def __init__(self, db):
self._db = db;
def list(self, filter=[]):
for k,v in self._db.filter(path=filter):
print "%s: %s"%(timestamp_to_str(v.timestamp), v.name)
def dir(self, prefix=[]):
for path, count in self._db.dir("path", prefix).iteritems():
print count, '\t', path
if __name__=='__main__':
parser = OptionParser(usage="usage: %prog [options] <PATH>")
parser.add_option("-d", "--dir", action="store_true", dest="dir",
help="dir-mode, list subdirectory")
parser.add_option("-l", "--list", action="store_false", dest="dir",
help="list-mode, list files")
(options, args) = parser.parse_args()
if len(args)>1:
parser.error("Only one path-argument supported")
elif args:
path=db.path_str2lst(args[0])
else:
path=[]
thisdb = DB(db.open(config))
if options.dir:
thisdb.dir(path)
else:
thisdb.list(path)