Skip to content

Commit

Permalink
Update Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
ucyo committed Dec 21, 2022
1 parent e634db0 commit 7886772
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions annotate.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import sys
import subprocess as sp
import json
from dataclasses import dataclass, field

""" Piped commands not working currently
"""

def main(keyword, hyperfine_json, cmd):
result = execute_cmd(cmd)
print(keyword, hyperfine_json, cmd, result)
@dataclass
class Annotation:
json: str
data: dict = field(init=False)

def __post_init__(self):
with open(self.json, 'r') as f:
self.data = json.load(f)

def execute_cmd(self, key, cmd):
try:
result = sp.check_output(cmd, shell=True).decode('ascii')
except sp.CalledProcessError as err:
print(f"Failed w/ {err}")
raise
else:
tmp = self.data["results"][0]
if hasattr(tmp,"annotations"):
tmp["annotations"][key] = result
else:
tmp["annotations"] = {key:result}
self.data["results"][0] = tmp

def execute_cmd(cmd):
try:
result = sp.check_output(cmd, shell=True)
except sp.CalledProcessError as err:
print(f"Failed w/ {err}")
raise
else:
return result
def export(self):
with open('new_' + self.json, 'w') as f:
json.dump(self.data, f, indent=2)


def main(keyword, hyperfine_json, cmd):
annon = Annotation(hyperfine_json)
annon.execute_cmd(keyword, cmd)
annon.export()

if __name__ == '__main__':
keyword = sys.argv[1]
json = sys.argv[2]
js = sys.argv[2]
command = sys.argv[3:]
main(keyword = keyword, hyperfine_json = json, cmd = command)
main(keyword = keyword, hyperfine_json = js, cmd = command)

0 comments on commit 7886772

Please sign in to comment.