def output_format_template_context(self, app: BaseConfig): """ Additional template context required by the output format. :param app: The config object for the app """ # WiX requires a 3-element, integer-only version number. If a version # triple isn't explicitly provided, generate one by stripping any # non-numeric portions from the version number. # If there are less than 3 numeric parts, 0s will be appended. try: version_triple = app.version_triple except AttributeError: parsed = parsed_version(app.version) version_triple = '.'.join( ([str(v) for v in parsed.release] + ['0', '0'])[:3]) # The application needs a unique GUID. # This is used to track the application, even if the application # name changes. We can generate a default GUID using the bundle # and the formal name; but you'll need to manually set this value # if you ever change those two keys. try: guid = app.guid except AttributeError: # Create a DNS domain by reversing the bundle identifier domain = '.'.join([app.app_name] + app.bundle.split('.')[::-1]) guid = uuid.uuid5(uuid.NAMESPACE_DNS, domain) print("Assigning {app.app_name} an application GUID of {guid}". format( app=app, guid=guid, )) try: if app.system_installer: install_scope = "perMachine" else: install_scope = "perUser" except AttributeError: # system_installer not defined in config; default to perUser install. install_scope = "perUser" return { 'version_triple': version_triple, 'guid': str(guid), 'install_scope': install_scope }
def output_format_template_context(self, app: BaseConfig): """ Additional template context required by the output format. :param app: The config object for the app """ # Android requires an integer "version code". If a version code # isn't explicitly provided, generate one from the version number. # The build number will also be appended, if provided. try: version_code = app.version_code except AttributeError: parsed = parsed_version(app.version) version_triple = (list(parsed.release) + [0, 0])[:3] version_code = '{v[0]:d}{v[1]:02d}{v[2]:02d}{build:02d}'.format( v=version_triple, build=int(getattr(app, 'build', '0'))).lstrip('0') return { 'version_code': version_code, }
def output_format_template_context(self, app: BaseConfig): """Additional template context required by the output format. :param app: The config object for the app """ # Android requires an integer "version code". If a version code # isn't explicitly provided, generate one from the version number. # The build number will also be appended, if provided. try: version_code = app.version_code except AttributeError: parsed = parsed_version(app.version) v = (list(parsed.release) + [0, 0])[:3] # version triple build = int(getattr(app, "build", "0")) version_code = f"{v[0]:d}{v[1]:02d}{v[2]:02d}{build:02d}".lstrip( "0") return { "version_code": version_code, "safe_formal_name": safe_formal_name(app.formal_name), }
def test_valid_app_version(version, parsed): assert is_pep440_canonical_version(version) assert parsed == parsed_version(version).__dict__