Beispiel #1
0
Datei: bugz.py Projekt: mtvee/bgz
 def do_time( self, args ):
     """ add or report time 
     
     bgz time
         report on time for this week (Monday - Sunday)
         
     bgz time add ID
         add a new time entry for the given ID
         
     bgz time DATERANGE
         report on time for a DATERANGE
         a DATERANGE can be:
         tw | [thisw]eek = this week (Monday - Sunday)
         lw | [lastw]eek = last week (Monday - Sunday)
         [y]esterday     = (midnight - midnight)
         [t]oday | [n]ow = (midnight - now)
         DD/MM/YYYY[:DD/MM/YYYY]
     """
     self._check_status()
     if len(args) == 0:
         args.append("thisweek")
     if args[0] == 'add':
         if len(args) < 2:
             return False
         dur = self._read_input( "Duration (0:0)", None, lambda x: re.match("\d?:\d+", x) )
         if len(dur) and self.do_comment(args[1:], 'time ' + dur ):
             return True
         else:
             return False
     else:
         # QnD report
         dts = dateparse.DateParser().parse_date_range( args[0] )
         s = 'Time Report'
         s += ' - ' + dts[0].strftime("%Y-%m-%d") + " / " + dts[1].strftime("%Y-%m-%d")
         print '-' * len(s)
         print s
         print '-' * len(s)
         projects = self._read_projects()
         gtotal = [0,0]
         for proj in projects:
             puthdr = True
             issue = Issue( proj )
             files = os.listdir( proj )
             for file in files:
                 if not issue.load( file ):
                     continue
                 tm = issue.time_total( dts ) 
                 if tm[0] > 0 or tm[1] > 0:
                     gtotal[0] += tm[0]
                     gtotal[1] += tm[1]
                     if puthdr:
                         print 'Project: ' + proj[:-(len(proj)-proj.rfind('.'))]
                         puthdr = False
                     print issue.rep( dts )
         gtotal[0] += gtotal[1]/60
         gtotal[1] = gtotal[1] % 60
         t = 'Total: %d:%02d'  % (gtotal[0],gtotal[1])
         print '=' * len(t)
         print t
Beispiel #2
0
Datei: bugz.py Projekt: mtvee/bgz
 def do_show( self, args ):
     """ show stuff 
     
     bgz show [partial_UUID]
     bgz show [a:author] [s:status] [ty:type] [ti:title] [d:date_range] 
     bgz show all
     """
     self._check_status()
     files = os.listdir( self.BGZ_DIR )
     issues = {}
     for file in files:
         issue = Issue(self.BGZ_DIR)
         if not issue.load( file ):
             continue
         if len(args) and args[0].find(':') != -1:
             hitcount = 0
             for arg in args:
                 tmp = arg.split(':')
                 if tmp[0].startswith('s'): 
                     if issue['Status'][0] == tmp[1][0]:
                         hitcount = hitcount + 1
                 elif tmp[0].startswith('ty'):
                     if issue['Type'][0] == tmp[1][0]:
                         hitcount = hitcount + 1
                 elif tmp[0].startswith('ti'):
                     if issue['Title'].find( tmp[1] ) != -1:
                         hitcount = hitcount + 1
                 elif tmp[0].startswith('a'):
                     if issue['Author'].find( tmp[1] ) != -1:
                         hitcount = hitcount + 1
                 elif tmp[0].startswith('d'):
                     # date range
                     dts = dateparse.DateParser().parse_date_range( tmp[1] )
                     if issue.date() >= dts[0] and issue.date() <= dts[1]:
                         hitcount = hitcount + 1
                 else:
                     raise BugzError( "Unknown qualifier: " + tmp[0] )
             # if all the args hit, then print it
             if hitcount == len( args ):
                 if not issues.has_key( issue['Type'] ):
                     issues[issue['Type'][0]] = []
                 issues[issue['Type'][0]].append( issue )
         elif len(args) and args[0] == 'all':
             if not issues.has_key( issue['Type'] ):
                 issues[issue['Type'][0]] = []
             issues[issue['Type'][0]].append( issue )
         else:
             if len(args):
                 if file.startswith( args[0] ):
                     issue.show()
                     return
     self._show_issues( issues )
Beispiel #3
0
Datei: bugz.py Projekt: mtvee/bgz
 def do_purge( self, args ):
     """ move closed issues to 'PROJECT/.bugz/purged' directory
     
     bgz purge
     """
     self._check_status()
     ppath = os.path.join(self.BGZ_DIR, 'purged')
     if not os.path.exists( ppath ):
         try:
             os.mkdir( ppath )
         except:
             raise BugzError( 'abort: unable to create ' + ppath )
     count = 0
     for file in os.listdir( self.BGZ_DIR ):
         issue = Issue(self.BGZ_DIR)
         if not issue.load( file ):
             continue
         if issue['Status'][0] == 'c':
             shutil.move(os.path.join(self.BGZ_DIR,file), ppath)
             count += 1
     self._log( 'purged %d issue(s)' % (count) )
Beispiel #4
0
Datei: bugz.py Projekt: mtvee/bgz
 def _find_issue( self, uid ):
     """ find an issue with a partial uid """
     if uid.startswith('g'):
         if not os.path.exists(os.path.join(self.BGZ_DIR,'general.' + self.opts['user.name'])):
             gen = Issue(self.BGZ_DIR)
             gen['Id'] = 'general.' + self.opts['user.name']
             gen['Title'] = 'General Project Catchall'
             gen['Author'] = self.opts['user.name']
             gen['Type'] = 'task'
             gen['Status'] = 'open'
             gen.save()
     flist = self._find_issues( uid )
     if len(flist) == 1:
         iss = Issue(self.BGZ_DIR)
         if not iss.load( flist[0] ):
             return None
         return iss
     elif len(flist) > 1:
         print 'Please be more specific: '
         for f in flist:
             print f
     return None
Beispiel #5
0
Datei: bugz.py Projekt: mtvee/bgz
 def do_status( self, args ):
     """ get the database status 
     
     bgz status [all]
     """
     self._check_status()
     files = os.listdir( self.BGZ_DIR )
     counts = {'new':0,'open':0,'closed':0}
     issues = {}
     for file in files:
         issue = Issue(self.BGZ_DIR)
         if not issue.load( file ):
             continue
         counts[issue['Status']] += 1
         if not issues.has_key( issue['Type'][0] ):
             issues[issue['Type'][0]] = []
             
         if next((a for a in args if a == 'all'),None):
             issues[issue['Type'][0]].append( issue )
         elif issue['Status'][0] != 'c':
             issues[issue['Type'][0]].append( issue )
     print 'Status: ',
     for k in counts.keys():
         pre = ""
         post = ""
         if self.opts.ansi:
             post = "\033[0m"    # reset
             if k[0] == 'n':
                 pre = "\033[31m"    # red     
             elif k[0] == 'c':
                 pre = "\033[32m"    # green   
             elif k[0] == 'o':
                 pre = "\033[33m"    # yellow                 
         print pre + k + post + "/" + str(counts[k]) + " ",
     print
     self._show_issues( issues )