示例#1
0
def set_labels(project, change, patchset, labels, message=None):
    home   = ave.config.load_etc()['home']
    config = ave.gerrit.config.load(home)
    host   = config['host']
    port   = config['port']
    user   = config['user']

    if type(project) not in [str, unicode]:
        raise Exception('project must be a string')
    if type(change) not in [str, unicode]:
        raise Exception('change must be a string')
    if type(patchset) not in [str, unicode]:
        raise Exception('patchset must be a string')
    if not labels:
        raise Exception('labels must be specified')
    if not isinstance(labels, dict):
        raise Exception('labels must be a dictionary')
    if message and (type(message) not in [str, unicode]):
        raise Exception('message must be a string')
    if message and (message[0] != message[-1] != '"'):
        raise Exception('message must start and end with a \'"\'')

    cmd = [
        'ssh', '-p', str(port), '-l', user, host, 'gerrit', 'review',
        '--project', project, '%s,%s' % (change, patchset)
    ]

    for label in labels:
        if type(label) not in [str, unicode]:
            raise Exception('label must be a string')
        score = labels[label]
        if not isinstance(score, int):
            raise Exception('score must be an integer')
        cmd.extend(['--label', '%s=%d' % (label, score)])

    if message:
        cmd.extend(['--message', message])

    # make sure ssh finds its configuration files
    os.environ['HOME'] = home
    # make sure ssh always reads its private key from $HOME/.ssh
    if 'SSH_AUTH_SOCK' in os.environ:
        del(os.environ['SSH_AUTH_SOCK'])

    s,o,_ = ave.cmd.run(cmd)
    if s != 0:
        raise RunError(cmd, o, 'Could not perform gerrit review')
示例#2
0
def clone(src, dst, timeout, debug=False, depth=1):
    '''
    Clone a git tree from the source 'src' to the destination 'dst'. The
    source may be a local file system path or any URL accepted by the
    'git clone' command line tool. Raise an exception if the call takes
    longer than 'timeout' seconds.
    '''

    cmd = ['git', 'clone', '--no-checkout', src, dst]
    if isinstance(depth, int) or isinstance(int(depth), int):
        cmd.extend(['--depth', str(depth)])
    (s, o, e) = ave.cmd.run(cmd, timeout=timeout, debug=debug)
    if s != 0:
        error = get_error_str(o)
        raise RunError(
            cmd     = 'ave.git.clone(%s,%s,%s)' % (src, dst, timeout),
            out     = o,
            message = 'failed to clone from %s to %s%s' % (src, dst, error)
        )
示例#3
0
def rev_list(path, limit=0, refspec=None, debug=False):
    '''
    List revisions by SHA1 id's in the git tree found on 'path'. Optionally
    limit the list to 'limit' revisions. Optionally use 'refspec' to set
    the starting point for the listing (defaults to "HEAD").
    '''
    if not refspec:
        refspec = 'HEAD'
    cmd = ['git', '--git-dir=%s/.git'%path, 'rev-list']
    if limit:
        cmd.extend(['--max-count=%d'%limit, refspec])
    else:
        cmd.append('--all')
    (s, o, e) = ave.cmd.run(cmd, debug=debug)
    if s != 0:
        error = get_error_str(o)
        msg   = 'failed to list revisions at %s (%s)%s' % (path,refspec,error)
        raise RunError(
            cmd     = 'ave.git.rev_list(%s,%s,%s)' % (path,limit,refspec),
            out     = o,
            message = msg
        )
    return [line for line in o.splitlines()]
示例#4
0
def get_version(apk_path, aapt_path=None):
    if not aapt_path:
        aapt_path = get_aapt_path()
    cmd = []
    cmd.append(aapt_path)
    cmd.extend(['d', 'badging'])
    cmd.append(apk_path)
    _, package_info, _ = ave.cmd.run(cmd, 1)

    version_line = None
    version_prefix = 'package: name='
    version_field = 'versionCode='
    for line in package_info.splitlines():
        line = line.strip()
        if line.startswith(version_prefix) and version_field in line:
            version_line = line
            break
    if not version_line:
        raise Exception('Can not find versionCode from "%s".' % package_info)
    # version line is something like
    # "package: name='xxx' versionCode='1' versionName='1.1'"
    version_code = line.split('versionCode=', 1)[1].split(' ', 1)[0]
    return int(version_code.strip("'"))
示例#5
0
文件: events.py 项目: yiu31802/ave
    def _begin(self):
        cmd = ['ssh']
        cmd.extend(['-p', str(self.config['port'])])
        cmd.extend(['-l', self.config['user']])
        cmd.append(self.config['host'])
        cmd.extend(['gerrit', 'stream-events'])

        # make sure ssh finds its configuration files
        os.environ['HOME'] = self.home
        # make sure ssh always reads its private key from $HOME/.ssh
        if 'SSH_AUTH_SOCK' in os.environ:
            del (os.environ['SSH_AUTH_SOCK'])

        self.ssh_pid, self.ssh_fd = ave.cmd.run_bg(cmd)
示例#6
0
                remote = urllib2.urlopen(request, timeout=timeout)
            info = remote.info()
            #get download file name
            if info.has_key('Content-Disposition'):
                tmpname = info['Content-Disposition'].partition('filename=')
                filename = tmpname[2][1:-1]
            else:
                filename = os.path.basename(url)

            download_path_name = os.path.join(path, filename)

            cmd = [
                'wget', '-O', download_path_name, '--content-disposition', url
            ]
            if proxy_user:
                cmd.extend(['--proxy-user', proxy_user])
            if proxy_password:
                cmd.extend(['--proxy-password', proxy_password])

            if not output_file:
                ave.cmd.run(cmd, timeout=timeout, output_file=sys.stdout)
            else:
                try:
                    file = open(os.path.join(path, output_file), 'a+')
                    ave.cmd.run(cmd, timeout=timeout, output_file=file)
                except Exception, e:
                    raise e
                finally:
                    file.close()

        except urllib2.URLError, e: