--login is now optional, ctrl-c caught
This commit is contained in:
25
registry.py
25
registry.py
@@ -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:
|
||||||
print "Please provide -l in the form USER:PASSWORD"
|
if not ':' in login:
|
||||||
exit(1)
|
print "Please provide -l in the form USER:PASSWORD"
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
(self.username, self.password) = login.split(':')
|
||||||
|
|
||||||
(self.username, self.password) = userpass.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()
|
||||||
main_loop(args)
|
try:
|
||||||
|
main_loop(args)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print "Ctrl-C pressed, quitting"
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user