def processFile(self, filePath): ignoreWatchFilePath = filePath + Config.getIgnoreWatchFilenameSuffix() if os.path.isfile(ignoreWatchFilePath): #this file was updated by supdate.py, do not process os.remove(ignoreWatchFilePath) return #Loic Horisberger - 17.10.2014: #This is a fix for MacVIM where current files are swap files. #If the file ends with ".swp", remove the extention to get the #original filename. Remove the "." at the beginning that makes #the file hidden as well. if filePath.endswith(".swp"): filePath = filePath.replace(".swp","") filePath = filePath[::-1].replace("/."[::-1],"/"[::-1],1)[::-1] self.__dbWorker.getFileInfo(self, filePath) fileInfo = self.__inputQueue.get() if fileInfo: SLogger.debug("Local modification detected for: %s" % filePath) client = clientPool.getClient(fileInfo.getTableName(), fileInfo.getInstance()) localUpdateDateString = fileInfo.getUpdatedOn() canUpdate = True if localUpdateDateString: SLogger.debug("Checking remote version...") remoteRecord = client.get(fileInfo.getSysId()) remoteUpdatedOnString = remoteRecord.sys_updated_on canUpdate = checkCanUpdate(localUpdateDateString, remoteUpdatedOnString) if canUpdate: SLogger.debug("Done") else: SLogger.warning("Remote file changed by %s on %s. Previous local version is %s. Cannot update" % (remoteRecord.sys_updated_by, snowServerToLocalDate(remoteUpdatedOnString), localUpdateDateString)) Commands.cannotUpload(remoteRecord.sys_updated_by, remoteUpdatedOnString, localUpdateDateString) if canUpdate: SLogger.debug("Updating in SNOW...") content = codecs.open(filePath, "r", "utf-8").read() success = client.updateContent(fileInfo.getSysId(), fileInfo.getContentFieldName(), content) if success: SLogger.debug("Updating local update date...") newRemoteRecord = client.get(fileInfo.getSysId()) newRemoteUpdatedOnString = newRemoteRecord.sys_updated_on self.__dbWorker.setUpdatedOn(self, filePath, newRemoteUpdatedOnString) confirmation = self.__inputQueue.get() if confirmation: SLogger.debug("Success updating %s" % fileInfo.getFileName()) Commands.success(fileInfo) else: SLogger.warning("Update of local date failed for file %s" % fileInfo) Commands.warning("Upload failed", "Update of local date failed for file %s" % fileInfo) else: SLogger.warning("Update of local date failed for file %s" % fileInfo) Commands.warning("Upload failed", "Update of local date failed for file %s" % fileInfo)
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))