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 run(cls, targetURL, *extraArgs): instance, tableName, sysId = cls.__parseURL(targetURL) nameField, contentField, fileExtension = cls._getTableInfo(tableName) localDir = os.getcwd() db = SnowFileDB(localDir) client = SnowClient(tableName, instance) record = client.get(sysId) if len(extraArgs) > 0: fileName = extraArgs[0] else: fileName = "%s.%s" % ( getattr(record, nameField).replace(" ", "-").replace("/", "-").replace("(", "[").replace(")", "]"), fileExtension, ) filePath = os.path.join(localDir, fileName) if os.path.exists(filePath): SLogger.warning("Local file %s already exists, will not overwrite" % filePath) return # if os.path.isfile(os.path.join(localDir, Config.getLockFilename())): # #swatch is watching, we do not want him to re-upload, we write a file for swatch.py to know # ignoreWatchFilePath = filePath + Config.getIgnoreWatchFilenameSuffix() # SLogger.debug("Creating file %s to avoid swatch to re-upload" % ignoreWatchFilePath) # ignoreWatchFile = open(ignoreWatchFilePath, "w") # ignoreWatchFile.close() f = codecs.open(filePath, "w", "utf-8") content = normalizeNewlines(getattr(record, contentField)) f.write(content) f.close() db.addFileInfo( FileInfo(fileName, instance, tableName, record.sys_id, nameField, contentField, record.sys_updated_on) ) db.commitAndClose() SLogger.debug("Done. Written to %s" % fileName)