#!/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()