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 __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)