Example #1
0
    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)
Example #2
0
 def cannotUpload(cls, updatedBy, remoteUpdatedOnString, localUpdateDateString):
     cannotUploadCommandTemplate = Config.getCannotUploadCommand()
     if cannotUploadCommandTemplate:
         command = cannotUploadCommandTemplate % {"person": updatedBy,
                                                  "remoteDate" : snowServerToLocalDate(remoteUpdatedOnString),
                                                  "localDate": localUpdateDateString}
         subprocess.call(shlex.split(str(command)))
Example #3
0
 def __init__(self, fileName, instance, tableName, sysId, nameFieldName, contentFieldName, updated_on):
     self.__fileName = fileName
     self.__instance = instance
     self.__tableName = tableName
     self.__sysId = sysId
     self.__nameFieldName = nameFieldName
     self.__contentFieldName = contentFieldName
     self.__updatedOn = snowServerToLocalDate(updated_on)
Example #4
0
 def setUpdatedOn(self, fileName, newUpdateDateString):
     if not self.__isTableCreated():
         self.__createTable()
     stringToWrite = snowServerToLocalDate(newUpdateDateString)
     self.__cursor.execute("UPDATE files SET updated_on = ? WHERE file_name = ?", (stringToWrite, fileName))
     return self.__cursor.rowcount > 0