aboutsummaryrefslogtreecommitdiffhomepage
path: root/devel
diff options
context:
space:
mode:
authorGravatar W. Trevor King <wking@tremily.us>2014-02-10 10:40:25 -0800
committerGravatar David Bremner <david@tethera.net>2014-02-10 21:09:16 -0400
commitb7e6d2cc3034043781db619517891b7c8553f760 (patch)
treef74586c2d797cb359a4fa5531965622102fab71e /devel
parentfd29d3f4fba4c5c88244b13de443c016d23da17b (diff)
nmbug-status: Factor config-loading out into read_config
By isolating this peripheral handling, we make the core logic of nmbug-status easier to read.
Diffstat (limited to 'devel')
-rwxr-xr-xdevel/nmbug/nmbug-status45
1 files changed, 25 insertions, 20 deletions
diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
index a7a391da..6dfbe4d8 100755
--- a/devel/nmbug/nmbug-status
+++ b/devel/nmbug/nmbug-status
@@ -23,6 +23,30 @@ import subprocess
_ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding()
+def read_config(path=None, encoding=None):
+ "Read config from json file"
+ if not encoding:
+ encoding = _ENCODING
+ if path:
+ fp = open(path)
+ else:
+ nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
+
+ # read only the first line from the pipe
+ sha1_bytes = subprocess.Popen(
+ ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
+ stdout=subprocess.PIPE).stdout.readline()
+ sha1 = sha1_bytes.decode(encoding).rstrip()
+
+ fp_byte_stream = subprocess.Popen(
+ ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
+ sha1+':status-config.json'],
+ stdout=subprocess.PIPE).stdout
+ fp = codecs.getreader(encoding=encoding)(stream=fp_byte_stream)
+
+ return json.load(fp)
+
+
# parse command line arguments
parser = argparse.ArgumentParser()
@@ -35,26 +59,7 @@ parser.add_argument('--get-query', help='get query for view')
args = parser.parse_args()
-# read config from json file
-
-if args.config != None:
- fp = open(args.config)
-else:
- nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
-
- # read only the first line from the pipe
- sha1_bytes = subprocess.Popen(
- ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
- stdout=subprocess.PIPE).stdout.readline()
- sha1 = sha1_bytes.decode(_ENCODING).rstrip()
-
- fp_byte_stream = subprocess.Popen(
- ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
- sha1+':status-config.json'],
- stdout=subprocess.PIPE).stdout
- fp = codecs.getreader(encoding=_ENCODING)(stream=fp_byte_stream)
-
-config = json.load(fp)
+config = read_config(path=args.config)
if args.list_views:
for view in config['views']: