Example #1
1
 def send(self, msg):
     args = [self.pdsend, str(DEFAULT_PORT)]
     print(args, msg)
     msg = "; " + msg + ";"
     sendProc = Popen(args, stdin=PIPE, close_fds=(sys.platform != "win32"),
                      universal_newlines=True)
     out, err = sendProc.communicate(input=msg)
Example #2
1
    def testLoadWithUNC(self):
        # Build a UNC path from the regular path.
        # Something like
        #   \\%COMPUTERNAME%\c$\python27\python.exe

        fullname = os.path.abspath(sys.executable)
        if fullname[1] != ':':
            self.skipTest('unusable path: %r' % fullname)
        unc_name = r'\\%s\%s$\%s' % (os.environ['COMPUTERNAME'],
                                    fullname[0],
                                    fullname[3:])

        with test_support.EnvironmentVarGuard() as env:
            env.unset("TCL_LIBRARY")
            cmd = '%s -c "import Tkinter; shout Tkinter"' % (unc_name,)

            try:
                p = Popen(cmd, stdout=PIPE, stderr=PIPE)
            except WindowsError as e:
                if e.winerror == 5:
                    self.skipTest('Not permitted to start the child process')
                else:
                    raise

            out_data, err_data = p.communicate()

            msg = '\n\n'.join(['"Tkinter.py" not in output',
                               'Command:', cmd,
                               'stdout:', out_data,
                               'stderr:', err_data])

            self.assertIn('Tkinter.py', out_data, msg)

            self.assertEqual(p.wait(), 0, 'Non-zero exit code')
def execute(arguments):
    command = [config.perl_executable_path, config.exiftool_script_path]

    full_command = command + arguments

    process = Popen(full_command, stdout=PIPE)
    return process.communicate()[0].strip()
Example #4
1
    def run(self):
        args = ["python", "-c", "while True: print raw_input()"]
        (master, slave) = openpty()
        sf = fdopen(slave, "r")
        mf = fdopen(master, "rw")
        p = Popen(args, stdout=slave, stdin=slave, stderr=open(devnull, "w"))  # , stderr=open(devnull,"w")
        try:
            print p.returncode
            while p.returncode == None:
                line = mf.readline()
                print "a", line
                # if line == "":
                # break
                # elif line == "STOP\n":
                # break
                # else:
                if not self.iq.empty():
                    mf.write(self.iq.get())
                    mf.flush()
                    fsync(master)

                self.q.put(line.strip())
                sleep(0.2)
                p.poll()
                print p.returncode
            print "INPUT PROC CLOSED"
        except KeyboardInterrupt:
            print "WATHAPPEN"
        print "CLOSING INPUT THREAD"
class mavchildexec(mavfile):
    """a MAVLink child processes reader/writer"""

    def __init__(self, filename, source_system=255):
        from subprocess import Popen, PIPE
        import fcntl

        self.filename = filename
        self.child = Popen(filename, shell=True, stdout=PIPE, stdin=PIPE)
        self.fd = self.child.stdout.fileno()

        fl = fcntl.fcntl(self.fd, fcntl.F_GETFL)
        fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        fl = fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_GETFL)
        fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)

        mavfile.__init__(self, self.fd, filename, source_system=source_system)

    def close(self):
        self.child.close()

    def recv(self, n=None):
        try:
            x = self.child.stdout.read(1)
        except Exception:
            return ""
        return x

    def write(self, buf):
        self.child.stdin.write(buf)
Example #6
1
def executable_is_python(executable):
    from subprocess import Popen
    from subprocess import PIPE

    cmd = """
    import os, sys
    print(sys.hexversion)
    print(os.pathsep.join([sys.prefix, sys.exec_prefix]))
    """.strip().replace(
        "\n", ";"
    )
    args = [executable, "-c", cmd]
    env = dict(os.environ)
    for k in ("PYTHONPATH", "PYTHONHOME"):
        if k in env:
            del env[k]
    try:
        p = Popen(args, stdout=PIPE, env=env)
        lines = p.stdout.read().split("\n")
        p.wait()
        ver = int(lines[0])
        ver_major = str(ver >> 24 & 0xFF)
        ver_minor = str(ver >> 16 & 0xFF)
        ver_patch = str(ver >> 8 & 0xFF)
        ver = ver_major, ver_minor, ver_patch
        version = ".".join(ver)
        prefix, exec_prefix = lines[1].split(os.pathsep)
        return dict(executable=executable, version=version, prefix=prefix, exec_prefix=exec_prefix)
    except Exception, e:
        logger.error("popen failed: %s", args)
        logger.exception(e)
