def processDir(): fileList = os.listdir(args.directory) for fileName in fileList: absPath = os.path.abspath(args.directory + '/' + fileName) if args.skipDotFiles and fileName.startswith('.'): continue if db.findFile(absPath): logger.debug("File {} already processed".format(absPath)) continue if args.storeOnly: print "Marking {} as processed".format(absPath) db.addFile(absPath) continue print "Processing file {}".format(absPath) cmd = args.command.format(absPath) logger.debug("Executing command \"{}\"".format(cmd)) returnCode = call(cmd, shell=True) if (returnCode == 0): logger.debug("Processing file {}".format(absPath)) db.addFile(absPath) else: logger.error("Error synchronizing file {}".format(absPath)) return False return True
def acquireLock(): global fileDesc fileDesc = os.open(args.lockFile, os.O_CREAT) logger.debug("Acquiring lock using file {}".format(args.lockFile)) try: fcntl.flock(fileDesc, fcntl.LOCK_EX | fcntl.LOCK_NB) except: logger.error("Error - unable to acquire lock. (Is another instance running?)") sys.exit()
def deleteIndex(idx): logger.debug("Deleting entry {} from file database".format(idx)) rslt = cursor.execute('DELETE FROM files WHERE rowid=?', (idx,)) if (rslt.rowcount == 0): logger.error("No file with index {} was present".format(idx)) connection.commit()