From: Joseph Coffland Date: Wed, 7 Feb 2018 23:24:17 +0000 (-0800) Subject: Use hostname in config backup filename X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=3d22aea26e143b6787c060326392139208015909;p=bbctrl-firmware Use hostname in config backup filename --- diff --git a/package.json b/package.json index e3b0b81..c7ca019 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bbctrl", - "version": "0.3.3", + "version": "0.3.4", "homepage": "https://github.com/buildbotics/bbctrl-firmware", "license": "GPL 3+", "dependencies": { diff --git a/scripts/sethostname b/scripts/sethostname index 53cdf21..73093b7 100755 --- a/scripts/sethostname +++ b/scripts/sethostname @@ -17,7 +17,7 @@ if [ "$HOSTNAME" =~ ^.*\.local$ ]; then exit 1 fi -if [[ ! "$HOSTNAME" =~ ^[a-zA-Z0-9-]{1,63}$ ]]; then +if [[ ! "$HOSTNAME" =~ ^[a-zA-Z][a-zA-Z0-9-]{0,62}$ ]]; then echo "Invalid hostname '$HOSTNAME'" exit 1 fi diff --git a/src/jade/templates/admin-view.jade b/src/jade/templates/admin-view.jade index 79871cc..2687583 100644 --- a/src/jade/templates/admin-view.jade +++ b/src/jade/templates/admin-view.jade @@ -71,8 +71,8 @@ script#admin-view-template(type="text/x-template") h3(slot="header") Hostname Set div(slot="body") p Hostname was successfuly set to {{hostname}}. - p Rebooting. Please wait... - p Redirecting in {{redirectTimeout}} seconds. + p Rebooting to apply changes. + p Redirecting to new hostname in {{redirectTimeout}} seconds. div(slot="footer") message(:show.sync="passwordSet") diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 58c01e3..5e57a9d 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -8,6 +8,7 @@ import datetime import shutil import tarfile import subprocess +import socket import bbctrl @@ -27,11 +28,7 @@ class RebootHandler(bbctrl.APIHandler): class HostnameHandler(bbctrl.APIHandler): - def get(self): - p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE) - hostname = p.communicate()[0].decode('utf-8').strip() - self.write_json(hostname) - + def get(self): self.write_json(socket.gethostname()) def put(self): if 'hostname' in self.json: @@ -109,7 +106,8 @@ class ConfigLoadHandler(bbctrl.APIHandler): class ConfigDownloadHandler(bbctrl.APIHandler): def set_default_headers(self): - filename = datetime.date.today().strftime('bbctrl-%Y%m%d.json') + fmt = socket.gethostname() + '-%Y%m%d.json' + filename = datetime.date.today().strftime(fmt) self.set_header('Content-Type', 'application/octet-stream') self.set_header('Content-Disposition', 'attachment; filename="%s"' % filename)