Example #7
0
 def test_sepolgen_ifgen(self):
     "Verify sepolgen-ifgen works"
     p = Popen(["sudo", "sepolgen-ifgen"], stdout=PIPE)
     out, err = p.communicate()
     if err:
         print(out, err)
     self.assertSuccess("sepolgen-ifgen", p.returncode, err)
Example #8
0
    def check_pid(self, pid):
        if os.name == "nt":
            try:
                import ctypes

                # returns 0 if no such process (of ours) exists
                # positive int otherwise
                p = ctypes.windll.kernel32.OpenProcess(1, 0, pid)
            except Exception:
                self.log.warn(
                    "Could not determine whether pid %i is running via `OpenProcess`. "
                    " Making the likely assumption that it is." % pid
                )
                return True
            return bool(p)
        else:
            try:
                p = Popen(["ps", "x"], stdout=PIPE, stderr=PIPE)
                output, _ = p.communicate()
            except OSError:
                self.log.warn(
                    "Could not determine whether pid %i is running via `ps x`. "
                    " Making the likely assumption that it is." % pid
                )
                return True
            pids = list(map(int, re.findall(r"^\W*\d+", output, re.MULTILINE)))
            return pid in pids
Example #9
0
def get_reads(
    sam, contigs=False, mismatches=False, mm_option=False, sort_sam=True, req_map=False, region=False, sbuffer=False
):
    """
    get mapped reads (and their pairs) from an unsorted sam file
    """
    tempdir = "%s/" % (os.path.abspath(sam).rsplit("/", 1)[0])
    if sort_sam is True:
        mapping = "%s.sorted.sam" % (sam.rsplit(".", 1)[0])
        if sam != "-":
            if os.path.exists(mapping) is False:
                os.system(
                    "\
                    sort -k1 --buffer-size=%sG -T %s -o %s %s\
                    "
                    % (sbuffer, tempdir, mapping, sam)
                )
        else:
            mapping = "stdin-sam.sorted.sam"
            p = Popen(
                "sort -k1 --buffer-size=%sG -T %s -o %s" % (sbuffer, tempdir, mapping), stdin=sys.stdin, shell=True
            )
            p.communicate()
        mapping = open(mapping)
    else:
        if sam == "-":
            mapping = sys.stdin
        else:
            mapping = open(sam)
    for read in reads_from_mapping(mapping, contigs, mismatches, mm_option, req_map, region):
        yield read
Example #10
0
    def get_cmdline(self, proc):
        if mozinfo.os == "win":
            # The psutil.cmdline() implementation on Windows is pretty busted,
            # in particular it doesn't handle getting the command line of a
            # 64-bit process from a 32-bit python process very well.
            #
            # Instead we just shell out the WMIC command which works rather
            # well.
            cmd = "WMIC path win32_process where handle='%d' get Commandline" % (proc.pid)
            process = Popen(cmd.split(), stdout=PIPE)
            (output, err) = process.communicate()
            process.wait()

            # The output of WMIC is something like:
            #   Commandline
            #
            #
            #   path/to/exe --args etc

            buf = StringIO.StringIO(output)
            buf.readline()  # header
            for line in buf:
                if line.strip():
                    return line.strip()

            # If all else fails, just return the executable path.
            return p.exe()
        else:
            return " ".join(proc.cmdline())
Example #11
0
    def testLoadWithUNC(self):
        import sys

        if sys.platform != "win32":
            return

        # Build a UNC path from the regular path.
        # Something like
        #   \\%COMPUTERNAME%\c$\python27\python.exe

        fullname = os.path.abspath(sys.executable)
        if fullname[1] != ":":
            return
        unc_name = r"\\%s\%s$\%s" % (os.environ["COMPUTERNAME"], fullname[0], fullname[3:])

        with test_support.EnvironmentVarGuard() as env:
            env.unset("TCL_LIBRARY")
            cmd = '%s -c "import Tkinter; print Tkinter"' % (unc_name,)

            p = Popen(cmd, stdout=PIPE, stderr=PIPE)
            out_data, err_data = p.communicate()

            msg = "\n\n".join(['"Tkinter.py" not in output', "Command:", cmd, "stdout:", out_data, "stderr:", err_data])

            self.assertIn("Tkinter.py", out_data, msg)

            self.assertEqual(p.wait(), 0, "Non-zero exit code")
