]> git.ipfire.org Git - location/libloc.git/blobdiff - src/python/location.in
location: Fix Python syntax error in verify()
[location/libloc.git] / src / python / location.in
index c4987a5ccae6672606b60ad2602f770520bf42f6..b5e57589b595c39b921cc32f6808b4141ed86b3b 100644 (file)
@@ -199,9 +199,14 @@ class CLI(object):
                try:
                        db = location.Database(args.database)
                except FileNotFoundError as e:
-                       sys.stderr.write("location: Could not open database %s: %s\n" \
-                               % (args.database, e))
-                       sys.exit(1)
+                       # Allow continuing without a database
+                       if args.func == self.handle_update:
+                               db = None
+
+                       else:
+                               sys.stderr.write("location: Could not open database %s: %s\n" \
+                                       % (args.database, e))
+                               sys.exit(1)
 
                # Translate family (if present)
                if "family" in args:
@@ -396,7 +401,7 @@ class CLI(object):
                        now = datetime.datetime.utcnow()
 
                        # Parse the database timestamp
-                       t = datetime.datetime.fromtimestamp(db.created_at)
+                       t = datetime.datetime.utcfromtimestamp(db.created_at)
 
                        if ns.cron == "daily":
                                delta = datetime.timedelta(days=1)
@@ -408,16 +413,16 @@ class CLI(object):
                        # Check if the database has recently been updated
                        if t >= (now - delta):
                                log.info(
-                                       _("The datase has recently be updated recently (%s)") % \
+                                       _("The database has been updated recently (%s)") % \
                                                format_timedelta(now - t),
                                )
-                               return
+                               return 3
 
                # Fetch the timestamp we need from DNS
                t = location.discover_latest_version()
 
                # Parse timestamp into datetime format
-               timestamp = datetime.datetime.fromtimestamp(t) if t else None
+               timestamp = datetime.datetime.utcfromtimestamp(t) if t else None
 
                # Check the version of the local database
                if db and timestamp and db.created_at >= timestamp.timestamp():
@@ -448,13 +453,7 @@ class CLI(object):
 
                return 0
 
-       def handle_verify(self, ns):
-               try:
-                       db = location.Database(ns.database)
-               except FileNotFoundError as e:
-                       log.error("%s: %s" % (ns.database, e))
-                       return 127
-
+       def handle_verify(self, db, ns):
                # Verify the database
                with open(ns.public_key, "r") as f:
                        if not db.verify(f):