Ejemplo n.º 1
0
 def add_key(self, key):
     if isinstance(key, str):
         if key.startswith('http'):
             res = http.fetch(src=key).do()
             dst = res['dst']
         else:
             dst = key
         with open(dst, 'rb') as fd:
             data = fd.read()
         if key.endswith('.gpg'):
             name = os.path.basename(key)
         else:
             name = self.args['name']
         fname = '/etc/apt/trusted.gpg.d/{0}.gpg'.format(name)
         if GPG_HEADER in data:
             self.sh('gpg --dearmor > {0}'.format(fname),
                     shell=True,
                     stdin=data)
         else:
             with open(fname, 'wb') as fd:
                 fd.write(data)
     elif isinstance(key, tuple):
         keyserver, keyid = key
         self.sh([
             'apt-key', 'adv', '--keyserver', keyserver, '--recv-keys',
             keyid
         ])
Ejemplo n.º 2
0
 def do(self):
     remove = False
     src = self.args['src']
     if src.startswith('http'):
         remove = True
         res = self.check(http.fetch(src=src).do())
         src = res['dst']
     res = self.sh(['tar', '-C', self.args['dst'], '-xzf', src])
     if remove:
         os.unlink(src)
     return res
Ejemplo n.º 3
0
    def do(self):
        dst = self.args['dst']
        pip = os.path.join(dst, 'bin', 'pip')
        binary = os.path.join(dst, 'bin', 'python')
        if not os.path.isfile(binary):
            executable = self.args.get('executable', utils.best_executable())
            if 'python3' in executable:
                # use stdlib venv
                args = [dst]
                self.sh([executable, '-m', 'venv', '--without-pip'] + args)
                self.sh([binary, '-m', 'ensurepip'], check=False)
            else:
                # use virtualenv
                dirname = os.path.dirname(sys.executable)
                venv = os.path.join(dirname, 'virtualenv')
                if not os.path.isfile(venv):
                    venv = 'virtualenv'

                res = self.sh([venv, '-p', executable, dst])

        if not os.path.isfile(binary):
            raise OSError('Not able to create {0}'.format(binary))

        has_pip = False
        if os.path.isfile(pip):
            has_pip = True
        if not has_pip:
            res = self.sh([binary, '-m', 'pip', '--version'], check=False)
            if res['rc'] == 0:
                has_pip = True

        if not has_pip:
            res = self.check(
                http.fetch(src=GET_PIP, dst=os.path.join(dst,
                                                         'get-pip.py')).do())
            res = self.sh([binary, res['dst']])
        else:
            res = dict(rc=0)

        files = self.args.get('files') or []
        if files:
            self.check(super(virtualenv, self).do())
            for f in files:
                if os.path.isfile(pip):
                    cmd = [pip, 'install']
                else:
                    cmd = [binary, '-m', 'pip', 'install']
                if self.args.get('upgrade'):
                    cmd.append('--upgrade')
                cmd.extend(['-r', f['dst']])
                self.sh(cmd)
        res.update(python=binary)
        return res