def insert_lpi_if_required(project_name):
    camel_case_project_name = quickly.templatetools.get_camel_case_name(
        project_name)
    existing_base_filename = os.path.join(
        quickly.templatetools.python_name(project_name) + '_lib', "Window.py")
    existing_ui_filename = os.path.join(
        "data", "ui", "%sWindow.ui" % camel_case_project_name)

    if os.path.isfile(existing_base_filename) and os.path.isfile(
            existing_ui_filename):
        tree = etree.parse(existing_ui_filename)
        help_menu = find_about_menu(tree)

        if help_menu:
            existing_base_file = file(existing_base_filename, "r")
            existing_lines = existing_base_file.readlines()
            existing_base_file.close()
            new_lines = detect_or_insert_lpi(existing_lines, project_name,
                                             help_menu)
            if new_lines:
                print _("Adding launchpad integration to existing application")
                new_content = ''.join(new_lines)
                templatetools.set_file_contents(existing_base_filename,
                                                new_content)
            return True
    return False
def update_metadata():
    # See https://wiki.ubuntu.com/PostReleaseApps/Metadata for details

    metadata = []
    project_name = configurationhandler.project_config['project']

    # Grab name and category from desktop file
    with open('%s.desktop.in' % project_name, 'r') as f:
        desktop = f.read()

        match = re.search('\n_?Name=(.*)\n', desktop)
        if match is not None:
            metadata.append('XB-AppName: %s' % match.group(1))

        match = re.search('\nCategories=(.*)\n', desktop)
        if match is not None:
            metadata.append('XB-Category: %s' % match.group(1))

    # Grab distribution for screenshot URLs from debian/changelog
    changelog = subprocess.Popen(['dpkg-parsechangelog'], stdout=subprocess.PIPE).communicate()[0]
    match = re.search('\nDistribution: (.*)\n', changelog)
    if match is not None:
        distribution = match.group(1)
        first_letter = project_name[0]
        urlbase = 'https://software-center.ubuntu.com/screenshots/%s' % first_letter
        metadata.append('XB-Screenshot-Url: %s/%s-%s.png' % (urlbase, project_name, distribution))
        metadata.append('XB-Thumbnail-Url: %s/%s-%s.thumb.png' % (urlbase, project_name, distribution))

    # Now ship the icon as part of the debian packaging
    icon_name = 'data/media/%s.svg' % project_name
    if not os.path.exists(icon_name):
        # Support pre-11.03.1 icon names
        icon_name = 'data/media/logo.svg'
        if not os.path.exists(icon_name):
            icon_name = None
    if icon_name:
        contents = ''
        with open('debian/rules', 'r') as f:
            contents = f.read()
        if contents and re.search('dpkg-distaddfile %s.svg' % project_name, contents) is None:
            contents += """
common-install-indep::
	cp %(icon_name)s ../%(project_name)s.svg
	dpkg-distaddfile %(project_name)s.svg raw-meta-data -""" % {
                'project_name': project_name, 'icon_name': icon_name}
            templatetools.set_file_contents('debian/rules', contents)

            metadata.append('XB-Icon: %s.svg' % project_name)

    # Prepend the start-match line, because update_file_content replaces it
    metadata.insert(0, 'XB-Python-Version: ${python:Versions}')
    templatetools.update_file_content('debian/control',
                                      'XB-Python-Version: ${python:Versions}',
                                      'Depends: ${misc:Depends},',
                                      '\n'.join(metadata) + '\n')
def insert_lpi_if_required(project_name):
    camel_case_project_name = quickly.templatetools.get_camel_case_name(project_name)
    existing_base_filename = os.path.join(quickly.templatetools.python_name(project_name) + '_lib',
                                          "Window.py")
    existing_ui_filename = os.path.join("data", "ui", "%sWindow.ui"%camel_case_project_name)
    
    if os.path.isfile(existing_base_filename) and os.path.isfile(existing_ui_filename):
        tree = etree.parse(existing_ui_filename)
        help_menu = find_about_menu(tree)
        
        if help_menu:
            existing_base_file = file(existing_base_filename, "r")
            existing_lines = existing_base_file.readlines()
            existing_base_file.close()
            new_lines = detect_or_insert_lpi(existing_lines, project_name, help_menu)
            if new_lines:
                print _("Adding launchpad integration to existing application")
                new_content = ''.join(new_lines)
                templatetools.set_file_contents(existing_base_filename, new_content)
            return True
    return False
