Browse Source

c_dirnotes: added database creation

Pat Beirne 1 year ago
parent
commit
aad00e1b2b
2 changed files with 23 additions and 9 deletions
  1. 13 5
      c_dirnotes.py
  2. 10 4
      dirnotes

+ 13 - 5
c_dirnotes.py

@@ -275,17 +275,25 @@ class Files():
     f = os.listdir(directory)
     f = os.listdir(directory)
     for i in f:
     for i in f:
       self.files.append(FileObj(directory + '/' + i))
       self.files.append(FileObj(directory + '/' + i))
+    self.sort()
+
+    self.db = None
+    try:
+      self.db = sqlite3.connect(DATABASE_NAME)
+      c = self.db.cursor()
+      c.execute("select * from dirnotes")
+    except sqlite3.OperationalError:
+      # TODO: problem with database....create one?
+      c.execute("create table dirnotes (name TEXT, date DATETIME, size INTEGER, comment TEXT, comment_date DATETIME, author TEXT)")
 
 
     try:
     try:
-      db = sqlite3.connect(DATABASE_NAME)
-      c = db.cursor()
+      c = self.db.cursor()
       self.directory.loadDbComment(c)
       self.directory.loadDbComment(c)
       for f in self.files:
       for f in self.files:
         f.loadDbComment(c)
         f.loadDbComment(c)
     except sqlite3.OperationalError:
     except sqlite3.OperationalError:
-      # TODO: problem with database....create one?
-      pass
-    self.sort()
+      errorBox("serial problem with the database")
+
 
 
   def sortName(a):
   def sortName(a):
     if a.getFileName() == '..':
     if a.getFileName() == '..':

+ 10 - 4
dirnotes

@@ -6,7 +6,6 @@ comments are stored in an SQLite3 database
 	default ~/.dirnotes.db
 	default ~/.dirnotes.db
 where possible, comments are duplicated in 
 where possible, comments are duplicated in 
 	xattr user.xdg.comment
 	xattr user.xdg.comment
-	depends on python-pyxattr
 
 
 	some file systems don't allow xattr, and even linux
 	some file systems don't allow xattr, and even linux
 	doesn't allow xattr on symlinks, so the database is
 	doesn't allow xattr on symlinks, so the database is
@@ -48,7 +47,7 @@ import sys,os,argparse,stat
 from PyQt5.QtGui import *
 from PyQt5.QtGui import *
 from PyQt5.QtWidgets import *
 from PyQt5.QtWidgets import *
 from PyQt5.QtCore import Qt
 from PyQt5.QtCore import Qt
-import xattr, sqlite3, time
+import sqlite3, time
 
 
 VERSION = "0.2"
 VERSION = "0.2"
 COMMENT_KEY = "user.xdg.comment"
 COMMENT_KEY = "user.xdg.comment"
@@ -159,7 +158,7 @@ class FileObj():
 			self.size = s.st_size
 			self.size = s.st_size
 		self.xattrComment = ''
 		self.xattrComment = ''
 		try:
 		try:
-			self.xattrComment = xattr.get(fileName,COMMENT_KEY,nofollow=True).decode()
+			self.xattrComment = os.getxattr(fileName,COMMENT_KEY,follow_symlinks=False).decode()
 		except Exception as e:
 		except Exception as e:
 			#print("comment read on %s failed, execption %s" % (self.fileName,e)) 
 			#print("comment read on %s failed, execption %s" % (self.fileName,e)) 
 			pass
 			pass
@@ -174,7 +173,7 @@ class FileObj():
 	def setXattrComment(self,newComment):
 	def setXattrComment(self,newComment):
 		self.xattrComment = newComment
 		self.xattrComment = newComment
 		try:
 		try:
-			xattr.set(self.fileName,COMMENT_KEY,self.xattrComment,nofollow=True)
+			os.setxattr(self.fileName,COMMENT_KEY,bytes(self.xattrComment,'utf8'),follow_symlinks=False)
 			return True
 			return True
 		# we need to move these cases out to a handler 
 		# we need to move these cases out to a handler 
 		except Exception as e:
 		except Exception as e:
@@ -498,6 +497,13 @@ user.xdg.publisher
 
 
 ''' TODO: also need a way to display-&-restore comments from the database '''
 ''' TODO: also need a way to display-&-restore comments from the database '''
 
 
+''' TODO: implement startup -s and -m for size and date '''
+
+''' TODO: add an icon for the app '''
+
+''' TODO: create 'show comment history' popup '''
+
+''' TODO: add dual-pane for file-move, file-copy '''
 	
 	
 ''' commandline xattr
 ''' commandline xattr
 getfattr -h (don't follow symlink) -d (dump all properties)
 getfattr -h (don't follow symlink) -d (dump all properties)