Ejemplo n.º 1
0
def openssh_import(sshtype, ssh_key):
	(fd, fname) = tempfile.mkstemp(text=True)
	os.close(fd)
	file(fname, 'w').write(ssh_key)
	try:
		openssh_format = check_output(['ssh-keygen', '-i', '-m', sshtype, '-f', fname])
	except subprocess.CalledProcessError as e:
		raise
	finally:
		os.unlink(fname)

	return openssh_format.strip()
Ejemplo n.º 2
0
def admin_command(trac_dir, args):
	"""trac_dir is the trac env dir, args is a list of arguments to trac-admin"""
	cmd = ['trac-admin', trac_dir]
	cmd.extend(args)
	path = options.value('env_path', "/bin:/usr/bin:/usr/local/bin:/opt/local/bin")
	env_copy = os.environ.copy()
	env_copy['PATH'] = path

	try:
		return check_output(cmd, stderr=subprocess.STDOUT, env=env_copy)
	except subprocess.CalledProcessError as e:
		raise TracAdminError(' '.join(cmd), e.returncode, e.output)
Ejemplo n.º 3
0
def openssh_import(sshtype, ssh_key):
    (fd, fname) = tempfile.mkstemp(text=True)
    os.close(fd)
    open(fname, 'w').write(ssh_key)
    try:
        openssh_format = check_output(
            ['ssh-keygen', '-i', '-m', sshtype, '-f', fname])
    except subprocess.CalledProcessError as e:
        raise
    finally:
        os.unlink(fname)

    return openssh_format.strip()
Ejemplo n.º 4
0
def admin_command(trac_dir, args):
    """trac_dir is the trac env dir, args is a list of arguments to trac-admin"""
    cmd = ['trac-admin', trac_dir]
    cmd.extend(args)
    path = options.value('env_path',
                         "/bin:/usr/bin:/usr/local/bin:/opt/local/bin")
    env_copy = os.environ.copy()
    env_copy['PATH'] = path

    try:
        return check_output(cmd, stderr=subprocess.STDOUT, env=env_copy)
    except subprocess.CalledProcessError as e:
        raise TracAdminError(' '.join(cmd), e.returncode, e.output)
Ejemplo n.º 5
0
    def job_sync(self, jobid, lines):
        for line in lines.strip().split('\n'):
            try:
                oldrev, newrev, refname = line.split()
            except ValueError as e:
                return 'trac-sync/%s/%s/%s: %s' % (self.vcs_type, self.repo,
                                                   jobid, str(e))

            cmd = ['git', 'rev-list', '--reverse', newrev, '^' + oldrev]
            if oldrev == '0' * 40:
                cmd.pop()

            try:
                revs = check_output(cmd, stderr=STDOUT, env=self.env_copy)
            except CalledProcessError as e:
                return 'cmd [%s] failed: %s', (cmd, e.output)

            for rev in revs.strip().split('\n'):
                args = ['changeset', 'added', '(default)', rev]
                output = trac.admin_command(self.trac_env, args)
                if output:
                    return 'trac-admin %s: %s' % (' '.join(args), output)

        return []
Ejemplo n.º 6
0
	def job_sync(self, jobid, lines):
		for line in lines.strip().split('\n'):
			try:
				oldrev, newrev, refname = line.split()
			except ValueError as e:
				return 'trac-sync/%s/%s/%s: %s' % (
					self.vcs_type, self.repo, jobid, str(e))

			cmd = ['git', 'rev-list', '--reverse', newrev, '^' + oldrev]
			if oldrev == '0' * 40:
				cmd.pop()

			try:
				revs = check_output(cmd, stderr=STDOUT, env=self.env_copy)
			except CalledProcessError as e:
				return 'cmd [%s] failed: %s', (cmd, e.output)

			for rev in revs.strip().split('\n'):
				args = ['changeset', 'added', '(default)', rev]
				output = trac.admin_command(self.trac_env, args)
				if output:
					return 'trac-admin %s: %s' % (' '.join(args), output)

		return []
