Created
June 16, 2015 09:16
-
-
Save JonasGroeger/6dc444411301ca467cc2 to your computer and use it in GitHub Desktop.
Generates '/etc/apt/sources.list' compatible lists for Ubuntu releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import getpass | |
import os | |
import time | |
import sys | |
KNOWN_CODENAMES = ['lucid', 'precise', 'trusty', 'utopic', 'vivid', 'wily'] | |
TEMPLATE = """ | |
# Start: Generated by '{user}' with '{program}' on '{date}' | |
# Binary | |
deb {url} {codename} main restricted universe multiverse | |
deb {url} {codename}-proposed main restricted universe multiverse | |
deb {url} {codename}-security main restricted universe multiverse | |
deb {url} {codename}-updates main restricted universe multiverse | |
deb {url} {codename}-backports main restricted universe multiverse | |
# Source | |
deb-src {url} {codename} main restricted universe multiverse | |
deb-src {url} {codename}-proposed main restricted universe multiverse | |
deb-src {url} {codename}-security main restricted universe multiverse | |
deb-src {url} {codename}-updates main restricted universe multiverse | |
deb-src {url} {codename}-backports main restricted universe multiverse | |
# End: Generated by '{user}' with '{program}' on '{date}' | |
""" | |
def main(args): | |
valid = validate_codename(args.codename, args.force_codename) | |
if not valid: | |
print("[ERR] Codename '{}' is not among the known codenames ({})." | |
.format(args.codename, ', '.join(KNOWN_CODENAMES)), file=sys.stderr) | |
print("[ERR] Exiting...", file=sys.stderr) | |
sys.exit(1) | |
# ISO 8601 with 'minute' timespec. same as `date -Imin` | |
now_iso8601 = time.strftime('%Y-%m-%dT%H:%M%z', time.gmtime()) | |
# The name of this file | |
script_name = os.path.basename(__file__) | |
user = getpass.getuser() | |
print(TEMPLATE.strip().format( | |
program=script_name, | |
date=now_iso8601, | |
user=user, | |
url=args.url, | |
codename=args.codename, | |
)) | |
def validate_codename(codename, force): | |
if force: | |
return True | |
if codename not in KNOWN_CODENAMES: | |
return False | |
return True | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description="Generates '/etc/apt/sources.list' compatible lists for Ubuntu releases") | |
parser.add_argument( | |
"--codename", | |
required=True, | |
help="Codename of the release. Can be checked via `lsb_release -c`") | |
parser.add_argument( | |
"--force-codename", | |
action='store_true', | |
default=False, | |
help="Force the use of the provided codename, even if it is not a known one") | |
parser.add_argument( | |
"--url", | |
required=True, | |
help="URL for the source / dist files of packages. Should end with 'ubuntu/'") | |
args = parser.parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment