1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import os
import sys
import syslog
import datetime
import bzwmfphab as bzlib
import rtlib
import fablib
from phabapi import phabapi as Phab
from phabdb import phdb
from phabdb import mailinglist_phid
from phabdb import set_project_icon
from config import cfile as configfile
import time
def now():
return int(time.time())
def tflatten(t_of_tuples):
return [element for tupl in t_of_tuples for element in tupl]
#import priority status meanings
ipriority = {'creation_failed': 6,
'creation_success': 7,
'fetch_failed': 5,
'na': 0,
'update_success': 8,
'update_failed': 9,
'unresolved': 1}
def return_bug_list():
if sys.stdin.isatty():
bugs = sys.argv[1:]
else:
bugs = sys.stdin.read().strip('\n').strip().split()
if '-' in bugs[0]:
start, stop = bugs[0].split('-')
bugrange = range(int(start), int(stop) + 1)
bugs = [str(b) for b in bugrange]
else:
bugs = [i for i in bugs if i.isdigit()]
log("Bugs count: %d" % (len(bugs)))
return bugs
def datetime_to_epoch(date_time):
return str((date_time - datetime.datetime(1970,1,1)).total_seconds())
def epoch_to_datetime(epoch, timezone='UTC'):
return str((datetime.datetime.fromtimestamp(int(float(epoch))
).strftime('%Y-%m-%d %H:%M:%S'))) + " (%s)" % (timezone,)
def errorlog(msg):
msg = unicode(msg)
try:
syslog.syslog(msg)
print >> sys.stderr, msg
except:
print 'error logging, well...error output'
def log(msg):
msg = unicode(msg)
if '-v' in ''.join(sys.argv):
try:
syslog.syslog(msg)
print msg
except:
print 'error logging output'
def vlog(msg):
msg = unicode(msg)
if '-vv' in ''.join(sys.argv):
try:
print '-> ', msg
except:
print 'error logging output'
def save_attachment(name, data):
f = open(name, 'wb')
f.write(data)
f.close()
|