def run(cls, src, dst): src = os.path.abspath(os.path.normpath(src)) dst = os.path.abspath(os.path.normcase(dst)) if src == dst: return if not os.path.exists(src): sys.stderr.write("File %s does not exist\n" % src) sys.exit(1) if os.path.exists(dst): sys.stderr.write("File %s already exists\n" % dst) sys.exit(1) sourceDir, sourceFilename = os.path.split(src) if not SnowFileDB.existsAtDir(sourceDir): sys.stderr.write("DB file not found at %s, aborting\n" % os.path.join(sourceDir, Config.getDBFilename())) sys.exit(1) destDir, destFilename = os.path.split(dst) if sourceDir != destDir: sourceDB = SnowFileDB(sourceDir) destDB = SnowFileDB(destDir) fileInfo = sourceDB.getFileInfo(sourceFilename) if not fileInfo: sys.stderr.write("File %s not present at DB file %s\n" % (sourceFilename, sourceDB.getDBFilePath())) sys.exit(1) sourceDB.deleteFile(sourceFilename) fileInfo.setFileName(destFilename) destDB.addFileInfo(fileInfo) shutil.move(src, dst) sourceDB.commitAndClose() destDB.commitAndClose() else: db = SnowFileDB(sourceDir) sucesss = db.renameFile(sourceFilename, destFilename) if not sucesss: sys.stderr.write("File %s not present at DB file %s\n" % (sourceFilename, db.getDBFilePath())) sys.exit(1) shutil.move(src, dst) db.commitAndClose() SLogger.debug("File successfully moved from %s to %s\n" % (src, dst))
def fileShouldBeIgnored(filePath): fileDir, fileName = os.path.split(os.path.normpath(os.path.abspath(filePath))) if fileName in Config.getIgnoreFiles().union(set([Config.getDBFilename(), Config.getLockFilename()])): return True else: return directoryShouldBeIgnored(fileDir)
def existsAtDir(cls, path): return os.path.exists(os.path.join(path, Config.getDBFilename()))
def run(cls, target): if not os.path.exists(target): sys.stderr.write("Unable to find file %s" % target) sys.exit(1) dirName, fileName = os.path.split(target) dirName = os.path.abspath(os.path.normpath(dirName)) db = SnowFileDB(dirName) fileInfo = db.getFileInfo(fileName) if not fileInfo: sys.stderr.write("File %s not found in %s" % (target, os.path.join(dirName, Config.getDBFilename()))) sys.exit(1) client = SnowClient(fileInfo.getTableName(), fileInfo.getInstance()) record = client.get(fileInfo.getSysId()) recordName = record.sys_id content = normalizeNewlines(getattr(record, fileInfo.getContentFieldName())) if os.path.isfile(os.path.join(dirName, Config.getLockFilename())): #swatch is watching, we do not want him to re-upload, we write a file for swatch.py to know ignoreWatchFilePath = target + Config.getIgnoreWatchFilenameSuffix() SLogger.debug("Creating file %s to avoid swatch to re-upload" % ignoreWatchFilePath) ignoreWatchFile = open(ignoreWatchFilePath, "w") ignoreWatchFile.close() f = codecs.open(target, "w", "utf-8") f.write(content) db.setUpdatedOn(fileName, record.sys_updated_on) db.commitAndClose() SLogger.debug("Updated record %s to file %s. set updated_on to %s" % (recordName, fileName, record.sys_updated_on))
def __init__(self, path): self.__dbFilePath = os.path.join(path, Config.getDBFilename()) SLogger.debug("Opening DB File: %s" % self.__dbFilePath) self.__conn = sqlite3.connect(self.__dbFilePath) self.__cursor = self.__conn.cursor()