Beispiel #1
0
def getTagList(obj, startJd, endJd):
    '''
        returns a list of (epoch, tag_name) tuples
    '''
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    cmd = [
        'git',
        '--git-dir', join(obj.vcsDir, '.git'),
        'tag',
    ]
    data = []
    for line in Popen(cmd, stdout=PIPE).stdout:
        tag = line.strip()
        if not tag:
            continue
        line = Popen([
            'git',
            '--git-dir', join(obj.vcsDir, '.git'),
            'log',
            '-1',
            tag,
            '--pretty=%ct',
        ], stdout=PIPE).stdout.read().strip()
        epoch = int(line)
        if epoch < startEpoch:
            continue
        if epoch >= endEpoch:
            break
        data.append((
            epoch,
            tag,
        ))
    return data
Beispiel #2
0
def getCommitListFromEst(obj, startJd, endJd, format_rev_id=None):
    '''
        returns a list of (epoch, rev_id) tuples
    '''
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for t0, t1, rev_id, dt in obj.est.search(startEpoch, endEpoch):
        if format_rev_id:
            rev_id = format_rev_id(obj.repo, rev_id)
        data.append((t0, rev_id))
    data.sort(reverse=True)
    return data
Beispiel #3
0
def getCommitListFromEst(obj, startJd, endJd, format_rev_id=None):
    '''
		returns a list of (epoch, rev_id) tuples
	'''
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for t0, t1, rev_id, dt in obj.est.search(startEpoch, endEpoch):
        if format_rev_id:
            rev_id = format_rev_id(obj.repo, rev_id)
        data.append((t0, rev_id))
    data.sort(reverse=True)
    return data
Beispiel #4
0
def getLastCommitIdUntilJd(obj, jd):
    untilEpoch = getEpochFromJd(jd)
    last = obj.est.getLastBefore(untilEpoch)
    if not last:
        return
    t0, t1, rev_id = last
    return str(obj.repo.get_revision(rev_id))
Beispiel #5
0
def getLastCommitIdUntilJd(obj, jd):
    untilEpoch = getEpochFromJd(jd)
    last = obj.est.getLastBefore(untilEpoch)
    if not last:
        return
    t0, t1, rev_id = last
    return str(obj.repo[rev_id])
Beispiel #6
0
def prepareToday():
    tm = getCurrentTime()
    (y, m, d) = localtime(tm)[:3]
    #log.debug('Date: %s/%s/%s   Epoch: %s'%(y, m, d, tm))
    todayJd = to_jd(y, m, d, DATE_GREG)
    dayRemainSecondsCeil = int(-(tm - 1)%(24*3600))
    timeout_add_seconds(dayRemainSecondsCeil, prepareToday)
    for group in eventGroups:
        if not group.enable:
            continue
        for epoch0, epoch1, eid in group.node.getEvents(getEpochFromJd(todayJd), getEpochFromJd(todayJd+1)):
            event = group[eid]
            if not event.notifiers:
                continue
            dt = epoch0 - event.getNotifyBeforeSec() - tm
            if dt >= 0:
                timeout_add_seconds(int(dt)+1, notify, eid)
Beispiel #7
0
def getTagList(obj, startJd, endJd):
    """
        returns a list of (epoch, tag_name) tuples
    """
    if not obj.repo:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for tag, unkown in obj.repo.tagslist():
        if tag == "tip":
            continue
        epoch = obj.repo[tag].date()[0]
        if startEpoch <= epoch < endEpoch:
            data.append((epoch, tag))
    data.sort()
    return data
Beispiel #8
0
def getCommitList(obj, startJd, endJd):
    """
        returns a list of (epoch, commit_id) tuples
    """
    if not obj.repo:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for rev in obj.repo.changelog:
        ctx = obj.repo[rev]
        epoch = ctx.date()[0]
        if epoch < startEpoch:
            continue
        if epoch >= endEpoch:
            break
        data.append((epoch, str(ctx)))
    return data
Beispiel #9
0
 def updateData(self):
     self.timeStart = getEpochFromJd(self.wcal.status[0].jd)
     self.pixelPerSec = float(self.get_allocation().height) / self.timeWidth ## pixel/second
     self.borderTm = 0 ## tbox.boxMoveBorder / self.pixelPerSec ## second
     self.boxes = tbox.calcEventBoxes(
         self.timeStart,
         self.timeStart + self.timeWidth,
         self.pixelPerSec,
         self.borderTm,
     )
