Пример #1
0
def _exec_and_log_errors(command, ask_on_warn_or_error=False):
    """exec the giving command and hide output if not in verbose mode"""

    if templatetools.in_verbose_mode():
        return subprocess.call(command)
    else:
        proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout_domain = DomainLevel.NONE
        stderr_domain = DomainLevel.NONE
        err_output = []
        warn_output = []
        while True:
            line_stdout = proc.stdout.readline().rstrip()
            line_stderr = proc.stderr.readline().rstrip()
            # filter stderr
            if line_stderr:
                (stderr_domain, err_output, warn_output) = _filter_out(
                    line_stderr, stderr_domain, err_output, warn_output
                )

            if not line_stdout:
                # don't replace by if proc.poll() as the output can be empty
                if proc.poll() != None:
                    break
            # filter stdout
            else:
                (stdout_domain, err_output, warn_output) = _filter_out(
                    line_stdout, stdout_domain, err_output, warn_output
                )

        return _continue_if_errors(err_output, warn_output, proc.returncode, ask_on_warn_or_error)
Пример #2
0
def _exec_and_log_errors(command, ask_on_warn_or_error=False):
    '''exec the giving command and hide output if not in verbose mode'''

    if templatetools.in_verbose_mode():
        return(subprocess.call(command))
    else:
        proc = subprocess.Popen(command, stdout=subprocess.PIPE,
                                         stderr=subprocess.PIPE)
        stdout_domain = DomainLevel.NONE
        stderr_domain = DomainLevel.NONE
        err_output = []
        warn_output = []
        while True:
            line_stdout = proc.stdout.readline().rstrip()
            line_stderr = proc.stderr.readline().rstrip()
            # filter stderr
            if line_stderr:
                (stderr_domain, err_output, warn_output) = _filter_out(line_stderr, stderr_domain, err_output, warn_output)

            if not line_stdout:
                # don't replace by if proc.poll() as the output can be empty
                if proc.poll() != None:
                    break
            # filter stdout
            else:
                (stdout_domain, err_output, warn_output) = _filter_out(line_stdout, stdout_domain, err_output, warn_output)

        return(_continue_if_errors(err_output, warn_output, proc.returncode,
                                     ask_on_warn_or_error))
