This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
/
common.py
145 lines (132 loc) · 4.21 KB
/
common.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import re
import time
import uuid
def getSupportedPlatforms():
return ('linux', 'linuxqt', 'linux64',
'win32', 'macosx', 'macosx64',
'win64', 'android',
'ics_armv7a_gecko',
'gb_armv7a_gecko', 'linux32_gecko',
'macosx64_gecko', 'win32_gecko',
'linux64_gecko', 'linux32_gecko_localizer',
'macosx64_gecko_localizer', 'win32_gecko_localizer',
'linux64_gecko_localizer')
def getPlatformFtpDir(platform):
platform_ftp_map = {
'linux': 'linux-i686',
'linux64': 'linux-x86_64',
'macosx': 'mac',
'macosx64': 'mac',
'win32': 'win32',
'win64': 'win64-x86_64',
'android': 'android-r7',
}
return platform_ftp_map.get(platform)
def genBuildID(now=None):
"""Return a buildid based on the current time"""
if not now:
now = time.time()
return time.strftime("%Y%m%d%H%M%S", time.localtime(now))
def genBuildUID():
"""Return a unique build uid"""
return uuid.uuid4().hex
def incrementBuildID(buildID):
"""Add 1 second to a buildID, handling rollovers to next minute/hour/etc"""
epoch = time.mktime(time.strptime(buildID, "%Y%m%d%H%M%S"))
return genBuildID(epoch + 1)
def normalizeName(name, product=None, min_=30, max_=30, filler='0'):
"""Shortens names and normalizes them within specified minimum
and maximum lengths. If names need lengthening, 'filler' is
appended until they reach the minimum length.
See https://bugzilla.mozilla.org/show_bug.cgi?id=827306 for background.
"""
origName = name
prefix = ''
if product != None and 'thunderbird' in product:
prefix = 'tb-'
mappings = {
'mozilla': 'm',
'comm': 'c',
'central': 'cen',
'1.9.1': '191',
'1.9.2': '192',
'places': 'plc',
'electrolysis': 'e10s',
'jaegermonkey': 'jm',
'shadow': 'sh',
'mobile': 'mb',
'desktop': '',
'debug': 'd',
'xulrunner': 'xr',
'build': 'bld',
'linux': 'lx',
'win32': 'w32',
'win64': 'w64',
'macosx': 'osx',
'macosx64': 'osx64',
'linux64': 'l64',
'android': 'and',
'release': 'rel',
'mochitest': 'm',
'browser-chrome': 'b-c',
'other': 'oth',
'browser': 'br',
'nightly': 'ntly',
'tryserver': 'try',
'cedar': 'ced',
'birch': 'bir',
'maple': 'map',
'leopard': 'leo',
'snowleopard': 'snow',
'fedora': 'fed',
'fedora64': 'fed64',
'ubuntu64': 'ub64',
'ubuntu32': 'ub32',
'repack': 'rpk',
'alder': 'a',
'holly': 'h',
'larch': 'l',
'accessibility': 'a11y',
'inbound': 'in',
'devtools': 'dev',
'services': 'srv',
'private-browsing': 'pb',
'gecko': 'g',
'localizer': 'lz',
'blocklistupdate': 'blu',
'armv6': 'a6',
'armv7a': 'a7',
'ionmonkey': 'ion',
'system': 'sys',
'panda': 'p',
'b2g18': 'b18',
'v1_0_0': '100',
'v1_0_1': '101',
'standalone': 'sa',
'thunderbird': 'tb',
'checksums': 'sums',
'update_verify': 'uv',
}
for word, replacement in mappings.iteritems():
# Regexes are slow, so make sure the word is there at all before
# trying to do a substitution.
if word in name:
# Match strings that...
regex = re.compile(
r'(-|_|\A)' + # Are the start of the string or after a separator
('%s' % word) + # Contain the word we're looking
r'(-|_|\Z)' # And don't have anything other the end of the string
# or a separator atfer them
)
name = regex.sub(r'\1%s\2' % replacement, name)
name = prefix + name
if len(name) > max_:
msg = 'Cannot shorten "%s" to maximum length (%d). Got to: %s' % (
origName, max_, name)
raise ValueError(msg)
# Add a seperator before the padding if necessary
if len(name) < min_:
name += '-'
while len(name) < min_:
name += filler
return name