database is typed now; included comment time
This commit is contained in:
@@ -24,9 +24,18 @@ import xattr, sqlite3, time
|
|||||||
DATABASE_NAME = os.path.expanduser(DATABASE_NAME)
|
DATABASE_NAME = os.path.expanduser(DATABASE_NAME)
|
||||||
|
|
||||||
class DataBase:
|
class DataBase:
|
||||||
''' the date here is the st_mtime, a float
|
''' the database is flat
|
||||||
and the filName is a fully qualified name'''
|
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):
|
def __init__(self):
|
||||||
|
'''try to open the database; if not found, create it'''
|
||||||
try:
|
try:
|
||||||
self.db = sqlite3.connect(DATABASE_NAME)
|
self.db = sqlite3.connect(DATABASE_NAME)
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
@@ -37,7 +46,7 @@ class DataBase:
|
|||||||
c.execute("select * from dirnotes")
|
c.execute("select * from dirnotes")
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
print("Table %s created" % ("dirnotes"))
|
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):
|
def getData(self, fileName):
|
||||||
c = self.db.cursor()
|
c = self.db.cursor()
|
||||||
@@ -45,8 +54,8 @@ class DataBase:
|
|||||||
return c.fetchone()
|
return c.fetchone()
|
||||||
def setData(self, fileName, _date, _size, comment):
|
def setData(self, fileName, _date, _size, comment):
|
||||||
c = self.db.cursor()
|
c = self.db.cursor()
|
||||||
c.execute("insert into dirnotes values (?,?,?,?)",
|
c.execute("insert into dirnotes values (?,?,?,?,?)",
|
||||||
(fileName, _date, _size, comment))
|
(fileName, _date, _size, comment, time.time()))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -56,7 +65,7 @@ def parse():
|
|||||||
nargs="*",help='filename or directory',default=".")
|
nargs="*",help='filename or directory',default=".")
|
||||||
parser.add_argument('-n','--nogui',action="store_const",const="1",
|
parser.add_argument('-n','--nogui',action="store_const",const="1",
|
||||||
help='use text base interface')
|
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()
|
return parser.parse_args()
|
||||||
|
|
||||||
def debug(x):
|
def debug(x):
|
||||||
@@ -142,9 +151,9 @@ if __name__=="__main__":
|
|||||||
p = parse()
|
p = parse()
|
||||||
|
|
||||||
db = DataBase()
|
db = DataBase()
|
||||||
db.setData("a",float(time.time()),12345,"a comment")
|
db.setData("a",float(time.time()),1244445,"a comment")
|
||||||
print(db.getData("a"))
|
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)))
|
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(d)))
|
||||||
|
|
||||||
a = QApplication([])
|
a = QApplication([])
|
||||||
|
|||||||
Reference in New Issue
Block a user