Skip to content

Commit 155f164

Browse files
Publishing can now talk to server, but server does not like our names.
1 parent 32c3409 commit 155f164

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

fusesoc/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def __init__(self, path=None):
5656
logger.debug("cache_root=" + self.cache_root)
5757
logger.debug("library_root=" + self.library_root)
5858
logger.debug("ssh-trustfile=" + (self.ssh_trustfile or "none"))
59+
logger.debug("publish-uri=" + (self.publish_uri or "none"))
60+
logger.debug("publish-uri-pem=" + (self.publish_uri_pem or "none"))
5961

6062
def _parse_library(self):
6163
# Parse library sections
@@ -199,6 +201,22 @@ def ssh_trustfile(self):
199201
def ssh_trustfile(self, val):
200202
self._set_default_section("ssh-trustfile", val)
201203

204+
@property
205+
def publish_uri(self):
206+
return self._cp.get(Config.default_section, "publish-uri", fallback=None)
207+
208+
@publish_uri.setter
209+
def publish_uri(self, val):
210+
self._set_default_section("publish-uri", val)
211+
212+
@property
213+
def publish_uri_pem(self):
214+
return self._cp.get(Config.default_section, "publish-uri-pem", fallback=None)
215+
216+
@publish_uri_pem.setter
217+
def publish_uri_pem(self, val):
218+
self._set_default_section("publish-uri-pem", val)
219+
202220
@property
203221
def library_root(self):
204222
return self._get_library_root()

fusesoc/main.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# SPDX-License-Identifier: BSD-2-Clause
66

77
import argparse
8+
import json
89
import os
910
import pathlib
1011
import shutil
@@ -301,29 +302,42 @@ def core_sign(fs, args):
301302

302303
def core_publish(fs, args):
303304
core = _get_core(fs, args.core)
304-
logger.info("publish core file: " + core.core_file)
305-
logger.info("to api at: " + args.url)
306-
if args.sigfile:
307-
logger.info("including sigfile: " + args.sigfile)
305+
uri = fs.config.publish_uri
306+
pem = fs.config.publish_uri_pem
307+
sigfile = core.core_file + ".sig"
308+
print("Publish core file: " + core.core_file)
309+
fob_core = open(core.core_file, "rb")
310+
body = {"core_file": fob_core}
311+
fob_sig = None
312+
if os.path.exists(sigfile):
313+
print("and signature file: " + sigfile)
314+
fob_sig = open(sigfile, "rb")
315+
body["signature_file"] = fob_sig
308316
else:
309-
logger.info("no sigfile")
310-
311-
file = open(core.core_file)
312-
cf_data = file.read()
313-
file.close()
314-
body = {"core_file": cf_data}
315-
if args.sigfile:
316-
file = open(args.sigfile)
317-
sf_data = file.read()
318-
file.close()
319-
body["signature_file"] = sf_data
320-
res = requests.post(
321-
args.url + "/api/fusesoc-packages/publish/", json=body, allow_redirects=True
322-
)
323-
logger.info("Got: " + str(res))
317+
print("(without signature file)")
318+
sf_data = None
319+
if pem:
320+
print("with certificate from: " + pem)
321+
print("to api at: " + uri)
322+
if args.yes:
323+
print("without confirmation")
324+
else:
325+
c = input("Confirm by typing 'yes': ")
326+
if c != "yes":
327+
print("Aborted.")
328+
return False
329+
330+
target = uri + "/v1/publish/"
331+
logger.debug("POST to " + target)
332+
res = requests.post(target, files=body, allow_redirects=True, verify=pem)
324333
if not res.ok:
325334
print("Request returned http result", res.status_code, res.reason)
335+
err = json.loads(res.content)
336+
print(str(err))
326337
res.close()
338+
fob_core.close()
339+
if fob_sig:
340+
fob_sig.close()
327341

328342

329343
def gen_clean(fs, args):

0 commit comments

Comments
 (0)