Skip to content

Commit

Permalink
Merge pull request #60 from wildfoundry/pi-fixes
Browse files Browse the repository at this point in the history
meta fix
  • Loading branch information
willmcgugan authored Mar 4, 2020
2 parents 147e258 + 99f4632 commit ee55b00
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dataplicity/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.4.35"
__version__ = "0.4.38"

if __name__ == "__main__":
# The build script uses this to extract the current version
Expand Down
5 changes: 3 additions & 2 deletions dataplicity/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .disk_tools import disk_usage
from .m2mmanager import M2MManager
from .portforward import PortForwardManager
from .tags import get_tag_list, TagException
from .tags import get_tag_list, TagError
import six

log = logging.getLogger("agent")
Expand Down Expand Up @@ -121,11 +121,12 @@ def tag_poll(self):
"""Gets the tag list for get_tag_list() and sends to the server"""
try:
tag_list = get_tag_list()
except TagException:
except TagError:
return

try:
if tag_list != self._tag_list:
log.debug("new machine tags: %r", tag_list)
with self.remote.batch() as batch:
batch.call_with_id(
"authenticate_result",
Expand Down
2 changes: 2 additions & 0 deletions dataplicity/rpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ def get_machine_revision():
except IOError:
return None
else:
if isinstance(revision_code, bytes):
return revision_code.decode("utf-8")
return revision_code
38 changes: 22 additions & 16 deletions dataplicity/tags.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
from __future__ import unicode_literals

import os
import subprocess
import re
import logging

log = logging.getLogger("agent")


TAG_SCRIPT = "/home/dataplicity/dataplicity_tags"


class TagException(Exception):
class TagError(Exception):
"""Custom exception raised when get_tag_list has an exception"""

pass


def get_tag_list():
"""Run the dataplicity.tags script, get output as a list of tags"""

home_dir = os.environ.get("HOME", "/home/dataplicity/")
tag_executable = os.path.join(home_dir, "dataplicity_tags")

# Early out if the script isn't there.
if not os.path.exists(tag_executable):
log.debug("tag executable %s does not exist", tag_executable)
return []

log.debug("reading tags from %s", tag_executable)
try:
output = subprocess.check_output(TAG_SCRIPT)
except OSError:
output = subprocess.check_output(tag_executable)
except OSError as error:
log.debug("failed to run %s; %s", tag_executable, error)
return []
except Exception as error:
log.error(error)
raise TagException
log.error("error running %s; %s", tag_executable, error)
raise TagError("error running %s" % tag_executable)

str_output = output.decode("utf-8", errors="ignore")

# regex split on comma, spaces, newline and tabs
tag_list = re.split(r"[,\s\n\t]", output)
return [
tag.strip().decode("utf8", errors="ignore")[:25]
for tag in tag_list
if tag != ""
]
tag_list = re.split(r"[,\s\n\t]", str_output)
tags = [tag.strip()[:25] for tag in tag_list if tag]
return tags

0 comments on commit ee55b00

Please sign in to comment.