Ubuntu Pastebin

Paste from nacc at Wed, 1 Nov 2017 23:13:56 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3

import argparse
import lazr.restfulclient
import os
import sys

# We expect to be running from a git repository in master for this
# script, because the snap's python code is not exposed except within
# the snap
try:
    REALPATH = os.readlink(__file__)
except OSError:
    REALPATH = __file__
sys.path.insert(
    0,
    os.path.abspath(
        os.path.join(os.path.dirname(REALPATH), os.path.pardir)
    )
)

from gitubuntu.source_information import launchpad_login_auth

def main(
    package,
    dry_run=False,
):
    launchpad = launchpad_login_auth()
    try:
        target = lp.load('ubuntu/+source/%s' % package)
        current_default = launchpad.git_repositories.getDefaultRepository(
            target=target
        )
        print(
            "Current default Git repository: %s" %
            current_default.git_https_url
        )
        if not dry_run:
            importer_git_repo = launchpad.git_repository.getByPath(
                path='~usd-import-team/ubuntu/+source/%s/+git/%s' % (
                    package,
                    package,
                )
            )
            launchpad.git_repositories.setDefaultRepository(
                repository=importer_git_repo,
                target=target,
            )
    except lazr.restfulclient.errors.BadRequest:
        print("No default Git repository set")

def cli_main():
    parser = argparse.ArgumentParser(
        description='Update the default Git repository for a source package',
    )
    parser.add_argument(
        'package',
        type=str,
        help="Name of source package",
    )
    parser.add_argument(
        '--dry-run',
        action='store_true',
        help="Simulate operation but do not actually do anything",
        default=False,
    )

    args = parser.parse_args()

    return main(
        package=args.package,
        dry_run=args.dry_run,
    )

if __name__ == '__main__':
    cli_main()
Download as text