Ejemplo n.º 1
0
    def service(self, service: str, data: bytes) -> IO:
        proc = Runner(service)\
            .arg('--stateless-rpc')\
            .arg(self.path)\
            .popen(stdin=PIPE, stdout=PIPE)

        try:
            data, _ = proc.communicate(data)
        finally:
            proc.wait()

        return io.BytesIO(data)
Ejemplo n.º 2
0
 def init(path: str) -> 'Git':
     Runner('git')\
         .arg('init')\
         .arg('--bare')\
         .arg(path)\
         .run(check=True)
     return Git(path)
Ejemplo n.º 3
0
async def ipfsinforefs(qmhash: str, service: Service):
    qmhash = f'Qm{qmhash}'
    path = Path(TEMPDIR.name, qmhash)
    repo = Git(path)

    Runner('ipfs')\
        .arg('get', qmhash)\
        .arg('--output', path)\
        .run(check=True)

    data = repo.inforefs(service.value)
    media = f'application/x-{service.value}-advertisement'
    return StreamingResponse(data, media_type=media)
Ejemplo n.º 4
0
    def inforefs(self, service: str) -> IO:
        result = Runner(service)\
            .arg('--stateless-rpc')\
            .arg('--advertise-refs')\
            .arg(self.path)\
            .run(check=True, capture_output=True)

        # Adapted from:
        #   https://github.com/schacon/grack/blob/master/lib/grack.rb
        data = b'# service=' + service.encode()
        datalen = len(data) + 4
        datalen = b'%04x' % datalen
        data = datalen + data + b'0000' + result.stdout

        return io.BytesIO(data)
Ejemplo n.º 5
0
 def test_init(self):
     """ Adds command to args """
     runner = Runner('ls')
     self.assertListEqual(runner._args, ['ls'])
Ejemplo n.º 6
0
 def test_open(self, Popen):
     """ Opens process """
     Runner('ls').popen(bufsize=0)
     Popen.assert_called_once_with(['ls'], env=None, bufsize=0)
Ejemplo n.º 7
0
 def test_run(self, run):
     """ Runs process """
     Runner('ls').run(check=True)
     run.assert_called_once_with(['ls'], env=None, check=True)
Ejemplo n.º 8
0
 def test_env(self):
     """ Adds kwargs to environment """
     runner = Runner('ls')\
         .env(KEY='key')
     self.assertDictEqual(runner._env, {'KEY': 'key'})
Ejemplo n.º 9
0
 def test_arg(self):
     """ Adds arguments to args list """
     runner = Runner('ls')\
         .arg('-h')\
         .arg('-l')
     self.assertListEqual(runner._args, ['ls', '-h', '-l'])