Example #4
0
def update_file(target_file, substitutions=[], rename = True):

    if not os.path.isfile(target_file):
        return
    target_dir = os.path.dirname(target_file)
    target_basename = os.path.basename(target_file)
    if rename:
        for s in substitutions:
            pattern, sub = s
            target_basename = target_basename.replace(pattern,sub)

    target_file = os.path.join(target_dir, target_basename)

    fin = open(target_file, 'r')
    file_contents = fin.read()
    for s in substitutions:
        pattern, sub = s
        file_contents = file_contents.replace(pattern,sub)

    templatetools.set_file_contents(target_file, file_contents)
    fin.close()
Example #5
0
def update_file(target_file, substitutions=[], rename=True):

    if not os.path.isfile(target_file):
        return
    target_dir = os.path.dirname(target_file)
    target_basename = os.path.basename(target_file)
    if rename:
        for s in substitutions:
            pattern, sub = s
            target_basename = target_basename.replace(pattern, sub)

    target_file = os.path.join(target_dir, target_basename)

    fin = open(target_file, 'r')
    file_contents = fin.read()
    for s in substitutions:
        pattern, sub = s
        file_contents = file_contents.replace(pattern, sub)

    templatetools.set_file_contents(target_file, file_contents)
    fin.close()
Example #6
0
            templatetools.update_file_content("./bin/%s" % project_name,
                    'if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY',
                    "    os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses",
                    content_to_update)
        except templatetools.CantUpdateFile, e:
            print _("WARNING: can't update your project to support /opt. This doesn't matter if you don't plan to submit your project to the application review board. Cause is: %s" % e)

### 11.09 update (but only through 11.10; later versions don't want this change)
if project_version < '11.09' and template_version <= '11.10':
    filename = './%s_lib/Builder.py' % python_name
    try:
        with open(filename) as fileobj:
            contents = fileobj.read()
        contents = contents.replace('from gi.repository import GObject', 'import gobject')
        contents = contents.replace('GObject.', 'gobject.')
        templatetools.set_file_contents(filename, contents)
    except IOError:
        pass

### EPOCH CHANGE
### This is where we upgraded the default projects to GTK3, PyGI, and GSettings.
### Warn the user that this happened and they should upgrade manually to fix.
if project_version and project_version < '11.12' and internal_run:
    print _("""WARNING: Your project is out of date.  Newly created projects use
GTK+ 3, PyGI, and GSettings.  See https://wiki.ubuntu.com/Quickly/GTK3 for
porting information and when you have finished porting your code, run
'quickly upgrade' to get rid of this message.""")
    sys.exit(0)

templatetools.update_version_in_project_file(template_version, 'git-python-gtk')
sys.exit(0)
def update_rules():
    project_name = configurationhandler.project_config["project"]

    install_rules = """
override_dh_install:
	dh_install"""

    opt_root = "/opt/extras.ubuntu.com/" + project_name

    # Move script to bin/ folder.
    # There are some complications here.  As of this writing, current versions
    # of python-mkdebian do not correctly install our executable script in a
    # bin/ subdirectory.  Instead, they either install it in the opt-project
    # root or in the opt-project python library folder (depending on whether
    # the project name is the same as its python name).  So if we find that to
    # be the case, we move the script accordingly.
    bin_path = "%(opt_root)s/bin/%(project_name)s" % {"opt_root": opt_root, "project_name": project_name}
    bad_bin_debpath = "debian/%(project_name)s%(opt_root)s/%(project_name)s" % {
        "opt_root": opt_root,
        "project_name": project_name,
    }
    python_name = templatetools.python_name(project_name)
    if project_name == python_name:
        bad_bin_debpath += "/" + project_name
    install_rules += """
	mkdir -p debian/%(project_name)s%(opt_root)s/bin
	if [ -x %(bad_bin_debpath)s ]; then mv %(bad_bin_debpath)s debian/%(project_name)s%(opt_root)s/bin; fi""" % {
        "project_name": project_name,
        "opt_root": opt_root,
        "bad_bin_debpath": bad_bin_debpath,
    }

    # Move desktop file and update it to point to our /opt locations.
    # The file starts, as expected, under /opt.  But the ARB wants and allows
    # us to install it in /usr, so we do.
    old_desktop_debdir = "debian/%(project_name)s%(opt_root)s/share/applications" % {
        "project_name": project_name,
        "opt_root": opt_root,
    }
    new_desktop_debdir = "debian/%(project_name)s/usr/share/applications" % {"project_name": project_name}
    new_desktop_debpath = new_desktop_debdir + "/extras-" + project_name + ".desktop"
    install_rules += """
	if [ -f %(old_desktop_debdir)s/%(project_name)s.desktop ]; then \\
		mkdir -p %(new_desktop_debdir)s; \\
		mv %(old_desktop_debdir)s/%(project_name)s.desktop %(new_desktop_debpath)s; \\
		rmdir --ignore-fail-on-non-empty %(old_desktop_debdir)s; \\
		sed -i 's|Exec=.*|Exec=%(bin_path)s|' %(new_desktop_debpath)s; \\
		sed -i 's|Icon=/usr/|Icon=%(opt_root)s/|' %(new_desktop_debpath)s; \\
	fi""" % {
        "bin_path": bin_path,
        "old_desktop_debdir": old_desktop_debdir,
        "new_desktop_debdir": new_desktop_debdir,
        "project_name": project_name,
        "opt_root": opt_root,
        "new_desktop_debpath": new_desktop_debpath,
    }

    # Set gettext's bindtextdomain to point to /opt and use the locale
    # module (gettext's C API) instead of the gettext module (gettext's Python
    # API), so that translations are loaded from /opt
    localedir = os.path.join(opt_root, "share/locale")
    install_rules += """
	grep -RlZ 'import gettext' debian/%(project_name)s/* | xargs -0 -r sed -i 's|\(import\) gettext$$|\\1 locale|'
	grep -RlZ 'from gettext import gettext as _' debian/%(project_name)s/* | xargs -0 -r sed -i 's|from gettext \(import gettext as _\)|from locale \\1|'
	grep -RlZ "gettext.textdomain('%(project_name)s')" debian/%(project_name)s/* | xargs -0 -r sed -i "s|gettext\(\.textdomain('%(project_name)s')\)|locale\.bindtextdomain('%(project_name)s', '%(localedir)s')\\nlocale\\1|" """ % {
        "project_name": project_name,
        "localedir": localedir,
    }

    # We install a python_nameconfig.py file that contains a pointer to the
    # data directory.  But that will be determined by setup.py, so it will be
    # wrong (python-mkdebian's --prefix command only affects where it moves
    # files during build, but not what it passes to setup.py)
    config_debpath = "debian/%(project_name)s%(opt_root)s/%(python_name)s*/%(python_name)sconfig.py" % {
        "project_name": project_name,
        "opt_root": opt_root,
        "python_name": python_name,
    }
    install_rules += """
	sed -i "s|__%(python_name)s_data_directory__ =.*|__%(python_name)s_data_directory__ = '%(opt_root)s/share/%(project_name)s/'|" %(config_debpath)s""" % {
        "opt_root": opt_root,
        "project_name": project_name,
        "python_name": python_name,
        "config_debpath": config_debpath,
    }

    # Adjust XDG_DATA_DIRS so we can find schemas and help files
    install_rules += """
	sed -i 's|        sys.path.insert(0, opt_path)|\\0\\n    os.putenv("XDG_DATA_DIRS", "%%s:%%s" %% ("%(opt_root)s/share/", os.getenv("XDG_DATA_DIRS", "")))|' debian/%(project_name)s%(bin_path)s""" % {
        "opt_root": opt_root,
        "project_name": project_name,
        "bin_path": bin_path,
    }

    # Compile the glib schema, since it is in a weird place that normal glib
    # triggers won't catch during package install.
    schema_debdir = "debian/%(project_name)s%(opt_root)s/share/glib-2.0/schemas" % {
        "opt_root": opt_root,
        "project_name": project_name,
    }
    install_rules += """
	if [ -d %(schema_debdir)s ]; then glib-compile-schemas %(schema_debdir)s; fi""" % {
        "schema_debdir": schema_debdir
    }

    # Set rules back to include our changes
    rules = ""
    with open("debian/rules", "r") as f:
        rules = f.read()
    rules += install_rules
    templatetools.set_file_contents("debian/rules", rules)
