def changelog(dpath, ctx, env): change = ctx.get('message', 'Autogenerated by py2dsp v{}'.format(VERSION)) version = ctx['debian_version'] distribution = ctx.get('distribution', 'UNRELEASED') fpath = join(dpath, 'debian', 'changelog') if exists(fpath): with open(fpath, encoding='utf-8') as fp: line = fp.readline() if ctx['version'] in line or 'UNRELEASED' in line: log.debug('changelog doesn\'t need an update') return else: yield from execute([ 'dch', '--force-distribution', '--distribution', distribution, '--newversion', version, '-m', change ], cwd=dpath) return now = datetime.utcnow() changelog = Changelog() changelog.new_block(package=ctx['src_name'], version=Version(version), distributions=distribution, urgency='low', author=ctx['creator'], date=now.strftime('%a, %d %b %Y %H:%M:%S +0000')) changelog.add_change('') changelog.add_change(' * {}'.format(change)) changelog.add_change('') with open(fpath, 'w', encoding='utf-8') as fp: changelog.write_to_open_file(fp) return True
def changelog(dpath, ctx, env): change = ctx.get('message', 'Autogenerated by py2dsp v{}'.format(VERSION)) version = "{}-{}".format(ctx['version'], ctx['debian_revision']) distribution = ctx.get('distribution', 'UNRELEASED') fpath = join(dpath, 'debian', 'changelog') if exists(fpath): with open(fpath, encoding='utf-8') as fp: line = fp.readline() if ctx['version'] in line or 'UNRELEASED' in line: log.debug('changelog doesn\'t need an update') return else: yield from execute(['dch', '--force-distribution', '--distribution', distribution, '--newversion', version, '-m', change], cwd=dpath) return now = datetime.utcnow() changelog = Changelog() changelog.new_block(package=ctx['src_name'], version=Version(version), distributions=distribution, urgency='low', author=ctx['creator'], date=now.strftime('%a, %d %b %Y %H:%M:%S +0000')) changelog.add_change('') changelog.add_change(' * {}'.format(change)) changelog.add_change('') with open(fpath, 'w', encoding='utf-8') as fp: changelog.write_to_open_file(fp) return True
def download(name, version=None, destdir='.'): details = yield from get_pypi_info(name, version) if not details: raise Exception('cannot get PyPI project details for {}'.format(name)) if not version: version = details['info']['version'] release = details['releases'].get(version, {}) if not release: log.debug('missing release of %s %s on PyPI', name, version) raise Exception('missing release') try: release = next((i for i in release if i['python_version'] == 'source')) except StopIteration: release = None if not release: raise Exception('source package not available on PyPI') orig_ext = ext = release['filename'].replace( '{}-{}.'.format(name, version), '') if ext not in {'tar.gz', 'tar.bz2', 'tar.xz'}: ext = 'tar.xz' fname = '{}_{}.orig.{}'.format(pkg_name(name), version, ext) fpath = join(destdir, fname) if exists(fpath): return fname session = None try: session = aiohttp.ClientSession() response = yield from session.get(release['url']) with open( fpath if ext == orig_ext else join( destdir, release['filename']), 'wb') as fp: data = yield from response.read() fp.write(data) finally: if session is not None: yield from session.close() if orig_ext != ext: cmd = [ 'mk-origtargz', '--rename', '--compression', 'xz', '--package', pkg_name(details['info']['name']), '--version', version, '--directory', destdir, '--repack', join(destdir, release['filename']) ] # TODO: add --copyright-file if overriden copyright file is available yield from execute(cmd) return fname
def download(name, version=None, destdir='.'): details = yield from get_pypi_info(name, version) if not details: raise Exception('cannot get PyPI project details for {}'.format(name)) if not version: version = details['info']['version'] release = details['releases'].get(version, {}) if not release: log.debug('missing release of %s %s on PyPI', name, version) raise Exception('missing release') try: release = next((i for i in release if i['python_version'] == 'source')) except StopIteration: release = None if not release: raise Exception('source package not available on PyPI') orig_ext = ext = release['filename'].replace('{}-{}.'.format(name, version), '') if ext not in {'tar.gz', 'tar.bz2', 'tar.xz'}: ext = 'tar.xz' fname = '{}_{}.orig.{}'.format(pkg_name(name), version, ext) fpath = join(destdir, fname) if exists(fpath): return fname response = yield from aiohttp.get(release['url'], connector=conn) with open(fpath if ext == orig_ext else join(destdir, release['filename']), 'wb') as fp: data = yield from response.read() fp.write(data) if orig_ext != ext: cmd = ['mk-origtargz', '--rename', '--compression', 'xz', '--package', pkg_name(details['info']['name']), '--version', version, '--directory', destdir, '--repack', join(destdir, release['filename'])] # TODO: add --copyright-file if overriden copyright file is available yield from execute(cmd) return fname
def debianize(dpath, ctx, profile=None): update_ctx(dpath, ctx) setupcfg_fpath = join(dpath, 'setup.cfg') if exists(setupcfg_fpath): upstream_cfg = ConfigParser() upstream_cfg.read(setupcfg_fpath) if 'py2dsp' in upstream_cfg: ctx.update(upstream_cfg['py2dsp'].items()) override_paths = [TEMPLATES_PATH] # profile overrides if profile: if isdir(profile): # --profile a_dir override_paths.append(profile) elif exists(profile): # --profile a_file with open(profile) as fp: ctx.update(load(fp)) else: # --profile name profile_dpath = join(PROFILES_PATH, profile) if isdir(profile_dpath): override_paths.append(profile_dpath) # package specific overrides... in global overrides dir o_dpath = join(OVERRIDES_PATH, ctx['name'].lower()) isdir(o_dpath) and override_paths.append(o_dpath) # ... in local ./overrides o_dpath = join('overrides', ctx['name'].lower()) isdir(o_dpath) and override_paths.append(o_dpath) # handle overrides debian_dir = join(dpath, 'debian') for o_dpath in override_paths: fpath = join(o_dpath, 'ctx.json') if exists(fpath): with open(fpath) as fp: ctx.update(load(fp)) # invoke pre hooks fpath = abspath(join(o_dpath, 'hooks', 'pre')) if exists(fpath) and access(fpath, X_OK): _dump_ctx(ctx) code = yield from execute([ fpath, ctx['src_name'], ctx['version'], ctx['debian_revision'] ], cwd=dpath) if code != 0: raise Exception("pre hook for %s failed with %d return code" % (ctx['name'], code)) for o_dpath in reversed(override_paths): # copy static files deb_dpath = join(o_dpath, 'debian') if isdir(deb_dpath): _copy_static_files(deb_dpath, debian_dir) for key in ('vcs_src', 'vcs_browser', 'uploaders'): if key in ctx: ctx[key] = ctx[key].format(**ctx) ctx['debian_version'] = "{}-{}".format(ctx['version'], ctx['debian_revision']) # Jinja setup: set templates directories templates_dir = [dpath] # use existing dir as a template dir as well templates_dir.extend(override_paths) templates_dir.append(TEMPLATES_PATH) env = Environment(loader=FileSystemLoader(templates_dir)) # render debian dir files (note that order matters) docs(dpath, ctx, env) control(dpath, ctx, env) rules(dpath, ctx, env) chmod(join(dpath, 'debian', 'rules'), 0o755) initial_release = yield from changelog(dpath, ctx, env) if initial_release: itp_mail(dpath, ctx, env) copyright(dpath, ctx, env) watch(dpath, ctx, env) clean(dpath, ctx, env) # invoke post hooks for o_dpath in override_paths: fpath = join(o_dpath, 'hooks', 'post') if exists(fpath) and access(fpath, X_OK): _dump_ctx(ctx) code = yield from execute([ fpath, ctx['src_name'], ctx['version'], ctx['debian_revision'] ], cwd=dpath) if code != 0: raise Exception("post hook for %s failed with %d return code" % (ctx['name'], code))