--login is now optional, ctrl-c caught

This commit is contained in:
Andrey Pohilko
2016-10-26 17:49:26 +06:00
parent 5cda401b12
commit d7411cb689

View File

@@ -47,12 +47,14 @@ class Registry:
# store last error if any # store last error if any
__error = None __error = None
def __init__(self, host, userpass): def __init__(self, host, login):
if not ':' in userpass: if login != None:
if not ':' in login:
print "Please provide -l in the form USER:PASSWORD" print "Please provide -l in the form USER:PASSWORD"
exit(1) exit(1)
(self.username, self.password) = userpass.split(':') (self.username, self.password) = login.split(':')
self.hostname = host self.hostname = host
def __atoi(self, text): def __atoi(self, text):
@@ -71,7 +73,9 @@ class Registry:
result = requests.request( result = requests.request(
method, "{}{}".format(self.hostname, path), method, "{}{}".format(self.hostname, path),
headers = self.HEADERS, headers = self.HEADERS,
auth=(self.username, self.password)) auth=(None if self.username == ""
else (self.username, self.password)))
except Exception as error: except Exception as error:
print "cannot connect to {}\nerror {}".format( print "cannot connect to {}\nerror {}".format(
self.hostname, self.hostname,
@@ -189,7 +193,7 @@ for more detail on garbage collection read here:
parser.add_argument( parser.add_argument(
'-l','--login', '-l','--login',
help="Login and password to access to docker registry", help="Login and password to access to docker registry",
required=True, required=False,
metavar="USER:PASSWORD") metavar="USER:PASSWORD")
parser.add_argument( parser.add_argument(
@@ -312,4 +316,9 @@ def main_loop(args):
if __name__ == "__main__": if __name__ == "__main__":
args = parse_args() args = parse_args()
try:
main_loop(args) main_loop(args)
except KeyboardInterrupt:
print "Ctrl-C pressed, quitting"
exit(1)