Skip to content

Instantly share code, notes, and snippets.

@clayrichardson
Created March 22, 2012 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayrichardson/2162249 to your computer and use it in GitHub Desktop.
Save clayrichardson/2162249 to your computer and use it in GitHub Desktop.
rs_tag --list output into json
import sys, subprocess, json, re
import pprint
def get_local_tags():
# rs_tag_list_command = 'rs_tag --list | awk \'{print "\\""$2"\\","}\'' terrible
rs_tag_list_command = 'rs_tag --list | awk \'{print $2}\''
p = subprocess.Popen(rs_tag_list_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, errors = p.communicate()
return output.split()
if __name__ == '__main__':
local_information = get_local_tags()
local_information.pop(0)
labels = []
tags = {}
for tag in local_information:
labels.append(re.split('=', tag))
for label in labels:
tag = re.split('\:', label[0])
tags[tag[0]] = {}
for label in labels:
tag = re.split('\:', label[0])
tags[tag[0]][tag[1]] = label[1]
json_tags = json.dumps(tags)
pprint.pprint(json_tags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment