Created
March 22, 2012 19:23
-
-
Save clayrichardson/2162249 to your computer and use it in GitHub Desktop.
rs_tag --list output into json
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
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