Beispiel #10
0
def getTagList(obj, startJd, endJd):
    '''
		returns a list of (epoch, tag_name) tuples
	'''
    if not obj.repo:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for tag, rev_id in obj.branch.tags.get_tag_dict().iteritems():
        rev = obj.repo.get_revision(rev_id)
        epoch = rev.timestamp
        if startEpoch <= epoch < endEpoch:
            data.append((
                epoch,
                tag,
            ))
    data.sort()
    return data
Beispiel #11
0
def getTagList(obj, startJd, endJd):
    '''
        returns a list of (epoch, tag_name) tuples
    '''
    if not obj.repo:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for tag, rev_id in obj.branch.tags.get_tag_dict().iteritems():
        rev = obj.repo.get_revision(rev_id)
        epoch = rev.timestamp
        if startEpoch <= epoch < endEpoch:
            data.append((
                epoch,
                tag,
            ))
    data.sort()
    return data
Beispiel #12
0
 def updateData(self):
     from scal2.time_utils import getEpochFromJd
     from scal2.ui_gtk import timeline_box as tbox
     self.timeStart = getEpochFromJd(self.wcal.status[0].jd)
     self.pixelPerSec = float(self.get_allocation().height) / self.timeWidth ## pixel/second
     self.borderTm = 0 ## tbox.boxMoveBorder / self.pixelPerSec ## second
     self.boxes = tbox.calcEventBoxes(
         self.timeStart,
         self.timeStart + self.timeWidth,
         self.pixelPerSec,
         self.borderTm,
     )
Beispiel #13
0
def getTagList(obj, startJd, endJd):
    '''
		returns a list of (epoch, tag_name) tuples
	'''
    if not obj.repo:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    for tag, unkown in obj.repo.tagslist():
        if tag == 'tip':
            continue
        epoch = obj.repo[tag].date()[0]
        if startEpoch <= epoch < endEpoch:
            data.append((
                epoch,
                tag,
            ))
    data.sort()
    return data
Beispiel #14
0
	def updateData(self):
		from scal2.time_utils import getEpochFromJd
		from scal2.ui_gtk import timeline_box as tbox
		self.timeStart = getEpochFromJd(self.wcal.status[0].jd)
		self.pixelPerSec = float(self.get_allocation().height) / self.timeWidth ## pixel/second
		self.borderTm = 0 ## tbox.boxMoveBorder / self.pixelPerSec ## second
		self.boxes = tbox.calcEventBoxes(
			self.timeStart,
			self.timeStart + self.timeWidth,
			self.pixelPerSec,
			self.borderTm,
		)
Beispiel #15
0
def getCommitList(obj, startJd, endJd):
    '''
        returns a list of (epoch, rev_id) tuples
    '''
    branch = obj.branch
    if not branch:
        return []
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    ###
    data = []
    ## obj.repo.revisions
    for rev_id, depth, revno, end_of_merge in \
    branch.iter_merge_sorted_revisions(direction='forward'):
        rev = obj.repo.get_revision(rev_id)
        epoch = rev.timestamp
        if epoch < startEpoch:
            continue
        if epoch >= endEpoch:
            break
        data.append((epoch, rev_id))
    return data
Beispiel #16
0
def getTagList(obj, startJd, endJd):
    '''
		returns a list of (epoch, tag_name) tuples
	'''
    startEpoch = getEpochFromJd(startJd)
    endEpoch = getEpochFromJd(endJd)
    cmd = [
        'git',
        '--git-dir',
        join(obj.vcsDir, '.git'),
        'tag',
    ]
    data = []
    for line in Popen(cmd, stdout=PIPE).stdout:
        tag = line.strip()
        if not tag:
            continue
        line = Popen([
            'git',
            '--git-dir',
            join(obj.vcsDir, '.git'),
            'log',
            '-1',
            tag,
            '--pretty=%ct',
        ],
                     stdout=PIPE).stdout.read().strip()
        epoch = int(line)
        if epoch < startEpoch:
            continue
        if epoch >= endEpoch:
            break
        data.append((
            epoch,
            tag,
        ))
    return data