Пример #3
0
def get_right_gpg_key_id(launchpad):
    '''Try to fech (and explain how to upload) right GPG key'''

    verbose = templatetools.in_verbose_mode()
    prefered_emails = get_all_emails()
    if not prefered_emails:
        raise gpg_error(_("Can't sign the package as no adress email found. " \
                          "Fulfill the AUTHORS file with name <emailadress> " \
                          "or export DEBEMAIL/EMAIL."))
    if verbose:
        print prefered_emails

    gpg_instance = subprocess.Popen(['gpg', '--list-secret-keys', '--with-colon'], stdout=subprocess.PIPE)
    result, err = gpg_instance.communicate()    
    if gpg_instance.returncode != 0:
        raise gpg_error(err)
    candidate_key_ids = {}
    for line in result.splitlines():
        if 'sec' in line:
            secret_key_id = line.split(':')[4][-8:]
            if verbose:
                print "found secret gpg key. id: %s" % secret_key_id
        candidate_email = take_email_from_string(line.split(':')[9])
        if verbose:
            print "candidate email: %s" % candidate_email
        if candidate_email and candidate_email in prefered_emails:
            # create candidate_key_ids[candidate_email] if needed
            try:
                candidate_key_ids[candidate_email]
            except KeyError:
                candidate_key_ids[candidate_email] = []
            candidate_key_ids[candidate_email].append(secret_key_id)
    if not candidate_key_ids:
        candidate_key_ids[prefered_emails[0]] = [create_gpg_key(
                                 launchpad.me.display_name, prefered_emails[0])]

    if verbose:
        print "candidate_key_ids: %s" % candidate_key_ids

    # reorder key_id by email adress
    prefered_key_ids = []
    for email in prefered_emails:
        try:
            prefered_key_ids.append((candidate_key_ids[email], email))
        except KeyError:
            pass
    if not prefered_key_ids:
        raise gpg_error(_("GPG keys found matching no prefered email. You " \
                          "can export DEBEMAIL or put it in AUTHORS file " \
                          "one matching your local gpg key."))
    if verbose:
        print "prefered_key_ids: %s" % prefered_key_ids

    # get from launchpad the gpg key
    launchpad_key_ids = []
    for key in launchpad.me.gpg_keys:
        launchpad_key_ids.append(key.keyid)

    if not launchpad_key_ids:
        upload_gpg_key_to_launchpad(prefered_key_ids[0])
        launchpad_key_ids = [prefered_key_ids[0]]

    if verbose:
        print "launchpad_key_ids: %s" % launchpad_key_ids

    # take first match:
    for key_ids, email in prefered_key_ids:
        for key_id in key_ids:
            if key_id in launchpad_key_ids:
                # export env variable for changelog and signing
                author_name = launchpad.me.display_name.encode('UTF-8')
                if not os.getenv('DEBFULLNAME'):
                    os.putenv('DEBFULLNAME', author_name)
                if not os.getenv('DEBEMAIL'):
                    os.putenv('DEBEMAIL', email)
                if verbose:
                    print "Selected key_id: %s, author: %s, email: %s" % (key_id, author_name, email)
                # set upstream author and email
                try:
                    get_setup_value('author')
                except cant_deal_with_setup_value:
                    set_setup_value('author', author_name)
                try:
                     get_setup_value('author_email')
                except cant_deal_with_setup_value:
                    set_setup_value('author_email', email)
                return key_id

    # shouldn't happen as other errors are caught
    raise gpg_error(_("No gpg key set matching launchpad one found.'"))
Пример #4
0
filelist = []
for root, dirs, files in os.walk('./'):
    for name in files:
        hide_path = root.endswith('_lib')
        py = name.endswith('.py')
        if py and not hide_path and name not in ('setup.py'):
            filelist.append(os.path.join(root, name))

# if config not already loaded
if not configurationhandler.project_config:
    configurationhandler.loadConfig()

# add launcher which does not end with .py for older projects (pre-lib split)
project_name = configurationhandler.project_config['project']
libdir = os.path.join(templatetools.python_name(project_name) + '_lib')
if not os.path.exists(libdir):
    filelist.append('bin/' + configurationhandler.project_config['project'])

# add helpfile sources
filelist.extend(glob.glob('help/C/*.page'))

editor = quicklyutils.get_quickly_editors()
if templatetools.in_verbose_mode():
    instance = subprocess.Popen([editor] + filelist)
else:
    nullfile = file("/dev/null")
    instance = subprocess.Popen([editor] + filelist, stderr=nullfile)
if editor != 'gedit':
    instance.wait()
Пример #5
0
and windows in your project. Note that you *must* open Glade
in this manner for quickly to work. If you try to open Glade
directly, and the open the UI files, Glade will throw errors
and won't open the files.""")
templatetools.handle_additional_parameters(sys.argv, help, usage=usage)

if not configurationhandler.project_config:
    configurationhandler.loadConfig()
mainfile = "data/ui/" + templatetools.get_camel_case_name(configurationhandler.project_config['project']).lower() + "window.ui"
files = []
for ui_file in glob.glob("data/ui/*.ui"):
    if ui_file.lower() != mainfile:
        files.insert(0, ui_file)
    else:
        files.append(ui_file)

(project_version, template_version) = templatetools.get_project_and_template_versions("git-python-gtk")
if project_version < '11.12': # GTK+ 3 changeover
    glade_cmd = 'GLADE_CATALOG_PATH=./data/ui glade-gtk2'
else:
    glade_cmd = 'GLADE_CATALOG_SEARCH_PATH=./data/ui glade'

