Ejemplo n.º 1
0
 def __init__(self, event_loop, origin, cmd):
     self.process = subprocess.Popen(cmd, bufsize = 0, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
     self.event_loop = event_loop
     self.origin = origin
     self.stdin = FileDispatcherWithSend(self.process.stdin)
     self.stdout = asyncore.file_dispatcher(self.process.stdout)
     self.stdout.handle_read = self.handle_read_stdout
     self.stdout.writable = lambda: False
     self.stderr = asyncore.file_dispatcher(self.process.stderr)
     self.stderr.handle_read = self.handle_read_stderr
     self.stderr.writable = lambda: False
     self.stdout_buffer = bytes()
     self.stderr_buffer = bytes()
     self.connected = True
Ejemplo n.º 2
0
 def __init__(self, event_loop, origin, cmd):
     self.process = subprocess.Popen(cmd,
                                     bufsize=0,
                                     stdin=subprocess.PIPE,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
     self.event_loop = event_loop
     self.origin = origin
     self.stdin = FileDispatcherWithSend(self.process.stdin)
     self.stdout = asyncore.file_dispatcher(self.process.stdout)
     self.stdout.handle_read = self.handle_read_stdout
     self.stdout.writable = lambda: False
     self.stderr = asyncore.file_dispatcher(self.process.stderr)
     self.stderr.handle_read = self.handle_read_stderr
     self.stderr.writable = lambda: False
     self.stdout_buffer = bytes()
     self.stderr_buffer = bytes()
     self.connected = True
Ejemplo n.º 3
0
def main():
    if not os.access(BIN, os.X_OK):
        sys.exit('aria2c not found_repo')
    try:
        uri, outfile = sys.argv[1:]
    except ValueError:
        sys.exit('incorrect number of arguments')

    outdir = os.path.dirname(outfile)
    outfile = os.path.basename(outfile)
    tempfile = outfile + '.airpac'
    infile, num = gen_input_file(uri)

    args = [
        BIN, '--conf-path=' + CONF, '--remote-time=true', '--continue',
        '--allow-overwrite=true', '--summary-interval=0', '--split=' + num,
        '--server-stat-if=' + STATS, '--server-stat-of=' + STATS,
        '--dir=' + outdir, '--out=' + tempfile, '--input-file=' + infile
    ]

    if uri.endswith('.db.tar.gz'):
        db_cache(tempfile)

    aria2c = Popen(args, stdout=PIPE)

    def terminate(signum=None, frame=None, failed=False):
        asyncore.socket_map.clear()
        aria2c.wait()
        os.unlink(infile)
        if signum is not None:
            print '\n'
            sys.stdout.flush()
        if signum is not None or failed:
            sys.exit(1)

    signal.signal(signal.SIGINT, terminate)
    signal.signal(signal.SIGTERM, terminate)

    # An easy way of getting the terminal width
    width = int(
        Popen(['stty', 'size'], stdout=PIPE).communicate()[0].split()[1])
    name = os.path.basename(uri).rsplit('.', 3)[0]

    def handle_read():
        data = aria2c.stdout.readline().strip()
        if data.startswith('[#1'):
            log(width, name, data.strip('[#1 ]'))
        elif data.startswith('(OK):'):
            log(width, name, 'DONE', cr=False)
            terminate()
        elif data.startswith('(ERR):'):
            log(width, name, 'FAIL', cr=False)
            terminate(failed=True)

    asyncore.file_dispatcher(aria2c.stdout).handle_read = handle_read
    asyncore.loop()

    if aria2c.returncode == 0:
        if uri.endswith('.db.tar.gz'):
            db_cache(tempfile, store=True)
        os.rename(tempfile, outfile)
Ejemplo n.º 4
0
Archivo: airpac.py Proyecto: kidaa/aur
def main():
    if not os.access(BIN, os.X_OK):
        sys.exit("aria2c not found_repo")
    try:
        uri, outfile = sys.argv[1:]
    except ValueError:
        sys.exit("incorrect number of arguments")

    outdir = os.path.dirname(outfile)
    outfile = os.path.basename(outfile)
    tempfile = outfile + ".airpac"
    infile, num = gen_input_file(uri)

    args = [
        BIN,
        "--conf-path=" + CONF,
        "--remote-time=true",
        "--continue",
        "--allow-overwrite=true",
        "--summary-interval=0",
        "--split=" + num,
        "--server-stat-if=" + STATS,
        "--server-stat-of=" + STATS,
        "--dir=" + outdir,
        "--out=" + tempfile,
        "--input-file=" + infile,
    ]

    if uri.endswith(".db.tar.gz"):
        db_cache(tempfile)

    aria2c = Popen(args, stdout=PIPE)

    def terminate(signum=None, frame=None, failed=False):
        asyncore.socket_map.clear()
        aria2c.wait()
        os.unlink(infile)
        if signum is not None:
            print "\n"
            sys.stdout.flush()
        if signum is not None or failed:
            sys.exit(1)

    signal.signal(signal.SIGINT, terminate)
    signal.signal(signal.SIGTERM, terminate)

    # An easy way of getting the terminal width
    width = int(Popen(["stty", "size"], stdout=PIPE).communicate()[0].split()[1])
    name = os.path.basename(uri).rsplit(".", 3)[0]

    def handle_read():
        data = aria2c.stdout.readline().strip()
        if data.startswith("[#1"):
            log(width, name, data.strip("[#1 ]"))
        elif data.startswith("(OK):"):
            log(width, name, "DONE", cr=False)
            terminate()
        elif data.startswith("(ERR):"):
            log(width, name, "FAIL", cr=False)
            terminate(failed=True)

    asyncore.file_dispatcher(aria2c.stdout).handle_read = handle_read
    asyncore.loop()

    if aria2c.returncode == 0:
        if uri.endswith(".db.tar.gz"):
            db_cache(tempfile, store=True)
        os.rename(tempfile, outfile)