def accept(self, parent_id, name, stat_info, arc_flag, fullPath = None): is_dir = 0 if stat.S_ISDIR(stat_info[stat.ST_MODE]): is_dir = 1 ext = self.getExt(name) self.file_no = self.file_no + 1 self.c.execute(""" INSERT INTO directory(snapshot, no, parent, name, extension, size, is_dir, arc_status, mdate) VALUES (%d, %d, %s, %s, %s, %d, %d, %d, '%s') """ % (self.disk_id, self.file_no, parent_id, DbConn.quote(name), DbConn.quote(ext), stat_info[stat.ST_SIZE], is_dir, arc_flag, time.strftime("%Y%m%d%H%M%S", time.localtime(stat_info[stat.ST_MTIME]))) ) id = self.c.lastrowid # Update UI with status self.feedbackObject.feedback(self.file_no); # Bookkeeping if arc_flag == Const.ARC_IN_ARCHIVE: if stat.S_ISDIR(stat_info[stat.ST_MODE]): self.numArcDirectories = self.numArcDirectories + 1 else: self.numArcFiles = self.numArcFiles + 1 else: if stat.S_ISDIR(stat_info[stat.ST_MODE]): self.numDirectories = self.numDirectories + 1 else: self.numFiles = self.numFiles + 1 if arc_flag == Const.ARC_IS_ARCHIVE: self.numArchives += 1 return int(id)
def insertNew(self, fullPath, fileInfo): path = self.getInVoumePath(fullPath) self.additions.append(path) dir = self.resolverApi.getIdByPath(self.disk_id, os.path.dirname(path)) sql = """ INSERT INTO directory(snapshot, no, parent, name, extension, size, is_dir, arc_status, mdate) VALUES (%d, %d, %s, %s, %s, %d, %d, %d, '%s') """ % (self.disk_id, 0, dir[0]["id"], DbConn.quote(fileInfo.name), DbConn.quote(self.getExt(fileInfo.name)), fileInfo.size, fileInfo.isDir, 0, fileInfo.mtime) if self.debugLevel & DbUpdateDumper.DEBUG_SQL: print sql self.c.execute(sql)
def addFileCategory(self, fileId, categoryId, value = None, timeStamp = None): if timeStamp == None: timeStamp = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())) cursor = self.connection.getCursor() cursor.execute("""\ INSERT INTO category_map(cat_id, obj_id, value, tstamp) VALUES (%d, %d, %s, '%s') """ % (categoryId, fileId, DbConn.quote(value), timeStamp)) self.connection.commit()
def reparent(self, fullPath, fileInfo, match): path = self.getInVoumePath(fullPath) # if fileRec["is_dir"]: path += "/" self.updates.append(( self.resolverApi.getFilePath(match["id"]) + ["", "/"][match["is_dir"]], path + ["", "/"][fileInfo.isDir] )) dir = self.resolverApi.getIdByPath(self.disk_id, os.path.dirname(path)) sql = "UPDATE directory SET parent=%d, name=%s, size=%d, mdate='%s' WHERE id=%d" % (dir[0]['id'], DbConn.quote(fileInfo.name), fileInfo.size, fileInfo.mtime, match['id']) if self.debugLevel & DbUpdateDumper.DEBUG_SQL: print sql self.c.execute(sql)
def findByParentIdAndName(self, diskId, parentId, name): cursor = self.connection.getCursor() cursor.execute("SELECT * FROM directory WHERE snapshot=%d AND parent=%d AND name=%s" % (diskId, parentId, DbConn.quote(name))) return cursor.fetchall()
def findByTypeAndName(self, type, name): cursor = self.connection.getCursor() cursor.execute("SELECT * FROM category WHERE type=%d AND name=%s" % (type, DbConn.quote(name))) if cursor.rowcount != 1: return None return cursor.fetchone()