cmd = glade_cmd + " " + " ".join(files)

#run glade with env variables pointing to catalogue xml files
if templatetools.in_verbose_mode():
    subprocess.Popen(cmd, shell=True)
else:
    nullfile=file("/dev/null") 
    subprocess.Popen(cmd, shell=True, stderr=nullfile)
Пример #6
0
def get_right_gpg_key_id(launchpad):
    '''Try to fech (and explain how to upload) right GPG key'''

    verbose = templatetools.in_verbose_mode()
    prefered_emails = get_all_emails()
    if not prefered_emails:
        raise gpg_error(_("Can't sign the package as no adress email found. " \
                          "Fulfill the AUTHORS file with name <emailadress> " \
                          "or export DEBEMAIL/EMAIL."))
    if verbose:
        print prefered_emails

    gpg_instance = subprocess.Popen(
        ['gpg', '--list-secret-keys', '--with-colon'], stdout=subprocess.PIPE)
    result, err = gpg_instance.communicate()
    if gpg_instance.returncode != 0:
        raise gpg_error(err)
    candidate_key_ids = {}
    for line in result.splitlines():  # pylint: disable=E1103
        if 'sec' in line:
            secret_key_id = line.split(':')[4][-8:]
            if verbose:
                print "found secret gpg key. id: %s" % secret_key_id
        candidate_email = take_email_from_string(line.split(':')[9])
        if verbose:
            print "candidate email: %s" % candidate_email
        if candidate_email and candidate_email in prefered_emails:
            # create candidate_key_ids[candidate_email] if needed
            try:
                candidate_key_ids[candidate_email]
            except KeyError:
                candidate_key_ids[candidate_email] = []
            candidate_key_ids[candidate_email].append(secret_key_id)
    if not candidate_key_ids:
        candidate_key_ids[prefered_emails[0]] = [
            create_gpg_key(launchpad.me.display_name, prefered_emails[0])
        ]

    if verbose:
        print "candidate_key_ids: %s" % candidate_key_ids

    # reorder key_id by email adress
    prefered_key_ids = []
    for email in prefered_emails:
        try:
            prefered_key_ids.append((candidate_key_ids[email], email))
        except KeyError:
            pass
    if not prefered_key_ids:
        raise gpg_error(_("GPG keys found matching no prefered email. You " \
                          "can export DEBEMAIL or put it in AUTHORS file " \
                          "one matching your local gpg key."))
    if verbose:
        print "prefered_key_ids: %s" % prefered_key_ids

    # get from launchpad the gpg key
    launchpad_key_ids = []
    for key in launchpad.me.gpg_keys:
        launchpad_key_ids.append(key.keyid)

    if not launchpad_key_ids:
        upload_gpg_key_to_launchpad(prefered_key_ids[0])
        launchpad_key_ids = [prefered_key_ids[0]]

    if verbose:
        print "launchpad_key_ids: %s" % launchpad_key_ids

    # take first match:
    for key_ids, email in prefered_key_ids:
        for key_id in key_ids:
            if key_id in launchpad_key_ids:
                # export env variable for changelog and signing
                author_name = launchpad.me.display_name.encode('UTF-8')
                if not os.getenv('DEBFULLNAME'):
                    os.putenv('DEBFULLNAME', author_name)
                if not os.getenv('DEBEMAIL'):
                    os.putenv('DEBEMAIL', email)
                if verbose:
                    print "Selected key_id: %s, author: %s, email: %s" % (
                        key_id, author_name, email)
                # set upstream author and email
                try:
                    get_setup_value('author')
                except cant_deal_with_setup_value:
                    set_setup_value('author', author_name)
                try:
                    get_setup_value('author_email')
                except cant_deal_with_setup_value:
                    set_setup_value('author_email', email)
                return key_id

    # shouldn't happen as other errors are caught
    raise gpg_error(_("No gpg key set matching launchpad one found."))