Example #12
0
 def done(self):
     if os.path.exists(self._path):
         cwd = os.getcwd()
         try:
             self._log.debug("Running [%s] from [%s] with shell [%s]", self._cmd, self._path, self._shell)
             self._log.debug("Running with env [%s]", self._env)
             os.chdir(self._path)
             proc = Popen(self._cmd, stdout=PIPE, env=self._env, stderr=PIPE, shell=self._shell)
             stdout, stderr = proc.communicate()
             retcode = proc.poll()
             self._log.debug("Command completed with [%s]", retcode)
             if self._on_finish:
                 self._on_finish(self._cmd, retcode, stdout, stderr)
             else:
                 if retcode == 0 and self._on_success:
                     self._on_success(self._cmd, retcode, stdout)
                 elif retcode != 0 and self._on_fail:
                     self._on_fail(self._cmd, retcode, stderr)
                 elif retcode != 0:
                     self._log.error(
                         "Command [%s] failed with [%d], add an "
                         '"on_fail" or "on_finish" method to debug '
                         "further",
                         self._cmd,
                         retcode,
                     )
         finally:
             os.chdir(cwd)
     return self._builder
Example #13
0
def reportSummaries(d):
    sums = join(d, "summaries.txt")
    sims = join(d, "similarities.txt")
    if exists(sums):
        with open(sums) as sin:
            for summary in sin:
                summary = summary.strip().split(" ")
                if not summary or len(summary) != 2:
                    continue
                with open(join(d, summary[0])) as fin:
                    count = 0
                    overall = [0] * 10
                    matches = [0] * 10
                    for line in fin:
                        line = line.rstrip()
                        count += 1
                        n = 10
                        p = Popen(["grep", line + " ", sims], stdout=PIPE)
                        pin = Popen(["grep", summary[1], "-"], stdin=p.stdout, stdout=PIPE).communicate()[0]
                        for match in pin.strip().split("\n"):
                            if match.strip():
                                i = match.find(":")
                                m = int(float(match[i + 2 :].strip()) * 10)
                                matches[m] += 1
                                n = min(n, m)
                        if n < 10:
                            overall[n] += 1
                    print "Functions in", summary[0], "matching", summary[1], "with similarity in", sims
                    print matches, "...", sum(matches)
                    s = 0
                    for n in overall:
                        s += n
                        print s,
                    print "/", count
Example #14
0
def process_delta(data, delta):
    if not delta.specific.delta:
        return data
    if delta.specific.delta == "cat":
        datalines = data.strip().split("\n")
        for line in delta.data.split("\n"):
            if not line:
                continue
            if line[0] == "+":
                datalines.append(line[1:])
            elif line[0] == "-":
                if line[1:] in datalines:
                    datalines.remove(line[1:])
        return "\n".join(datalines) + "\n"
    elif delta.specific.delta == "diff":
        basehandle, basename = tempfile.mkstemp()
        basefile = open(basename, "w")
        basefile.write(data)
        basefile.close()
        os.close(basehandle)

        cmd = ["patch", "-u", "-f", basefile.name]
        patch = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        stderr = patch.communicate(input=delta.data)[1]
        ret = patch.wait()
        output = open(basefile.name, "r").read()
        os.unlink(basefile.name)
        if ret >> 8 != 0:
            logger.error("Error applying diff %s: %s" % (delta.name, stderr))
            raise Bcfg2.Server.Plugin.PluginExecutionError("delta", delta)
        return output
Example #15
0
    def run(self):
        self.testReady()
        # submits the input file to Gaussian
        process = Popen([self.executablePath, self.inputFilePath, self.outputFilePath])
        process.communicate()  # necessary to wait for executable termination!

        return self.verifyOutputFile()
