def _importClass(self, className): classloader = ZClassLoader() classObj = classloader.loadClass(className) if not (issubclass(classObj, IZCustomLogOutput)): raise ValueError, _extstr( u"logoutput.ClassMustExtendIZCustomLogOutputError" ) % className #$NON-NLS-1$ return classObj
def shutdown(self): self.done = True self.debug( u"", -1, None, _extstr(u"logger.ShuttingDownLogger")) #$NON-NLS-1$ #$NON-NLS-2$ while self.running: pass
def _initFromString(self, dtString): m = DATE_TIME_PATTERN.match(dtString) if not m: raise ZException( _extstr(u"schematypes.FailedToParseDateTimeString") % dtString) #$NON-NLS-1$ year = m.group(2) month = m.group(3) day = m.group(4) hour = m.group(5) minute = m.group(6) second = m.group(7) isUTC = (not m.group(10)) or (m.group(10) == u"Z") #$NON-NLS-1$ tz = UTC_TIMEZONE if not isUTC: tzDir = m.group(12) tzHr = m.group(13) tzMin = m.group(14) tz = ZSimpleTimeZone(tzHr, tzMin, tzDir) # Note: not sure about the millis param... self._initFromYYYYMMDDHHMMSS(int(year), int(month), int(day), int(hour), int(minute), int(second), tz)
def saveProperties(self): try: tempSysPropsFileName = self.sysPropsFileName + u".t" #$NON-NLS-1$ self.sysPropsDoc.save(tempSysPropsFileName, True) deleteFile(self.sysPropsFileName) renameFile(tempSysPropsFileName, self.sysPropsFileName) except Exception, e: raise ZException(_extstr(u"sysprops.ErrorSavingPropsFile") % self.sysPropsFileName, e) #$NON-NLS-1$
def run(self): self.done = False try: if self.runnable: self.runnable.run() else: self._run() except Exception, e: self._handleException(ZException(_extstr(u"zthread.UnexpectedErrorInThread"), e)) #$NON-NLS-1$
def doCommand(self): u"""Sequentially invokes doCommand on each of the commands in the collection.""" #$NON-NLS-1$ for command in self.getCommands(): if not self.isCancelled(): try: command.doCommand() except Exception, e: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInDoCommand"), e)) #$NON-NLS-1$ except: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInDoCommand"))) #$NON-NLS-1$
def saveProperties(self): try: tempSysPropsFileName = self.sysPropsFileName + u".t" #$NON-NLS-1$ self.sysPropsDoc.save(tempSysPropsFileName, True) deleteFile(self.sysPropsFileName) renameFile(tempSysPropsFileName, self.sysPropsFileName) except Exception, e: raise ZException( _extstr(u"sysprops.ErrorSavingPropsFile") % self.sysPropsFileName, e) #$NON-NLS-1$
def deleteFile(path): # If the path does not exist, just return. if not os.path.exists(path): return # If the path exists but is not a file, that's an error. if not os.path.isfile(path): raise ZException(_extstr(u"fileutil.InvalidFilePath") % path) #$NON-NLS-1$ os.remove(path)
def deleteDirectory(path, alsoDeleteDir=True, deleteFilter=EVERYTHING_FILTER): u"""deleteDirectory(string, boolean?) -> None Recursively deletes the contents of the given directory. If the alsoDeleteDir boolean flag is True, then the directory itself is also deleted. If it is False, then only the contents of the directory are deleted.""" #$NON-NLS-1$ # If the path doesn't exist, just return 0. if not os.path.exists(path): return 0 # Throw if the root path is given as the param! if path == u"/" or path.endswith(u":/") or path.endswith( u":\\"): #$NON-NLS-3$ #$NON-NLS-2$ #$NON-NLS-1$ raise ZException( _extstr(u"fileutil.FailedToDeleteRootPathMsg")) #$NON-NLS-1$ # If the path exists, but is not a directory, that's an error. if not os.path.isdir(path): raise ZException(_extstr(u"fileutil.InvalidDirPath") % path) #$NON-NLS-1$ try: count = 0 files = os.listdir(path) for file in files: fullFile = os.path.join(path, file) if os.path.isfile(fullFile): if deleteFilter(fullFile): deleteFile(fullFile) count = count + 1 else: shouldDeleteDir = deleteFilter(fullFile) count = count + deleteDirectory(fullFile, shouldDeleteDir, deleteFilter) if alsoDeleteDir: os.rmdir(path) return count except Exception, e: raise ZException(_extstr(u"fileutil.DirDeleteFailed") % path, e) #$NON-NLS-1$
def run(self): self.done = False try: if self.runnable: self.runnable.run() else: self._run() except Exception, e: self._handleException( ZException(_extstr(u"zthread.UnexpectedErrorInThread"), e)) #$NON-NLS-1$
def undoCommand(self): u"""Sequentially (in reverse order) invokes undoCommand on each of the commands in the collection.""" #$NON-NLS-1$ cmdList = [] cmdList.extend( self.getCommands() ) cmdList.reverse() for command in cmdList: try: command.undoCommand() except Exception, e: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInUnDoCommand"), e)) #$NON-NLS-1$ except:
def doCommand(self): u"""Sequentially invokes doCommand on each of the commands in the collection.""" #$NON-NLS-1$ for command in self.getCommands(): if not self.isCancelled(): try: command.doCommand() except Exception, e: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInDoCommand"), e)) #$NON-NLS-1$ except: self._handleException(
def __init__(self, date = None): param = date if not date: param = getCurrentUtcDateTime() if isinstance(param, str) or isinstance(param, unicode): self._initFromString(param) elif isinstance(param, long) or isinstance(param, int): self._initFromLongMs(param) elif isinstance(param, datetime): self.dateTime = convertToUtcDateTime(param) else: raise ZException(_extstr(u"schematypes.SchemaDateTimeFormatError")) #$NON-NLS-1$
def __init__(self, date=None): param = date if not date: param = getCurrentUtcDateTime() if isinstance(param, str) or isinstance(param, unicode): self._initFromString(param) elif isinstance(param, long) or isinstance(param, int): self._initFromLongMs(param) elif isinstance(param, datetime): self.dateTime = convertToUtcDateTime(param) else: raise ZException(_extstr( u"schematypes.SchemaDateTimeFormatError")) #$NON-NLS-1$
def undoCommand(self): u"""Sequentially (in reverse order) invokes undoCommand on each of the commands in the collection.""" #$NON-NLS-1$ cmdList = [] cmdList.extend(self.getCommands()) cmdList.reverse() for command in cmdList: try: command.undoCommand() except Exception, e: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInUnDoCommand"), e)) #$NON-NLS-1$ except:
def deleteDirectory(path, alsoDeleteDir = True, deleteFilter = EVERYTHING_FILTER): u"""deleteDirectory(string, boolean?) -> None Recursively deletes the contents of the given directory. If the alsoDeleteDir boolean flag is True, then the directory itself is also deleted. If it is False, then only the contents of the directory are deleted.""" #$NON-NLS-1$ # If the path doesn't exist, just return 0. if not os.path.exists(path): return 0 # Throw if the root path is given as the param! if path == u"/" or path.endswith(u":/") or path.endswith(u":\\"): #$NON-NLS-3$ #$NON-NLS-2$ #$NON-NLS-1$ raise ZException(_extstr(u"fileutil.FailedToDeleteRootPathMsg")) #$NON-NLS-1$ # If the path exists, but is not a directory, that's an error. if not os.path.isdir(path): raise ZException(_extstr(u"fileutil.InvalidDirPath") % path) #$NON-NLS-1$ try: count = 0 files = os.listdir(path) for file in files: fullFile = os.path.join(path, file) if os.path.isfile(fullFile): if deleteFilter(fullFile): deleteFile(fullFile) count = count + 1 else: shouldDeleteDir = deleteFilter(fullFile) count = count + deleteDirectory(fullFile, shouldDeleteDir, deleteFilter) if alsoDeleteDir: os.rmdir(path) return count except Exception, e: raise ZException(_extstr(u"fileutil.DirDeleteFailed") % path, e) #$NON-NLS-1$
def getFileMetaData(fileName): u"""getFileMetaData(string) -> (string, string, int, ZSchemaDateTime) Called to get meta information about a file. Pass in the file name and get back a tuple of information: (shortFileName, abs file name, file size, timestamp).""" #$NON-NLS-1$ if not os.path.isfile(fileName): raise ZException(_extstr(u"fileutil.NotAValidFileError") % fileName) #$NON-NLS-1$ shortName = os.path.basename(fileName) absPath = os.path.abspath(fileName) status = os.lstat(absPath) size = status[stat.ST_SIZE] modEpoch = status[stat.ST_MTIME] modifiedTimeDT = getDateTimeFromEpoch(modEpoch) return (shortName, absPath, size, ZSchemaDateTime(modifiedTimeDT))
class ZCommandGroup(ZCommandBase): u"""Encapsulates a group of commands.""" #$NON-NLS-1$ def __init__(self, command=None, name=None): ZCommandBase.__init__(self, name) self.commands = [] self.addCommand(command) def addCommand(self, command): u"""addCommand(IZCommand) -> void Adds the given command to internal collection.""" #$NON-NLS-1$ if command and command != self and command not in self.commands: self.commands.append(command) def getCommands(self): u"""getCommands() -> list of IZCommand objects Returns list of commands.""" #$NON-NLS-1$ return self.commands def cancel(self): u"""Flags all commands in the collection as cancelled.""" #$NON-NLS-1$ for command in self.getCommands(): command.cancel() ZCommandBase.cancel(self) def doCommand(self): u"""Sequentially invokes doCommand on each of the commands in the collection.""" #$NON-NLS-1$ for command in self.getCommands(): if not self.isCancelled(): try: command.doCommand() except Exception, e: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInDoCommand"), e)) #$NON-NLS-1$ except: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInDoCommand")) ) #$NON-NLS-1$
def _initFromString(self, dtString): m = DATE_TIME_PATTERN.match(dtString) if not m: raise ZException(_extstr(u"schematypes.FailedToParseDateTimeString") % dtString) #$NON-NLS-1$ year = m.group(2); month = m.group(3); day = m.group(4); hour = m.group(5); minute = m.group(6); second = m.group(7); isUTC = (not m.group(10)) or (m.group(10) == u"Z") #$NON-NLS-1$ tz = UTC_TIMEZONE if not isUTC: tzDir = m.group(12) tzHr = m.group(13) tzMin = m.group(14) tz = ZSimpleTimeZone(tzHr, tzMin, tzDir) # Note: not sure about the millis param... self._initFromYYYYMMDDHHMMSS(int(year), int(month), int(day), int(hour), int(minute), int(second), tz)
def run(self): self.done = False try: if self.runnable: self.runnable.run() else: self._run() except Exception, e: self._handleException( ZException(_extstr(u"zthread.UnexpectedErrorInThread"), e)) #$NON-NLS-1$ except: self._handleException( ZException( _extstr(u"zthread.UnexpectedErrorInThread"))) #$NON-NLS-1$ self.done = True # end run() def _handleException(self, zexception): #@UnusedVariable zexception.printStackTrace() # end _handleException() def _run(self): pass # end _run() def isDone(self):
def checkDirectory(dirPath): if not os.path.isdir(dirPath): raise ZException(_extstr(u"fileutil.InvalidDirPath") % dirPath) #$NON-NLS-1$
def checkFile(fileName): if not os.path.isfile(fileName): raise ZException(_extstr(u"fileutil.InvalidFilePath") % fileName) #$NON-NLS-1$
def _importClass(self, className): classloader = ZClassLoader() classObj = classloader.loadClass(className) if not (issubclass(classObj, IZCustomLogOutput)): raise ValueError, _extstr(u"logoutput.ClassMustExtendIZCustomLogOutputError") % className #$NON-NLS-1$ return classObj
name = u"ZThread" #$NON-NLS-1$ Thread.__init__(self, None, None, name) self.setDaemon(daemonic) # end __init__() def run(self): self.done = False try: if self.runnable: self.runnable.run() else: self._run() except Exception, e: self._handleException(ZException(_extstr(u"zthread.UnexpectedErrorInThread"), e)) #$NON-NLS-1$ except: self._handleException(ZException(_extstr(u"zthread.UnexpectedErrorInThread"))) #$NON-NLS-1$ self.done = True # end run() def _handleException(self, zexception): #@UnusedVariable zexception.printStackTrace() # end _handleException() def _run(self): pass # end _run() def isDone(self): return self.done # end isDone()
u"""Sequentially (in reverse order) invokes undoCommand on each of the commands in the collection.""" #$NON-NLS-1$ cmdList = [] cmdList.extend(self.getCommands()) cmdList.reverse() for command in cmdList: try: command.undoCommand() except Exception, e: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInUnDoCommand"), e)) #$NON-NLS-1$ except: self._handleException( ZException( _extstr(u"zcommand.UnexpectedErrorInUnDoCommand")) ) #$NON-NLS-1$ # ---------------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------------- class ZAsyncCommand(ZThread, IZCommand): u"""Command which executes the given command on a daemon thread.""" #$NON-NLS-1$ def __init__(self, command): self.command = command self.running = False name = command.getName() + u"_ZAsyncCommand" #$NON-NLS-1$ ZThread.__init__(self, name=name, daemonic=True)
def shutdown(self): self.done = True self.debug(u"", -1, None, _extstr(u"logger.ShuttingDownLogger")) #$NON-NLS-1$ #$NON-NLS-2$ while self.running: pass
self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInDoCommand"), e)) #$NON-NLS-1$ except: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInDoCommand"))) #$NON-NLS-1$ def undoCommand(self): u"""Sequentially (in reverse order) invokes undoCommand on each of the commands in the collection.""" #$NON-NLS-1$ cmdList = [] cmdList.extend( self.getCommands() ) cmdList.reverse() for command in cmdList: try: command.undoCommand() except Exception, e: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInUnDoCommand"), e)) #$NON-NLS-1$ except: self._handleException(ZException(_extstr(u"zcommand.UnexpectedErrorInUnDoCommand"))) #$NON-NLS-1$ # ---------------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------------- class ZAsyncCommand(ZThread, IZCommand): u"""Command which executes the given command on a daemon thread.""" #$NON-NLS-1$ def __init__(self, command): self.command = command self.running = False name = command.getName() + u"_ZAsyncCommand" #$NON-NLS-1$ ZThread.__init__(self, name = name, daemonic = True) # end __init__() def isRunning(self):