X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=automate.py;fp=automate.py;h=2c67ffe97936aa3d10b1b5fdc6aa2e9f041b64d5;hb=d0652340b89d51c6115edb13d5c7c72b34dea66f;hp=0000000000000000000000000000000000000000;hpb=9a5afb968bf6ee5c9b03470c957b98906d3b78a9;p=monitor.git diff --git a/automate.py b/automate.py new file mode 100644 index 0000000..2c67ffe --- /dev/null +++ b/automate.py @@ -0,0 +1,40 @@ +import csv +from glob import glob +import os +import time + +def time_to_str(t): + return time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(t)) + +def get_filelist_from_dir(dirname): + filelist = glob("%s/*.out" % dirname) + + ret_list = [] + for file in filelist: + ret_list.append(file) + return ret_list + +def get_hostlist_from_dir(dirname): + filelist = glob("%s/*.out" % dirname) + + ret_list = [] + for file in filelist: + ret_list.append([os.path.basename(file)[:-4], '']) + return ret_list + +def csv_to_hash(r): + ret = {} + for line in r: + (k,v) = (line[0], line[1]) + if k not in ret: + ret[k] = v + else: + # multiple values for the same key + if isinstance(ret[k], list): + ret[k].append(v) + else: + ret[k] = [ret[k], v] + return ret + +def getcsv(file): + return csv_to_hash(csv.reader(open(file,'r')))