mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use new fosshub upload API
This commit is contained in:
parent
3fff9ec9cd
commit
826119e797
@ -11,7 +11,7 @@ from subprocess import check_call
|
|||||||
from tempfile import NamedTemporaryFile, mkdtemp, gettempdir
|
from tempfile import NamedTemporaryFile, mkdtemp, gettempdir
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.urllib import urlopen, urlencode
|
from polyglot.urllib import urlopen, Request
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
d = os.path.dirname
|
d = os.path.dirname
|
||||||
@ -157,8 +157,37 @@ def run_remote_upload(args):
|
|||||||
|
|
||||||
|
|
||||||
def upload_to_fosshub():
|
def upload_to_fosshub():
|
||||||
|
# https://devzone.fosshub.com/dashboard/restApi
|
||||||
# fosshub has no API to do partial uploads, so we always upload all files.
|
# fosshub has no API to do partial uploads, so we always upload all files.
|
||||||
|
api_key = get_fosshub_data()
|
||||||
|
|
||||||
|
def request(path, data=None):
|
||||||
|
r = Request('https://api.fosshub.com/rest/' + path.lstrip('/'),
|
||||||
|
headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-auth-key': api_key,
|
||||||
|
'User-Agent': 'calibre'
|
||||||
|
})
|
||||||
|
res = urlopen(r, data=data)
|
||||||
|
ans = json.loads(res.read())
|
||||||
|
if ans.get('error'):
|
||||||
|
raise SystemExit(ans['error'])
|
||||||
|
if res.getcode() != 200:
|
||||||
|
raise SystemExit('Request to {} failed with response code: {}'.format(path, res.getcode()))
|
||||||
|
# from pprint import pprint
|
||||||
|
# pprint(ans)
|
||||||
|
return ans['data'] if 'data' in ans else ans['status']
|
||||||
|
|
||||||
print('Sending upload request to fosshub...')
|
print('Sending upload request to fosshub...')
|
||||||
|
project_id = None
|
||||||
|
|
||||||
|
for project in request('projects'):
|
||||||
|
if project['name'].lower() == 'calibre':
|
||||||
|
project_id = project['id']
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise SystemExit('No calibre project found')
|
||||||
|
|
||||||
files = set(installers())
|
files = set(installers())
|
||||||
entries = []
|
entries = []
|
||||||
for fname in files:
|
for fname in files:
|
||||||
@ -167,33 +196,18 @@ def upload_to_fosshub():
|
|||||||
__version__, os.path.basename(fname)
|
__version__, os.path.basename(fname)
|
||||||
)
|
)
|
||||||
entries.append({
|
entries.append({
|
||||||
'url': url,
|
'fileUrl': url,
|
||||||
'type': desc,
|
'type': desc,
|
||||||
'version': __version__,
|
'version': __version__,
|
||||||
})
|
})
|
||||||
jq = {
|
jq = {
|
||||||
'software': 'Calibre',
|
'version': __version__,
|
||||||
'apiKey': get_fosshub_data(),
|
'files': entries,
|
||||||
'upload': entries,
|
'publish': True,
|
||||||
'delete': [{
|
'isOldRelease': False,
|
||||||
'type': '*',
|
|
||||||
'version': '*',
|
|
||||||
'name': '*'
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
# print(json.dumps(jq, indent=2))
|
# print(json.dumps(jq, indent=2))
|
||||||
rq = urlopen(
|
request('projects/{}/releases/'.format(project_id), data=json.dumps(jq))
|
||||||
'https://www.fosshub.com/JSTools/uploadJson',
|
|
||||||
urlencode({
|
|
||||||
'content': json.dumps(jq)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
resp = rq.read()
|
|
||||||
if rq.getcode() != 200:
|
|
||||||
raise SystemExit(
|
|
||||||
'Failed to upload to fosshub, with HTTP error code: %d and response: %s'
|
|
||||||
% (rq.getcode(), resp)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UploadInstallers(Command): # {{{
|
class UploadInstallers(Command): # {{{
|
||||||
@ -207,7 +221,7 @@ class UploadInstallers(Command): # {{{
|
|||||||
)
|
)
|
||||||
|
|
||||||
def run(self, opts):
|
def run(self, opts):
|
||||||
# return upload_to_fosshub()
|
return upload_to_fosshub()
|
||||||
all_possible = set(installers())
|
all_possible = set(installers())
|
||||||
available = set(glob.glob('dist/*'))
|
available = set(glob.glob('dist/*'))
|
||||||
files = {
|
files = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user