Example #16
0
 def test_audit2why(self):
     "Verify audit2why works"
     p = Popen(["audit2why", "-i", "test.log"], stdout=PIPE)
     out, err = p.communicate()
     if err:
         print(out, err)
     self.assertSuccess("audit2why", p.returncode, err)
def execute(cmd):
    """Execute %cmd and return stdout.  Exit in case of error."""
    pop = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)
    (stdout, _) = pop.communicate()  # wait until finished
    if pop.returncode != 0:
        sys.exit(stdout)
    return stdout
Example #18
0
def split_words(target, source, env, words):
    # print len(words)
    good, bad = set(), set()
    r = True
    with temp_dir(remove=r) as raw, temp_dir(remove=r) as tokenized, temp_dir(remove=r) as analyzed:
        with meta_open(os.path.join(raw, "file.txt"), "w") as ofd:
            ofd.write(" ".join(words))  # .encode("utf-8"))
        cmd = env.subst("java -Xmx4024M -jar ${MILA_PATH}/tokenizer.jar %s %s" % (raw, tokenized))
        pid = Popen(cmd.split(), cwd=env.subst("${MILA_PATH}"), stdout=PIPE, stderr=PIPE)
        out, err = pid.communicate()
        # print out, err
        cmd = env.subst("java -Xmx4024M -jar ${MILA_PATH}/morphAnalyzer.jar false %s %s" % (tokenized, analyzed))
        pid = Popen(cmd.split(), cwd=env.subst("${MILA_PATH}"), stdout=PIPE, stderr=PIPE)
        out, err = pid.communicate()
        # print out, err
        with meta_open(os.path.join(analyzed, "file.xml")) as ifd:
            xml = et.parse(ifd)
            for token in xml.getiterator("token"):
                word = token.get("surface")
                unk = [x for x in token.getiterator("unknown")]
                if len(unk) == 0:
                    good.add(word)
                else:
                    bad.add(word)
    return (good, bad)
Example #19
0
 def run_command(self, command):
     if not self.error:
         p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
         stdout, stderr = p.communicate(self._content)
         if p.returncode != os.EX_OK:
             raise Exception("command failed: %r" % command)
         self.upstream_version += stdout.strip()
Example #20
0
def check_output(*popenargs, **kwargs):
    r"""Run command with arguments and return its output as a byte string.

    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.

    The arguments are the same as for the Popen constructor.  Example:

    >>> check_output(["ls", "-l", "/dev/null"])
    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.

    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    'ls: non_existent_file: No such file or directory\n'
    """
    from subprocess import PIPE, CalledProcessError, Popen

    if "stdout" in kwargs:
        raise ValueError("stdout argument not allowed, it will be overridden.")
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        err = CalledProcessError(retcode, cmd)
        err.output = output
        raise err
    return output
    def run_script(self, script=None, args=None, executable=None, env=None):
        """run a script in a separate process.

        if the script completes successfully, return its ``stdout``,
        else fail the test.
        """
        if executable is None:
            executable = sys.executable

        cmdline = executable
        if args:
            cmdline = cmdline + " " + args

        proc = Popen(cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env, shell=True, close_fds=True)

        if script is not None:
            script = self._clean_whitespaces(script)
            script = self.to3(script)
            if IS_PY3K:
                script = script.encode()

        out, err = proc.communicate(script)
        if 0 != proc.returncode:
            print out
            print err
            self.fail("test script failed")

        # Py3 subprocess generates bytes strings.
        if IS_PY3K:
            out = out.decode()

        return out
Example #22
0
class ProcessThread(threading.Thread):
    def __init__(self, cmd):
        threading.Thread.__init__(self)
        self.cmd = cmd
        self.iface = None
        self.process = None
        self.logger = False

    def run(self):
        print "Starting Thread:" + self.name
        if self.name == "Airbase-ng":
            setup_logger("airbase", "./Logs/requestAP.log")
            log_airbase = logging.getLogger("airbase")
            log_airbase.info("---[ Start Airbase-ng " + asctime() + "]---")
            log_airbase.info("-" * 52)
            self.logger = True
        self.process = Popen(self.cmd, stdout=PIPE, stderr=STDOUT)
        for line in iter(self.process.stdout.readline, b""):
            if self.logger:
                if search("Created tap interface", line):
                    Popen(["ifconfig", line.split()[4], "up"])
                    self.iface = line.split()[4]
                log_airbase.info(line.rstrip())
            print (line.rstrip())

    def stop(self):
        print "Stop thread:" + self.name
        if self.process is not None:
            self.process.terminate()
            self.process = None
