-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from wildfoundry/pi-fixes
meta fix
- Loading branch information
Showing
4 changed files
with
28 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |