Ejemplo n.º 1
0
    def _execute(self):
        try:
            f_name = "tests/run_%s.py" % self.param('key')
            f = open(f_name, "w")
            data = self.param('text')
            cf = generate_config_file(self.db)
            cf_nums = len(cf.split("\n"))
            f.write(cf)
            f.write(data)
            f.write("\n")
            f.write(generate_report_script())
            f.close()
            res = Popen("/usr/bin/python3 %s" % (f_name), shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT).stdout.read()
            res = str(res, "utf-8")

            tmp = 'File "tests/run_%s.py", line ' % self.param('key')
            try:
                i_s = res.index(tmp) + len(tmp)
                try:
                    i_e = res.index(",", i_s)
                except:
                    i_e = res.index("\n", i_s)
                res_s = res[0:i_s]
                res_e = res[i_e:]
                num = int(res[i_s:i_e]) - cf_nums + 1
                return "".join([res_s, str(num), res_e])
            except:
                pass
            return res
        except Exception as e:
            return "%s" % (e.args,)
def GetMovieDuration(path):
    output = Popen(["ffmpeg", "-i", path], stdout=PIPE, stderr=STDOUT).communicate()[0]
    start = output.index("Duration: ")
    end = output.index(", start: ")
    duration = output[start+len("Duration: "):end]
    hours, mins,secs = duration.split(":")
    totalSecs = float(hours)* 60 * 60 + float(mins) * 60 + float(secs)
    return totalSecs
Ejemplo n.º 3
0
def GetMovieDuration(path):
    output = Popen(["ffmpeg", "-i", path], stdout=PIPE,
                   stderr=STDOUT).communicate()[0]
    start = output.index("Duration: ")
    end = output.index(", start: ")
    duration = output[start + len("Duration: "):end]
    hours, mins, secs = duration.split(":")
    totalSecs = float(hours) * 60 * 60 + float(mins) * 60 + float(secs)
    return totalSecs
Ejemplo n.º 4
0
    def get_cosbench(self):
        """returns the cosbench scores of self.step_count timestep which will
        be used to calculate the reward
        :return: Response Time
        """
        # get latest job_id

        cmd = "pdsh -w cosbench 'cd {}; echo $(ls -dt w*/ | head -1)'".format(
            self.cosbench_log_folder)  # cosbench: w802-workmix2/
        # print (cmd)
        var = Popen(
            cmd, shell=True,
            stdout=PIPE).stdout.read().strip().split()[1]  # w802-workmix2/
        # regular expression can be used
        job_id = var[var.index('w'):var.index('-')]  # w802

        cosbench_url = self.cosbench_url
        url = cosbench_url + job_id

        # get RTs from web UI
        driver = webdriver.PhantomJS(executable_path=self.phantomjs_path)
        driver.get(url)
        html = driver.page_source

        soup = BeautifulSoup(html, 'html.parser')

        tag_list = (soup.find_all('td'))
        numbers = [d.text.encode('utf-8') for d in tag_list]

        # read_response time
        rd_rt = numbers[11].strip().split()[0]  # unit is in ms

        # bandwidth unit is in MB/s
        if numbers[14].strip().split()[1] == 'KB/S':
            rd_bw = (float(numbers[14].strip().split()[0]) / 1000.0)
        else:
            rd_bw = numbers[14].strip().split()[0]

        wr_rt = numbers[19].strip().split()[0]

        if numbers[22].strip().split()[1] == 'KB/S':
            wr_bw = (float(numbers[22].strip().split()[0]) / 1000.0)
        else:
            wr_bw = numbers[22].strip().split()[0]

        cos_data = np.array([rd_rt, rd_bw, wr_rt, wr_bw])
        # print (cos_data)
        TOTAL_RT = sum(
            [float(rd_rt),
             float(rd_bw),
             float(wr_rt),
             float(wr_bw)])
        # print (TOTAL_RT)
        return TOTAL_RT
Ejemplo n.º 5
0
 def cleancss_ver(self):
     if not hasattr(self, '_cleancss_ver'):
         # out = b"MAJOR.MINOR.REVISION" // b"3.4.19" or b"4.0.0"
         out, err = Popen(['cleancss', '--version'],
                          stdout=PIPE).communicate()
         self._cleancss_ver = int(out[:out.index(b'.')])
     return self._cleancss_ver
Ejemplo n.º 6
0
 def cleancss_ver(self):
     if not hasattr(self, '_cleancss_ver'):
         # out = b"MAJOR.MINOR.REVISION" // b"3.4.19" or b"4.0.0"
         out, err = Popen(
             ['cleancss', '--version'], stdout=PIPE).communicate()
         self._cleancss_ver = int(out[:out.index(b'.')])
     return self._cleancss_ver
Ejemplo n.º 7
0
def main():
    first = True
    for dir_ in dirs:
        if first:
            first = False
        else:
            print
            print
        key = os.path.split(dir_)[1]
        print key
        print "=" * len(key)
        print

        pattern = os.path.join(dir_, "*.po")
        keys = ["translated", "fuzzy", "untranslated"]
        ress = []
        for fname in sorted(glob.glob(pattern)):
            locale = os.path.split(fname)[1][:-3]
            log = Popen(["env", "-i", "msgfmt", "-v", fname],
                         stderr=PIPE).stderr.read().split()
            res = [locale, 0, 0, 0]
            for idx, key in enumerate(keys):
                try:
                    if key in log:
                        res[idx+1] = int(log[log.index(key)-1])
                except:
                    pass
            ress.append(res)
        ress.sort(cmp=_cmp)
        print 'locale\t%12s / %12s / %12s' % (keys[0], keys[1], keys[2])
        for x in ress:
            print "%s\t%12i / %12i / %12i" % tuple(x)
Ejemplo n.º 8
0
 def rebase_opt(self):
     """Determine which option name to use."""
     if not hasattr(self, '_rebase_opt'):
         # out = b"MAJOR.MINOR.REVISION" // b"3.4.19" or b"4.0.0"
         out, err = Popen(['cleancss', '--version'],
                          stdout=PIPE).communicate()
         ver = int(out[:out.index(b'.')])
         self._rebase_opt = ['--root', self.root] if ver == 3 else []
     return self._rebase_opt
Ejemplo n.º 9
0
def get_answer(passage, question):

    cq_dict = {"passage": passage, "question": question}

    m = json.dumps(cq_dict)
    m = json.loads(m)

    with open('quest/src/examples.jsonl', 'w') as outfile:
        json.dump(m, outfile)

    a = Popen(
        "python -m allennlp.run predict \quest/src/qna_model.gz \quest/src/examples.jsonl",
        stdout=PIPE,
        shell=True).stdout.read()
    a = a.decode('utf-8')
    print("---------------------------------")
    print(a[a.index('"best_span_str"') + 18:-3])
    print("---------------------------------")
    return a[a.index('"best_span_str"') + 18:-3]
Ejemplo n.º 10
0
def parse_keyid(sig_filename):
    args = ["gpg", "--list-packet", sig_filename]
    out, err = Popen(args, stdout=PIPE, stderr=PIPE).communicate()
    if err.decode('utf-8') != '':
        print(err.decode('utf-8'))
        return None
    out = out.decode('utf-8')
    ai = out.index('keyid') + len('keyid ')
    bi = ai + out[ai:].index('\n')
    return out[ai:bi].strip()
Ejemplo n.º 11
0
def get_cpu_temperature():
    try:
        output, _error = Popen(
            ['vcgencmd', 'measure_temp'], stdout=PIPE).communicate()
        return float(output[output.index('=') + 1:output.rindex("'")])
    except:
        try:
            output, _error = Popen(['sensors'], stdout=PIPE).communicate()
            temp = float(output.split("+")[1].split(" ")[0])
            return temp
        except OSError as e:
            return "0"
def GetMovieFPS(path):
    #mplayer -vo null -nosound 0_0.mpg -ss 00:10:00 -endpos 00:00:01
    output = Popen(["mplayer", "-vo", "null", "-nosound", path, "-endpos", "00:00:01"], stdout=PIPE, stderr=STDOUT).communicate()[0]
    linestart = output.index("VIDEO: ")
    lineend = linestart + output[linestart:].index("\n")
    #print "line start,end:", linestart, lineend
    line = output[linestart:lineend]
    #print "line:", line
    words = line.split()
    #print "words:", words
    fpsIndex = words.index("fps") - 1 
    fps = float(words[fpsIndex])
    return fps
Ejemplo n.º 13
0
def GetMovieFPS(path):
    #mplayer -vo null -nosound 0_0.mpg -ss 00:10:00 -endpos 00:00:01
    output = Popen(
        ["mplayer", "-vo", "null", "-nosound", path, "-endpos", "00:00:01"],
        stdout=PIPE,
        stderr=STDOUT).communicate()[0]
    linestart = output.index("VIDEO: ")
    lineend = linestart + output[linestart:].index("\n")
    #print "line start,end:", linestart, lineend
    line = output[linestart:lineend]
    #print "line:", line
    words = line.split()
    #print "words:", words
    fpsIndex = words.index("fps") - 1
    fps = float(words[fpsIndex])
    return fps
Ejemplo n.º 14
0
 def watson(self):
     res = Popen(["watson", "status"], stdout=PIPE).communicate()[0]
     res = res.decode()
     if not res.startswith("No project started"):
         out = res[0:res.index("(") - 1]
         out = " ".join(out.split()[1:])
         out = out.replace(" started ", ": ")
         out = out.replace(" ago", "")
         out = out.strip()
     else:
         out = "No project"
     res = Popen("watson report --json -d".split(' '),
                 stdout=PIPE).communicate()[0]
     doc = json.loads(res.decode())
     seconds_today = int(doc['time'])
     hours = int(seconds_today / 3600)
     minutes = int((seconds_today % 3600) / 60)
     out += " ({}h{}m)".format(hours, minutes)
     return {
         'full_text': out,
         'cached_until': self.py3.time_in(30),
     }
Ejemplo n.º 15
0
# Build ID
for buildid in BUILDPROP.split('\n'):
    if 'ro.build.display.id' in buildid:
        BUILD_ID = buildid.strip().split('=')[1]
try:
    print(" Build number: " + BUILD_ID)
    REPORT.append(["Build name", BUILD_ID])
except:
    pass

# Wifi
DUMPSYS_W = Popen([ADB, 'shell', SUC, 'dumpsys', 'wifi'],
                  stdout=PIPE,
                  stderr=STDOUT).stdout.read().decode('UTF-8')
try:
    wifi_beg = DUMPSYS_W.index('MAC:') + 5
    wifi_end = DUMPSYS_W[wifi_beg:].index(',')
    if wifi_end == 17:
        WIFI_MAC = DUMPSYS_W[wifi_beg:wifi_beg + wifi_end].lower()
        try:
            print(" Wi-fi MAC: " + WIFI_MAC)
            REPORT.append(["Wifi MAC", WIFI_MAC])
        except:
            pass
except:
    pass

# Time and date
LOCAL_TIME = time.strftime('%Y-%m-%d %H:%M:%S %Z')
try:
    print(" Local time: " + LOCAL_TIME)
Ejemplo n.º 16
0
def get_foreground_app():
    foregroundAppCode = Popen(["lsappinfo", "front"], stdout=PIPE).stdout.read()
    foregroundAppInfo = Popen(["lsappinfo", "info", "-only", "name", foregroundAppCode], stdout=PIPE).stdout.read()
    return foregroundAppInfo[foregroundAppInfo.index('=') + 2:-2]