示例#1
0
    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))
示例#2
0
 def __scheduleDir(cls, dirPath, rootDirPath):
     if not directoryShouldBeIgnored(dirPath):
         SLogger.debug("Watching dir %s" % os.path.abspath(dirPath))
         lockFilePath = os.path.abspath(os.path.join(dirPath, Config.getLockFilename()))
         if os.path.exists(lockFilePath):
             SLogger.warning("%s already exists. Another swatch might be watching this directory or might not have shut down correctly. Consider using the scleanlockfiles command." % (lockFilePath))
             if dirPath == rootDirPath:
                 Commands.warning("Directory already watched", "Another swatch might be watching or might not have shut down correctly.")
         else:
             lockFile = open(lockFilePath, "w")
             lockFile.close()
             cls.__lockFiles.append(lockFilePath)
         
         cls.__observer.schedule(cls.__handler, path=dirPath)
示例#3
0
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)
示例#4
0
 def __cleanDir(cls, dirPath):
     lockFilePath = os.path.abspath(os.path.join(dirPath, Config.getLockFilename()))
     if os.path.exists(lockFilePath):
         SLogger.debug("Deleting %s" % os.path.abspath(lockFilePath))
         os.remove(lockFilePath)