Merge ~smoser/usd-importer:usd-clone-user-cleanup into usd-importer:master

Proposed by Scott Moser on 2016-11-10
Status: Merged
Merged at revision: 353135299cdef348f614ee659b294ebdecfcfe22
Proposed branch: ~smoser/usd-importer:usd-clone-user-cleanup
Merge into: usd-importer:master
Diff against target: 152 lines (+33/-46)
1 file modified
usd/clone.py (+33/-46)
Reviewer Review Type Date Requested Status
Nish Aravamudan 2016-11-10 Approve on 2016-11-10
Review via email: mp+310580@code.launchpad.net
To post a comment you must log in.
Nish Aravamudan (nacc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/usd/clone.py b/usd/clone.py
2index 1dc0a4a..aa70201 100644
3--- a/usd/clone.py
4+++ b/usd/clone.py
5@@ -6,13 +6,14 @@ import re
6 from subprocess import CalledProcessError
7 import sys
8 from usd.git_repository import USDGitRepository
9-from usd.run import decode_binary
10+from usd.run import decode_binary, run
11+
12+LP_USER_NONE = 'NONE'
13
14 class USDClone:
15 def __init__(self):
16 self.lpusi = 'usd-import-team'
17 self.lpusd = 'ubuntu-server-dev'
18- self.LP_USER_NONE = 'NONE'
19
20 def parse_args(self, subparsers=None):
21 kwargs = dict(
22@@ -63,69 +64,55 @@ Example:
23 return parser.parse_args()
24 return 'clone - %s' % kwargs['description']
25
26- def find_lp_user(self, user_in):
27+ @staticmethod
28+ def find_lp_user(user_in=None):
29 # find a launchpad user.
30 # return 1 on error, 2 on "just didn't find anything"
31 if user_in is not None:
32 return user_in
33+ rmatch = re.compile(
34+ r'^(url.*(git\+|)ssh://(.*)@git.launchpad.*).insteadof.*')
35+ gitcmd = ['git', 'config', '--get-regexp', 'url.*ssh://.*.insteadof']
36 try:
37 # ideally could use self.local_repo.config.get_multivar
38 # but it does not support getting by regex
39- cp = self.local_repo.git_run(['config', '--get-regexp',
40- 'url.git.*.insteadof'
41- ]
42- )
43- instead_of_re = r'^(url.git\+ssh://(.*)@git.launchpad.*).insteadof.*'
44- for instead_of in decode_binary(cp.stdout).strip():
45- m = re.match(instead_of_re, instead_of)
46+ cp = run(gitcmd)
47+ for line in decode_binary(cp.stdout).splitlines():
48+ m = rmatch.match(line)
49 if m is not None:
50- logging.debug('found user %s in %s' % (m.group(1),
51- m.group(0)
52- )
53- )
54- return m.group(1)
55- break
56+ logging.debug("found user '%s' in '%s'",
57+ m.group(3), m.group(1))
58+ return m.group(3)
59 except CalledProcessError:
60 # if no insteadof found
61 logging.debug("Unable to find a launchpad user in git config.")
62 return None
63
64- def prompt_for_lpuser(self):
65+ @staticmethod
66+ def prompt_for_lpuser(default=LP_USER_NONE):
67 if not sys.stdin.isatty() or not sys.stdout.isatty():
68- logging.error('Input not a terminal, assuming user=%s' %
69- self.LP_USER_NONE
70- )
71- return self.LP_USER_NONE
72+ logging.error('Input not a terminal, assuming user=%s', default)
73+ return default
74 user = input('What is your launchpad username? [Enter to skip] ')
75 if len(user) == 0:
76 logging.error("pass --no-launchpad-user to avoid this prompt.")
77- _RET="$none"
78- return self.LP_USER_NONE
79+ return default
80 url = 'ssh://%s@git.launchpad.net/' % user
81- args = ['config', '--global', 'url.%s.insteadof' % url, 'lp:']
82+ args = ['git', 'config', '--global', 'url.%s.insteadof' % url, 'lp:']
83 logging.error('I can store this answer for next time by adding '
84 'a git config alias of "lp:" to "%s"\n'
85- 'Command to do that is:\n%s' %
86- (url, ' '.join(args))
87- )
88- add = input('Shall I do that now? [Y/n] ')
89- if len(add) == 0:
90- add = 'y'
91- if add == 'y' or add == 'Y' or add == 'yes' or add == 'Yes':
92- add = 'y'
93- if add == 'n' or add == 'N' or add == 'no' or add == 'No':
94- add = 'n'
95- if add != 'y' and add != 'n':
96- logging.error('Assuming "%s" meant no.' % add)
97- add='n'
98- if add == 'y':
99+ 'Command to do that is:\n %s',
100+ url, ' '.join(args))
101+ add = input('Shall I do that now? [Y/n] ').lower()
102+ if add in ("", "y", "yes"):
103 try:
104- self.local_repo.git_run(args)
105+ run(args)
106 except CalledProcessError:
107- logging.error('failed to configure git with %s' %
108- ' '.join(args)
109- )
110+ logging.error('failed to configure git with %s',
111+ ' '.join(args))
112 sys.exit(1)
113+ elif add not in ("n", "no"):
114+ logging.error('Assuming "%s" meant no.', add)
115 return user
116
117 def render_url(self, proto, user):
118@@ -141,7 +128,7 @@ Example:
119 logging.error('empty package')
120 return None
121 if proto == 'ssh':
122- if self.lp_user is None or self.lp_user == self.LP_USER_NONE:
123+ if self.lp_user is None or self.lp_user == LP_USER_NONE:
124 logging.error("ssh requires lpuser")
125 return None
126 return '%s://%s@%s' % (proto, self.lp_user, base)
127@@ -154,7 +141,7 @@ Example:
128 self.package = args.package
129 self.proto = args.proto
130 if args.no_launchpad_user:
131- self.lp_user = self.LP_USER_NONE
132+ self.lp_user = LP_USER_NONE
133 else:
134 self.lp_user = args.launchpad_user
135 self.directory = (
136@@ -183,14 +170,14 @@ Example:
137 self.lp_user = self.prompt_for_lpuser()
138
139 usd_proto = 'ssh'
140- if self.lp_user == self.LP_USER_NONE:
141+ if self.lp_user == LP_USER_NONE:
142 usd_proto = self.proto
143
144 remotes = [
145 (self.proto, self.lpusi, 'importer'),
146 (usd_proto, self.lpusd, 'lpusd')
147 ]
148- if self.lp_user != self.LP_USER_NONE:
149+ if self.lp_user != LP_USER_NONE:
150 remotes += [('ssh', self.lp_user, self.lp_user)]
151
152 for proto, user, namespace in remotes:

Subscribers

People subscribed via source and target branches