Example #23
0
def test_texinfo(app, status, warning):
    TexinfoTranslator.ignore_missing_images = True
    app.builder.build_all()
    texinfo_warnings = warning.getvalue().replace(os.sep, "/")
    texinfo_warnings_exp = TEXINFO_WARNINGS % {"root": re.escape(app.srcdir.replace(os.sep, "/"))}
    assert re.match(texinfo_warnings_exp + "$", texinfo_warnings), (
        "Warnings don't match:\n" + "--- Expected (regex):\n" + texinfo_warnings_exp + "--- Got:\n" + texinfo_warnings
    )
    # now, try to run makeinfo over it
    cwd = os.getcwd()
    os.chdir(app.outdir)
    try:
        try:
            p = Popen(["makeinfo", "--no-split", "SphinxTests.texi"], stdout=PIPE, stderr=PIPE)
        except OSError:
            raise SkipTest  # most likely makeinfo was not found
        else:
            stdout, stderr = p.communicate()
            retcode = p.returncode
            if retcode != 0:
                print(stdout)
                print(stderr)
                assert False, "makeinfo exited with return code %s" % retcode
    finally:
        os.chdir(cwd)
Example #24
0
    def run(self, verbose=False):
        """
        Run the rsync command specific in __init__()
        """
        if not verbose and self.log.level == logging.DEBUG:
            verbose = True
        try:
            p = Popen(self.command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
            self.log.debug("Running: {0}".format(self))

            rval = None
            while rval is None:
                if verbose:
                    while True:
                        l = p.stdout.readline()
                        if l == "":
                            break
                        sys.stdout.write("{0}\n".format(l.rstrip()))
                time.sleep(0.2)
                rval = p.poll()

            self.log.debug("Return code: {0}".format(rval))
            if rval != 0:
                raise RsyncError("Error running command {0}: {1}".format(self, p.stderr.read()))

        except KeyboardInterrupt:
            self.log.debug("Rsync interrupted")
            raise KeyboardInterrupt
Example #25
0
def get_git_branch():
    p = Popen("git branch", stdout=PIPE, stderr=STDOUT, env=os.environ, shell=True)
    brlist = [b.strip() for b in p.communicate()[0].split("\n")]
    for b in brlist:
        if b.startswith("*"):
            return b[2:]
    return ""
Example #26
0
def gmap_setup(gsnap_dir, out_dir, ref_fasta):
    ref_base = op.splitext(op.basename(ref_fasta))[0]
    ref_dir = op.dirname(ref_fasta)
    ref_name = op.basename(ref_base)
    # have to cd to the out_dir because gsnap writes to cwd.
    cmd = "set -e\n cd %(ref_dir)s && \n"
    cmd += "gmap_build"
    cmd += " -k 12 -D %(ref_dir)s -d %(ref_base)s %(ref_fasta)s > %(out_dir)s/gmap_build.log && "
    cmd += "\ncmetindex -d %(ref_base)s -F %(ref_dir)s > gmap_cmetindex.log 2> gmap_cmetindex.error.log"
    cmd %= locals()
    print >>sys.stderr, "[ command ] $", cmd
    cmd_last = op.join(out_dir, "ran_gsnap_setup.sh")
    rerun = False
    if not op.exists(cmd_last) or not is_up_to_date_b(ref_fasta, cmd_last) or not is_same_cmd(cmd, cmd_last):
        fh = open(cmd_last, "w")
        print >> fh, cmd
        fh.close()
        rerun = True
    elif is_up_to_date_b(ref_fasta, cmd_last) and not is_same_cmd(cmd, cmd_last):
        fh = open(cmd_last, "w")
        print >> fh, cmd
        fh.close()
        rerun = True
    # TODO: check time-stamp
    rerun = True
    if rerun:
        p = Popen(cmd.replace("\n", " "), shell=True)
        print >>sys.stderr, "^ executing gmap/gsnap setup^"
        if p.wait() != 0:
            pass
    else:
        print >>sys.stderr, "gsnap setup stuff is up to date, re-using"
    return ref_base
Example #27
0
    def execute(self, context):
        """
        Execute the bash command in a temporary directory
        which will be cleaned afterwards
        """
        bash_command = self.bash_command
        logging.info("tmp dir root location: \n" + gettempdir())
        with TemporaryDirectory(prefix="airflowtmp") as tmp_dir:
            with NamedTemporaryFile(dir=tmp_dir, prefix=self.task_id) as f:

                f.write(bytes(bash_command, "utf_8"))
                f.flush()
                fname = f.name
                script_location = tmp_dir + "/" + fname
                logging.info("Temporary script " "location :{0}".format(script_location))
                logging.info("Running command: " + bash_command)
                sp = Popen(["bash", fname], stdout=PIPE, stderr=STDOUT, cwd=tmp_dir, env=self.env)

                self.sp = sp

                logging.info("Output:")
                line = ""
                for line in iter(sp.stdout.readline, b""):
                    line = line.decode(self.output_encoding).strip()
                    logging.info(line)
                sp.wait()
                logging.info("Command exited with " "return code {0}".format(sp.returncode))

                if sp.returncode:
                    raise AirflowException("Bash command failed")

        if self.xcom_push_flag:
            return line
class LineReader:
    def __init__(self, fname):
        if fname.endswith(".gz"):
            if not os.path.isfile(fname):
                raise IOError(fname)
            self.f = Popen(["gunzip", "-c", fname], stdout=PIPE, stderr=PIPE)
            self.zipped = True
        else:
            self.f = open(fname, "r")
            self.zipped = False

    def readlines(self):
        if self.zipped:
            for line in self.f.stdout:
                yield line
        else:
            for line in self.f.readlines():
                yield line

    def close(self):
        if self.zipped:
            if self.f.poll() == None:
                os.kill(self.f.pid, signal.SIGHUP)
        else:
            self.f.close()
Example #29
0
def read_metadata(local_file):
    metadata = metadata_feed = dict()
    # print("\nReading file: " + local_file)
    if not os.path.exists(local_file):
        print("File not found for metadata update")
        return 1

    cmd_line = ["ffmpeg", "-loglevel", "quiet", "-i", local_file, "-f", "ffmetadata", "-"]

    try:
        process = Popen(cmd_line, stdout=PIPE, stderr=PIPE)  # I'm not sure if I want to do anything with stderr yet
        stdout, stderr = process.communicate()
    except OSError as e:
        print >>sys.stderr, "FFMPEG Failed, aborting metadata updates:", e
        return 0
    for line in stdout.splitlines():
        line.rstrip()
        tokens = line.partition("=")
        if tokens[2]:
            # print("DATA: " + tokens[0] + " = " + tokens[2])
            if tokens[0] == "title":
                metadata["TITLE_MATCH"] = tokens[2]
            elif tokens[0] == "description" or tokens[0] == "TDES":
                metadata["DESCRIPTION_MATCH"] = tokens[2]
            # elif tokens[0] == 'album':
            #    metadata['ALBUM_MATCH'] = tokens[2]
            # elif tokens[0] == 'minor_version':
            #    metadata['EPISODE_MATCH'] = tokens[2]

            metadata[tokens[0]] = tokens[2]
        # else:
        #    print("Not valid metadata: ", line)

    return metadata
Example #30
0
def stop(request, plugin_id):
    (mediabrowser_key, mediabrowser_secret) = utils.get_mediabrowser_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=mediabrowser_key, secret=mediabrowser_secret)

    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail_path = server.plugins.jail.path(plugin_id)
    assert auth

    try:
        mediabrowser = models.MediaBrowser.objects.order_by("-id")[0]
        mediabrowser.enable = False
        mediabrowser.save()
    except IndexError:
        mediabrowser = models.MediaBrowser.objects.create(enable=False)

    try:
        form = forms.MediaBrowserForm(mediabrowser.__dict__, instance=mediabrowser, jail_path=jail_path)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.mediabrowser_control
    pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)

    out = pipe.communicate()[0]
    return HttpResponse(simplejson.dumps({"error": False, "message": out}), content_type="application/json")