|
@@ -24,9 +24,18 @@ import xattr, sqlite3, time
|
|
|
DATABASE_NAME = os.path.expanduser(DATABASE_NAME)
|
|
|
|
|
|
class DataBase:
|
|
|
- ''' the date here is the st_mtime, a float
|
|
|
- and the filName is a fully qualified name'''
|
|
|
+ ''' the database is flat
|
|
|
+ fileName: fully qualified name
|
|
|
+ st_mtime: a float
|
|
|
+ size: a long
|
|
|
+ comment: a string
|
|
|
+ comment_time: a float, the time of the comment save
|
|
|
+ this is effectively a log file, as well as a resource for a restore
|
|
|
+ (in case a file-move is done without comment)
|
|
|
+ the database is associated with a user, in the $HOME dir
|
|
|
+ '''
|
|
|
def __init__(self):
|
|
|
+ '''try to open the database; if not found, create it'''
|
|
|
try:
|
|
|
self.db = sqlite3.connect(DATABASE_NAME)
|
|
|
except sqlite3.OperationalError:
|
|
@@ -37,7 +46,7 @@ class DataBase:
|
|
|
c.execute("select * from dirnotes")
|
|
|
except sqlite3.OperationalError:
|
|
|
print("Table %s created" % ("dirnotes"))
|
|
|
- c.execute("create table dirnotes (name, date, size, comment)")
|
|
|
+ c.execute("create table dirnotes (name TEXT, date REAL, size INTEGER, comment TEXT, comment_date REAL)")
|
|
|
|
|
|
def getData(self, fileName):
|
|
|
c = self.db.cursor()
|
|
@@ -45,8 +54,8 @@ class DataBase:
|
|
|
return c.fetchone()
|
|
|
def setData(self, fileName, _date, _size, comment):
|
|
|
c = self.db.cursor()
|
|
|
- c.execute("insert into dirnotes values (?,?,?,?)",
|
|
|
- (fileName, _date, _size, comment))
|
|
|
+ c.execute("insert into dirnotes values (?,?,?,?,?)",
|
|
|
+ (fileName, _date, _size, comment, time.time()))
|
|
|
self.db.commit()
|
|
|
return True
|
|
|
|
|
@@ -56,7 +65,7 @@ def parse():
|
|
|
nargs="*",help='filename or directory',default=".")
|
|
|
parser.add_argument('-n','--nogui',action="store_const",const="1",
|
|
|
help='use text base interface')
|
|
|
- parser.add_argument('-v','--version',action='version',version='%(prog)s 0.1')
|
|
|
+ parser.add_argument('-v','--version',action='version',version='%(prog)s 0.2')
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def debug(x):
|
|
@@ -142,9 +151,9 @@ if __name__=="__main__":
|
|
|
p = parse()
|
|
|
|
|
|
db = DataBase()
|
|
|
- db.setData("a",float(time.time()),12345,"a comment")
|
|
|
+ db.setData("a",float(time.time()),1244445,"a comment")
|
|
|
print(db.getData("a"))
|
|
|
- (f,d,s,c) = db.getData("a")
|
|
|
+ (f,d,s,c,cd) = db.getData("a")
|
|
|
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(d)))
|
|
|
|
|
|
a = QApplication([])
|