Ejemplo n.º 7
0
def apache_modules():
    path = options.value('env_path',
                         '/bin:/usr/bin:/usr/local/bin:/opt/local/bin')
    paths = path.split(':')
    paths.extend(['/sbin', '/usr/sbin'])
    path = ':'.join(paths)
    env_copy = os.environ.copy()
    env_copy['PATH'] = path
    modules = []
    cmds = [
        ['apachectl', '-t', '-D', 'DUMP_MODULES'],
        ['apache2ctl', '-t', '-D', 'DUMP_MODULES'],
        # Gentoo specific workaround (see #326)
        ['apache2ctl', 'modules'],
    ]
    errormsgs = []
    server_info_url = options.value('apache_server_info_url',
                                    'http://localhost/server-info?list')

    for cmd in cmds:
        try:
            output = check_output(cmd, stderr=STDOUT, env=env_copy)
        except OSError as e:
            errormsgs.append(str(e))
            continue  # try the next command, if any
        except CalledProcessError as e:
            errormsgs.append(e.output)
            continue  # try the next command, if any
        else:
            errormsgs.append('')

            for line in output.decode('utf-8').split('\n'):
                if line.endswith('(shared)') or line.endswith('(static)'):
                    module = line.strip().split(' ')[0]
                    modules.append(module.replace('_module', ''))

        if len(modules) > 0:
            return modules  # return if any command doing the work

    # Above commands didn't work, maybe because we do not have permission to
    # view SSL certificate. This lets apache fail to verify and thus fail
    # to dump the list of modules (see #330).  Final try, direct via URL...
    cmds.append(['[internal URL get]', server_info_url])
    try:
        response = urllib2.urlopen(server_info_url)
    except urllib2.HTTPError as e:
        errormsgs.append('HTTP error %u' % (e.code, ))
    except urllib2.URLError as e:
        errormsgs.append('URL error %u: %s' % (e.reason[0], e.reason[1]))
    else:
        html = response.read()
        modules = re.findall('<dd>mod_([^<]+)\.c</dd>', html)
        if len(modules) > 0:
            return modules
        errormsgs.append('Could not find list of modules at URL %s' %
                         (server_info_url, ))

    # That failed too, give up and show our attempts
    errormsg = 'executable apachectl not found, tried:\n'
    for cmd, msg in zip(cmds, errormsgs):
        errormsg += " * command: '%s', errormsg:\n\n%s\n\n" % \
          (' '.join(cmd), msg)

    errormsg = errormsg.replace('<', '&lt;').replace('>', '&gt;')
    raise ApacheCtlError(errormsg)
Ejemplo n.º 8
0
def apache_modules():
	path = options.value('env_path',
			'/bin:/usr/bin:/usr/local/bin:/opt/local/bin')
	paths = path.split(':')
	paths.extend(['/sbin', '/usr/sbin'])
	path = ':'.join(paths)
	env_copy = os.environ.copy()
	env_copy['PATH'] = path
	modules = []
	cmds = [
		['apachectl', '-t', '-D', 'DUMP_MODULES'],
		['apache2ctl', '-t', '-D', 'DUMP_MODULES'],
		# Gentoo specific workaround (see #326)
		['apache2ctl', 'modules'],
	]
	errormsgs = []
	server_info_url = options.value('apache_server_info_url',
		'http://localhost/server-info?list')

	for cmd in cmds:
		try:
			output = check_output(cmd, stderr=STDOUT, env=env_copy)
		except OSError as e:
			errormsgs.append(str(e))
			continue # try the next command, if any
		except CalledProcessError as e:
			errormsgs.append(e.output)
			continue # try the next command, if any
		else:
			errormsgs.append('')

			for line in output.split('\n'):
				if line.endswith('(shared)') or line.endswith('(static)'):
					module = line.strip().split(' ')[0]
					modules.append(module.replace('_module', ''))

		if len(modules) > 0:
			return modules # return if any command doing the work

	# Above commands didn't work, maybe because we do not have permission to
	# view SSL certificate. This lets apache fail to verify and thus fail
	# to dump the list of modules (see #330).  Final try, direct via URL...
	cmds.append(['[internal URL get]', server_info_url])
	try:
		response = urllib2.urlopen(server_info_url)
	except urllib2.HTTPError as e:
		errormsgs.append('HTTP error %u' % (e.code, ))
	except urllib2.URLError as e:
		errormsgs.append('URL error %u: %s' % (e.reason[0], e.reason[1]))
	else:
		html = response.read()
		modules = re.findall('<dd>mod_([^<]+)\.c</dd>', html)
		if len(modules) > 0:
			return modules
		errormsgs.append('Could not find list of modules at URL %s' %
				(server_info_url, ))

	# That failed too, give up and show our attempts
	errormsg = 'executable apachectl not found, tried:\n'
	for cmd, msg in zip(cmds, errormsgs):
		errormsg += " * command: '%s', errormsg:\n\n%s\n\n" % \
				(' '.join(cmd), msg)

	errormsg = errormsg.replace('<', '&lt;').replace('>', '&gt;')
	raise ApacheCtlError(errormsg)