def update_rules():
    project_name = configurationhandler.project_config['project']

    install_rules = """
override_dh_install:
	dh_install"""

    opt_root = "/opt/extras.ubuntu.com/" + project_name

    # Move script to bin/ folder.
    # There are some complications here.  As of this writing, current versions
    # of python-mkdebian do not correctly install our executable script in a
    # bin/ subdirectory.  Instead, they either install it in the opt-project
    # root or in the opt-project python library folder (depending on whether
    # the project name is the same as its python name).  So if we find that to
    # be the case, we move the script accordingly.
    bin_path = "%(opt_root)s/bin/%(project_name)s" % {
        'opt_root': opt_root, 'project_name': project_name}
    bad_bin_debpath = "debian/%(project_name)s%(opt_root)s/%(project_name)s" % {
        'opt_root': opt_root, 'project_name': project_name}
    python_name = templatetools.python_name(project_name)
    if project_name == python_name:
        bad_bin_debpath += "/" + project_name
    install_rules += """
	mkdir -p debian/%(project_name)s%(opt_root)s/bin
	if [ -x %(bad_bin_debpath)s ]; then mv %(bad_bin_debpath)s debian/%(project_name)s%(opt_root)s/bin; fi""" % {
        'project_name': project_name, 'opt_root': opt_root, 'bad_bin_debpath': bad_bin_debpath}

    # Move desktop file and update it to point to our /opt locations.
    # The file starts, as expected, under /opt.  But the ARB wants and allows
    # us to install it in /usr, so we do.
    old_desktop_debdir = "debian/%(project_name)s%(opt_root)s/share/applications" % {
        'project_name': project_name, 'opt_root': opt_root}
    new_desktop_debdir = "debian/%(project_name)s/usr/share/applications" % {'project_name': project_name}
    new_desktop_debpath = new_desktop_debdir + "/extras-" + project_name + ".desktop"
    install_rules += """
	if [ -f %(old_desktop_debdir)s/%(project_name)s.desktop ]; then \\
		mkdir -p %(new_desktop_debdir)s; \\
		mv %(old_desktop_debdir)s/%(project_name)s.desktop %(new_desktop_debpath)s; \\
		rmdir --ignore-fail-on-non-empty %(old_desktop_debdir)s; \\
		sed -i 's|Exec=.*|Exec=%(bin_path)s|' %(new_desktop_debpath)s; \\
		sed -i 's|Icon=/usr/|Icon=%(opt_root)s/|' %(new_desktop_debpath)s; \\
	fi""" % {
        'bin_path': bin_path, 'old_desktop_debdir': old_desktop_debdir,
        'new_desktop_debdir': new_desktop_debdir, 'project_name': project_name,
        'opt_root': opt_root, 'new_desktop_debpath': new_desktop_debpath}

    # Set gettext's bindtextdomain to point to /opt and use the locale
    # module (gettext's C API) instead of the gettext module (gettext's Python
    # API), so that translations are loaded from /opt
    localedir = os.path.join(opt_root, 'share/locale') 
    install_rules += """
	grep -RlZ 'import gettext' debian/%(project_name)s/* | xargs -0 -r sed -i 's|\(import\) gettext$$|\\1 locale|'
	grep -RlZ 'from gettext import gettext as _' debian/%(project_name)s/* | xargs -0 -r sed -i 's|from gettext \(import gettext as _\)|from locale \\1|'
	grep -RlZ "gettext.textdomain('%(project_name)s')" debian/%(project_name)s/* | xargs -0 -r sed -i "s|gettext\(\.textdomain('%(project_name)s')\)|locale\.bindtextdomain('%(project_name)s', '%(localedir)s')\\nlocale\\1|" """ % {
        'project_name': project_name, 'localedir': localedir}

    # We install a python_nameconfig.py file that contains a pointer to the
    # data directory.  But that will be determined by setup.py, so it will be
    # wrong (python-mkdebian's --prefix command only affects where it moves
    # files during build, but not what it passes to setup.py)
    config_debpath = "debian/%(project_name)s%(opt_root)s/%(python_name)s*/%(python_name)sconfig.py" % {
        'project_name': project_name, 'opt_root': opt_root, 'python_name': python_name}
    install_rules += """
	sed -i "s|__%(python_name)s_data_directory__ =.*|__%(python_name)s_data_directory__ = '%(opt_root)s/share/%(project_name)s/'|" %(config_debpath)s""" % {
        'opt_root': opt_root, 'project_name': project_name,
        'python_name': python_name, 'config_debpath': config_debpath}

    # Adjust XDG_DATA_DIRS so we can find schemas and help files
    install_rules += """
	sed -i 's|        sys.path.insert(0, opt_path)|\\0\\n    os.putenv("XDG_DATA_DIRS", "%%s:%%s" %% ("%(opt_root)s/share/", os.getenv("XDG_DATA_DIRS", "")))|' debian/%(project_name)s%(bin_path)s""" % {
        'opt_root': opt_root, 'project_name': project_name, 'bin_path': bin_path}

    # Compile the glib schema, since it is in a weird place that normal glib
    # triggers won't catch during package install.
    schema_debdir = "debian/%(project_name)s%(opt_root)s/share/glib-2.0/schemas" % {
        'opt_root': opt_root, 'project_name': project_name}
    install_rules += """
	if [ -d %(schema_debdir)s ]; then glib-compile-schemas %(schema_debdir)s; fi""" % {
        'schema_debdir': schema_debdir}

    # Set rules back to include our changes
    rules = ''
    with open('debian/rules', 'r') as f:
        rules = f.read()
    rules += install_rules
    templatetools.set_file_contents('debian/rules', rules)