forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathrelease_utils.py
More file actions
149 lines (118 loc) · 4.42 KB
/
Copy pathrelease_utils.py
File metadata and controls
149 lines (118 loc) · 4.42 KB
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
146
147
148
#! /usr/bin/python
################################################################################
# #
# Copyright (C) 2011-2015, Armory Technologies, Inc. #
# Distributed under the GNU Affero General Public License (AGPL v3) #
# See LICENSE or http://www.gnu.org/licenses/agpl.html #
# #
################################################################################
from __future__ import print_function
import sys
import os
import time
import shutil
from subprocess import Popen, PIPE
################################################################################
def execAndWait(cli_str, timeout=0, usepipes=True, cwd=None):
"""
There may actually still be references to this function where check_output
would've been more appropriate. But I didn't know about check_output at
the time...
"""
if isinstance(cli_str, (list, tuple)):
cli_str = ' '.join(cli_str)
print('Executing:', '"' + cli_str + '"')
if usepipes:
process = Popen(cli_str, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, cwd=cwd)
else:
process = Popen(cli_str, shell=True, cwd=cwd)
pid = process.pid
start = time.time()
while process.poll() == None:
time.sleep(0.1)
if timeout>0 and (time.time() - start)>timeout:
print('Process exceeded timeout, killing it')
killProcess(pid)
out,err = process.communicate()
return [out,err]
################################################################################
# Copied from armoryengine.py
def getVersionString(vquad, numPieces=4):
vstr = '%d.%02d' % vquad[:2]
if (vquad[2] > 0 or vquad[3] > 0) and numPieces>2:
vstr += '.%d' % vquad[2]
if vquad[3] > 0 and numPieces>3:
vstr += '.%d' % vquad[3]
return vstr
def readVersionString(verStr):
verList = [int(piece) for piece in verStr.split('.')]
while len(verList)<4:
verList.append(0)
return tuple(verList)
def getVersionInt(vquad, numPieces=4):
vint = int(vquad[0] * 1e7)
vint += int(vquad[1] * 1e5)
if numPieces>2:
vint += int(vquad[2] * 1e3)
if numPieces>3:
vint += int(vquad[3])
return vint
################################################################################
# Extract [osName, verStr, verInt, verType, ext]
# Example ['winAll', '0.91.1', 91001000, 'rc1', '.exe']
def parseInstallerName(fn):
pcs = fn.split('_')
if not len(pcs)==3 or not pcs[0]=='armory':
return None
temp,verWhole,osNameExt = pcs[:]
vpcs = verWhole.split('-')
verStr = vpcs[0]
verType = ('-'+vpcs[1]) if len(vpcs)>1 else ''
epcs = osNameExt.split('.')
osName = epcs[0]
osExt = '.'.join(epcs[1:])
verQuad = readVersionString(verStr)
verInt = getVersionInt(verQuad)
return [osName, verStr, verInt, verType, osExt]
################################################################################
# Parse filenames to return the latest version number present (and assoc type)
def getLatestVerFromList(filelist):
latestVerInt = 0
latestVerStr = ''
verType = ''
# Find the highest version number
for fn in filelist:
fivevals = parseInstallerName(fn)
if fivevals is None:
continue;
verstr,verint,vertype = fivevals[1:4]
if verint>latestVerInt:
latestVerInt = verint
latestVerStr = verstr
latestVerType = vertype
return (latestVerInt, latestVerStr, latestVerType)
################################################################################
def getAllHashes(fnlist):
hashes = []
for fn in fnlist:
out,err = execAndWait('sha256sum %s' % fn)
hashes.append([fn, out.strip().split()[0]])
return hashes
################################################################################
def checkExists(fullPath, onDNE='exit'):
fullPath = os.path.expanduser(fullPath)
if os.path.exists(fullPath):
print('Found file: %s' % fullPath)
else:
print('Path does not exist: %s' % fullPath)
if onDNE=='skip':
return None
elif onDNE=='exit':
exit(1)
return fullPath
def makeOutputDir(dirpath, wipe=True):
if os.path.exists(dirpath) and wipe:
shutil.rmtree(dirpath)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
return dirpath