Skip to content

Commit dac7b8f

Browse files
author
Terrence Meiczinger
committed
merge
2 parents f7afc1e + 1107cf6 commit dac7b8f

File tree

2 files changed

+85
-31
lines changed

2 files changed

+85
-31
lines changed

packages/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ IF(RPM)
102102
SET(CPACK_RPM_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
103103
SET(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
104104
SET(DOCUMENTATION_PATH share/doc/${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
105+
SET(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
106+
/usr
107+
/usr/bin
108+
/usr/share
109+
/usr/share/man
110+
)
105111
ENDIF()
106112
#-----------------------------------------------------------------------------
107113

scripts/publish.py

+79-31
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@
33
import requests
44
from BeautifulSoup import BeautifulStoneSoup as Soup
55
import urllib
6-
import hashlib
6+
import hashlib
77
import os
88
import re
99
import sys
1010

1111

1212
class BinTray(object):
13+
1314
def __init__(self):
1415
self.base_url = 'https://api.bintray.com/{section}/tmeiczin/opendcp/opendcp/{command}/'
1516
self.auth = None
1617

1718
def version_exists(self):
1819
url = self.base_url.format(section='packages', command='versions')
1920
url += self.version
20-
21+
2122
r = requests.get(url, auth=self.auth)
22-
23+
2324
if r.ok:
2425
print 'version found'
2526
return True
2627

2728
def publish(self, version):
2829
url = self.base_url.format(section='content', command=version)
2930
url += '/publish'
30-
31+
3132
r = requests.post(url, auth=self.auth)
3233

3334
if r.ok:
@@ -38,9 +39,9 @@ def publish(self, version):
3839
def do_upload(self, filename, version):
3940
url = self.base_url.format(section='content', command=version)
4041
url += os.path.basename(filename)
41-
files = {'file': open(filename, 'rb')}
42-
43-
r = requests.put(url, files=files, auth=self.auth)
42+
43+
with open(filename, 'rb') as f:
44+
r = requests.put(url, data=f, auth=self.auth)
4445

4546
if r.ok:
4647
return True
@@ -50,7 +51,9 @@ def do_upload(self, filename, version):
5051
def upload(self, files):
5152
for filename in files:
5253
basename = os.path.basename(filename)
53-
version = re.search('opendcp(?:-|_)(\d+.\d+.\d+)', basename).group(1)
54+
version = re.search(
55+
'opendcp(?:-|_)(\d+.\d+.\d+)',
56+
basename).group(1)
5457

5558
if self.do_upload(filename, version):
5659
print 'uploading %s... ok' % (filename)
@@ -60,34 +63,34 @@ def upload(self, files):
6063

6164

6265
class OpenBuild(object):
66+
6367
def __init__(self):
6468
self.base_url = 'https://api.opensuse.org/build/home:tmeiczin:opendcp'
6569
self.auth = None
6670

6771
def _get_repositories(self):
6872
url = 'https://api.opensuse.org/build/home:tmeiczin:opendcp'
69-
73+
7074
r = requests.get(url, auth=self.auth)
71-
print r.text
72-
75+
7376
if not r.ok:
7477
return []
75-
78+
7679
soup = Soup(r.text)
7780
entries = soup.findAll('entry')
7881
return [x['name'] for x in entries]
7982

8083
def _get_arch(self, repo):
8184
url = 'https://api.opensuse.org/build/home:tmeiczin:opendcp/' + repo
82-
85+
8386
r = requests.get(url, auth=self.auth)
84-
87+
8588
if not r.ok:
8689
return []
8790

8891
soup = Soup(r.text)
8992
entries = soup.findAll('entry')
90-
93+
9194
return [x['name'] for x in entries]
9295

9396
def _get_paths(self):
@@ -102,11 +105,12 @@ def _get_paths(self):
102105
return data
103106

104107
def _arch(self, arch, binary):
105-
deb = {'i586': 'i386', 'x86_64': 'amd64'}
108+
deb = {'i586': 'i386', 'x86_64': 'amd64'}
109+
rpm = {'i586': 'i686', 'x86_64': 'x86_64'}
106110
if 'deb' in binary:
107111
return deb[arch]
108112
else:
109-
return arch
113+
return rpm[arch]
110114

111115
def _get_md5(self, link):
112116
md5_url = '%s.md5' % (link)
@@ -125,7 +129,7 @@ def links(self):
125129
base = 'https://api.opensuse.org/build/home:tmeiczin:opendcp/'
126130

127131
paths = self._get_paths()
128-
132+
129133
for path in paths:
130134
for repo, v in path.items():
131135
for arch in v:
@@ -134,51 +138,89 @@ def links(self):
134138
soup = Soup(r.text)
135139
binaries = [x['filename'] for x in soup.findAll('binary')]
136140
for binary in binaries:
137-
if any(ext in binary for ext in ['i386.deb', 'amd64.deb', 'i586.rpm', 'i686.rpm', 'x86_64.rpm']):
141+
if any(
142+
ext in binary for ext in [
143+
'i386.deb',
144+
'amd64.deb',
145+
'i586.rpm',
146+
'i686.rpm',
147+
'x86_64.rpm']):
138148
link = 'http://download.opensuse.org/repositories/home:/tmeiczin:/opendcp'
139-
link = '%s/%s/%s/%s' % (link, repo, self._arch(arch, binary), binary)
149+
link = '%s/%s/%s/%s' % (link,
150+
repo,
151+
self._arch(
152+
arch,
153+
binary),
154+
binary)
140155
md5 = self._get_md5(link)
141-
links.append({'name': repo, 'url':link, 'md5':md5})
156+
links.append(
157+
{'name': repo, 'url': link, 'md5': md5})
142158

143159
return links
144160

145161

146162
class Publish(object):
163+
147164
def __init__(self):
148165
self.tmp_path = '/tmp'
149166
self.downloaded_files = []
150-
167+
151168
def md5_checksum(self, filename, md5):
152169
if not md5:
170+
print 'No MD5 found, skipping'
153171
return True
154172

155-
with open(filename, 'rb') as fh:
173+
with open(filename, 'rb') as f:
156174
m = hashlib.md5()
157175
while True:
158-
data = fh.read(8192)
176+
data = f.read(8192)
159177
if not data:
160178
break
161179
m.update(data)
180+
f.close()
162181

163-
if md5 == m.hexdigest():
164-
return True
182+
if md5 != m.hexdigest():
183+
print 'MD5 mismatch %s (%s -> %s)' % (filename, md5, m.hexdigest())
184+
return False
165185

166-
return False
186+
return True
167187

168188
def replace_os(self, filename):
169189
filename = filename.replace('centos_centos-6', 'centos_6')
170190
filename = filename.replace('redhat_rhel-6', 'rhel_6')
171191
if 'opensuse' in filename:
172-
filename = re.sub(r'(opendcp-\d+.\d+.\d+-\w+_\d+.\d+)(-\d+.\d+)', r'\1', filename)
192+
filename = re.sub(
193+
r'(opendcp-\d+.\d+.\d+-\w+_\d+.\d+)(-\d+.\d+)',
194+
r'\1',
195+
filename)
173196
else:
174-
filename = re.sub(r'(opendcp-\d+.\d+.\d+-\w+_\d+)(-\d+.\d+)', r'\1', filename)
197+
filename = re.sub(
198+
r'(opendcp-\d+.\d+.\d+-\w+_\d+)(-\d+.\d+)',
199+
r'\1',
200+
filename)
175201

176202
return filename
177203

178204
def get_links(self):
179205
print 'Getting OpenDCP URLs'
180206
self.ob_files = OpenBuild().links()
181207

208+
def download_file(self, url, filename):
209+
with open(filename, 'wb') as f:
210+
r = requests.get(url, stream=True)
211+
212+
if not r.ok:
213+
print 'bad http request %s %s (%s)' % (url, filename, r.status_code)
214+
return False
215+
216+
for block in r.iter_content(1024):
217+
if not block:
218+
break
219+
f.write(block)
220+
f.close()
221+
222+
return True
223+
182224
def download(self):
183225
self.downloaded_files = []
184226
self.get_links()
@@ -196,16 +238,22 @@ def download(self):
196238
replacement = '%s_%s' % (version, l['name'])
197239
else:
198240
replacement = '%s-%s' % (version, l['name'])
199-
filename = '%s/%s' % (self.tmp_path, re.sub(search, replacement, basename).lower())
241+
filename = '%s/%s' % (self.tmp_path,
242+
re.sub(
243+
search,
244+
replacement,
245+
basename).lower())
200246
filename = self.replace_os(filename)
201247

202-
urllib.urlretrieve (l['url'], filename)
248+
if not self.download_file(l['url'], filename):
249+
continue
203250

204251
if self.md5_checksum(filename, l['md5']):
205252
print 'downloading %s... ok' % (filename)
206253
self.downloaded_files.append(filename)
207254
else:
208255
print 'downloading %s... not ok' % (filename)
256+
self.downloaded_files.append(filename)
209257

210258
def upload(self):
211259
bintray = BinTray()

0 commit comments

Comments
 (0)