Ejemplo n.º 1
0
    def getUidTimecode(cls, prefix=None, suffix=None):
        """ Creates a timecode down to the microsecond for use in creating unique UIDs. """
        out = Base64.to64(cls.getNowSeconds()) + '-' + Base64.to64(
            datetime.microsecond)

        return ((StringUtils.toUnicode(prefix) + '-') if prefix else '') + out \
            + (('-' + StringUtils.toUnicode(suffix)) if suffix else '')
Ejemplo n.º 2
0
    def getUidTimecode(cls, prefix=None, suffix=None):
        """ Creates a timecode down to the microsecond for use in creating unique UIDs. """
        out = Base64.to64(cls.getNowSeconds()) + "-" + Base64.to64(datetime.microsecond)

        return (
            ((StringUtils.toUnicode(prefix) + "-") if prefix else "")
            + out
            + (("-" + StringUtils.toUnicode(suffix)) if suffix else "")
        )
Ejemplo n.º 3
0
    def getSecondsFromTimecode(cls, timecode, zeroTime =None):
        if zeroTime is None:
            zeroTime = cls._ZERO_TIME

        if timecode is None:
            return zeroTime

        return 60*(Base64.from64(timecode)) + zeroTime
Ejemplo n.º 4
0
    def getSecondsFromTimecode(cls, timecode, zeroTime =None):
        if zeroTime is None:
            zeroTime = cls._ZERO_TIME

        if timecode is None:
            return zeroTime

        return 60*(Base64.from64(timecode)) + zeroTime
Ejemplo n.º 5
0
 def createUniqueId(cls, prefix = u''):
     """ Creates a universally unique identifier string based on current
         time, active application instance state, and a randomized hash
     """
     cls._UID_INDEX += 1
     return '%s%s-%s-%s' % (
         prefix,
         TimeUtils.getNowTimecode(cls.BASE_UNIX_TIME),
         Base64.to64(cls._UID_INDEX),
         StringUtils.getRandomString(12))
Ejemplo n.º 6
0
    def getTimecodeFromDatetime(cls, time =None, zeroTime =None, rotationInterval =None):
        if zeroTime is None:
            zeroTime = cls._ZERO_TIME

        if rotationInterval is None:
            rotationInterval = cls._ROTATION_INTERVAL

        if time is None:
            time = datetime.datetime.utcnow()

        t = float(TimeUtils.datetimeToSeconds(time) - zeroTime)/60.0
        t = float(rotationInterval)*math.floor(t/float(rotationInterval))
        return Base64.to64(int(t))
Ejemplo n.º 7
0
    def getTimecodeFromDatetime(cls, time =None, zeroTime =None, rotationInterval =None):
        if zeroTime is None:
            zeroTime = cls._ZERO_TIME

        if rotationInterval is None:
            rotationInterval = cls._ROTATION_INTERVAL

        if time is None:
            time = datetime.datetime.utcnow()

        t = float(TimeUtils.datetimeToSeconds(time) - zeroTime)/60.0
        t = float(rotationInterval)*math.floor(t/float(rotationInterval))
        return Base64.to64(int(t))
Ejemplo n.º 8
0
 def timecodeToDatetime(cls, timeCode, baseTime=0):
     """ Returns the datetime object that represents the given Base64 timeCode for the given
         base time, which by default is 0.
     """
     return cls.secondsToDatetime(Base64.from64(timeCode) + baseTime)
Ejemplo n.º 9
0
 def getPrefix(self):
     return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
Ejemplo n.º 10
0
 def to64(cls, value):
     """Doc..."""
     return Base64.to64(int(value))
Ejemplo n.º 11
0
 def i64(self):
     return Base64.to64(self.i)
Ejemplo n.º 12
0
 def to64(cls, value):
     """Doc..."""
     return Base64.to64(int(value))
Ejemplo n.º 13
0
 def from64(cls, value):
     """Doc..."""
     return Base64.from64(value, True)
Ejemplo n.º 14
0
 def getPrefix(self):
     return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
Ejemplo n.º 15
0
 def datetimeToTimecode(cls, dt, baseTime=0):
     """ Returns a timecode (base64 encoded seconds string) for the given datetime object and
         offset by the baseTime number of seconds.
     """
     return Base64.to64(cls.datetimeToSeconds(dt) - baseTime)
Ejemplo n.º 16
0
 def timecodeToDatetime(cls, timeCode, baseTime =0):
     """ Returns the datetime object that represents the given Base64 timeCode for the given
         base time, which by default is 0.
     """
     return cls.secondsToDatetime(Base64.from64(timeCode) + baseTime)
Ejemplo n.º 17
0
 def getNowTimecode(cls, baseTime=0):
     return Base64.to64(cls.getNowSeconds() - baseTime)
Ejemplo n.º 18
0
 def datetimeToTimecode(cls, dt, baseTime =0):
     """ Returns a timecode (base64 encoded seconds string) for the given datetime object and
         offset by the baseTime number of seconds.
     """
     return Base64.to64(cls.datetimeToSeconds(dt) - baseTime)
Ejemplo n.º 19
0
 def _parseTimestamp(cls, value):
     if value is None:
         return datetime.datetime.utcnow()
     elif StringUtils.isStringType(value):
         return TimeUtils.secondsToDatetime(Base64.from64(value) + PyGlassEnvironment.BASE_UNIX_TIME)
     return value
Ejemplo n.º 20
0
 def getNowTimecode(cls, baseTime =0):
     return Base64.to64(cls.getNowSeconds() - baseTime)
Ejemplo n.º 21
0
 def getCurrentID(cls, sep ='::'):
     return str(os.getpid()) + '-' + Base64.to64(threading.current_thread().ident) \
         + sep + str(threading.current_thread().name)
Ejemplo n.º 22
0
 def from64(cls, value):
     """Doc..."""
     return Base64.from64(value, True)