Beispiel #17
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch-timeStart)*pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd)-timeStart)*pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1+1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1+1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec ## px
    minMonthUnit = float(minStep) / avgMonthLen ## month
    if minMonthUnit <= 3:
        for ym in range(year0*12+month0-1, year1*12+month1-1+1):## +1 FIXME
            if ym%3==0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12) ; m+=1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                getMonthName(calTypes.primary, m) if unitSize >= majorStepMin else '',
            ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1+1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
                color=weekStartTickColor,
            ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1+1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day==16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel*dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit*stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec*pixelPerSec
        firstEpoch = iceil(timeStart/stepSec)*stepSec
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s==0:
                    label = '%s:%s'%(
                        _(h),
                        _(m, fillZero=2),
                    )
                else:# elif timeWidth < 60 or stepSec < 30:
                    label = LRM + '%s"'%_(s, fillZero=2)
                #else:
                #    label = '%s:%s:%s'%(
                #        _(h),
                #        _(m, fillZero=2),
                #        _(s, fillZero=2),
                #    )
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data
Beispiel #18
0
dayOfYear = lambda y, m, d: datesDiff(y, 1, 1, y, m, d) + 1

## jwday: Calculate day of week from Julian day
## 0 = Sunday
## 1 = Monday
jwday = lambda jd: (jd + 1) % 7

def getJdRangeForMonth(year, month, mode):
    day = getMonthLen(year, month, mode)
    return (
        to_jd(year, month, 1, mode),
        to_jd(year, month, day, mode) + 1,
    )

def getFloatYearFromEpoch(epoch, mode):
    module = calTypes[mode]
    return float(epoch - module.epoch)/module.avgYearLen + 1

def getEpochFromFloatYear(year, mode):
    module = calTypes[mode]
    return module.epoch + (year-1)*module.avgYearLen

getFloatYearFromJd = lambda jd, mode: getFloatYearFromEpoch(getEpochFromJd(jd), mode)

getJdFromFloatYear = lambda year, mode: getJdFromEpoch(getEpochFromFloatYear(year, mode))

getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode))


Beispiel #19
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec  ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch - timeStart) * pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd) - timeStart) * pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1 + 1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec  ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec  ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec  ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1 + 1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec  ## px
    minMonthUnit = float(minStep) / avgMonthLen  ## month
    if minMonthUnit <= 3:
        for ym in range(year0 * 12 + month0 - 1,
                        year1 * 12 + month1 - 1 + 1):  ## +1 FIXME
            if ym % 3 == 0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12)
            m += 1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    getMonthName(calTypes.primary, m)
                    if unitSize >= majorStepMin else '',
                ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1 + 1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    label,
                    color=weekStartTickColor,
                ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen  ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1 + 1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day == 16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel * dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit * stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec * pixelPerSec
        utcOffset = int(getUtcOffsetCurrent())
        firstEpoch = iceil(
            (timeStart + utcOffset) / stepSec) * stepSec - utcOffset
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s == 0:
                    label = '%s:%s' % (
                        _(h),
                        _(m, fillZero=2),
                    )
                else:  # elif timeWidth < 60 or stepSec < 30:
                    label = LRM + '%s"' % _(s, fillZero=2)
                #else:
                #	label = '%s:%s:%s'%(
                #		_(h),
                #		_(m, fillZero=2),
                #		_(s, fillZero=2),
                #	)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data
Beispiel #20
0
    yearStartJd = module.to_jd(year, 1, 1)
    nextYearStartJd = module.to_jd(year + 1, 1, 1)
    dayOfYear = jd - yearStartJd
    return year + float(dayOfYear) / (nextYearStartJd - yearStartJd)


def getJdFromFloatYear(fyear, mode):
    module = calTypes[mode]
    year = int(math.floor(fyear))
    yearStartJd = module.to_jd(year, 1, 1)
    nextYearStartJd = module.to_jd(year + 1, 1, 1)
    dayOfYear = int((fyear - year) * (nextYearStartJd - yearStartJd))
    return yearStartJd + dayOfYear


getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode))


def ymdRange(date1, date2, mode=None):
    y1, m1, d1 = date1
    y2, m2, d2 = date2
    if y1 == y2 and m1 == m2:
        for d in range(d1, d2):
            yield y1, m1, d
    if mode == None:
        mode = DATE_GREG
    calType = calTypes[mode]
    j1 = int(calType.to_jd(y1, m1, d1))
    j2 = int(calType.to_jd(y2, m2, d2))
    for j in range(j1, j2):
        yield calType.jd_to(j)