Ejemplo n.º 1
0
def copy_license_to_files(license_content):
    """Copy license header to every .py files"""

    # get the project name
    if not configurationhandler.project_config:
        configurationhandler.loadConfig()
    project_name = configurationhandler.project_config['project']

    # open each python file and main bin file
    for root, dirs, files in os.walk('./'):
        for name in files:
            if name.endswith('.py') or os.path.join(
                    root, name) == "./bin/" + project_name:
                target_file_name = os.path.join(root, name)
                try:
                    templatetools.update_file_content(
                        target_file_name, BEGIN_LICENCE_TAG, END_LICENCE_TAG,
                        '%s\n%s' % (BEGIN_LICENCE_TAG, license_content))
                except templatetools.CantUpdateFile, e:
                    print _(
                        "WARNING: %s was not found in the file %s. No licence replacement"
                    ) % (END_LICENCE_TAG, target_file_name)
                except (OSError, IOError), e:
                    msg = _("%s file was not found") % target_file_name
                    raise LicenceError(msg)
Ejemplo n.º 2
0
def copy_license_to_files(license_content):
    """Copy license header to every .py files"""

    # get the project name
    if not configurationhandler.project_config:
        configurationhandler.loadConfig()
    project_name = configurationhandler.project_config['project']

    # open each python file and main bin file
    for root, dirs, files in os.walk('./'):
        for name in files:
            if name.endswith('.py') or os.path.join(root, name) == "./bin/" + project_name:
                target_file_name = os.path.join(root, name)
                try:
                    templatetools.update_file_content(
                        target_file_name,
                        BEGIN_LICENCE_TAG,
                        END_LICENCE_TAG,
                        '%s\n%s' % (BEGIN_LICENCE_TAG, license_content)
                        )
                except templatetools.CantUpdateFile, e:
                    print _("WARNING: %s was not found in the file %s. No licence replacement") % (END_LICENCE_TAG, target_file_name)
                except (OSError, IOError), e:
                    msg = _("%s file was not found") % target_file_name
                    raise LicenceError(msg)
Ejemplo n.º 3
0
def update_rules():
    # Also update debian/control to add a new Build-Depends needed for
    # glib-compile-schemas
    templatetools.update_file_content(
        'debian/control',
        "Build-Depends: debhelper (>= 8),",
        " python (>= 2.6.6-3~),",
        "Build-Depends: debhelper (>= 8), libglib2.0-bin,")
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
0
        sys.path.insert(0, opt_path)
if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, '%(python_name)s'))
    and PROJECT_ROOT_DIRECTORY not in sys.path):
    python_path.insert(0, PROJECT_ROOT_DIRECTORY)
    sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
if python_path:
    os.putenv('PYTHONPATH', "%%s:%%s" %% (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses''' % {'python_name' : python_name, 'project_name' : project_name}

    # projects based on ~/quickly-projects/template-name have no project_version
    # so only upgrade if really necessary     
    with open("./bin/%s" % project_name) as project_bin:
        contents =  project_bin.read()
    if not content_to_update in contents:
        try:
            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