Move code into main()
This commit is contained in:
@@ -79,7 +79,12 @@ class ManifestBuilder(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
builder = ManifestBuilder(FLAGS.image_dir, FLAGS.image_type, FLAGS.old_manifest)
|
builder = ManifestBuilder(FLAGS.image_dir, FLAGS.image_type, FLAGS.old_manifest)
|
||||||
manifest = builder.BuildManifest()
|
manifest = builder.BuildManifest()
|
||||||
json.dump(manifest, sys.stdout, indent=4)
|
json.dump(manifest, sys.stdout, sort_keys=True, indent=4)
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class Fetcher(object):
|
|||||||
def _ChooseImage(self, manifest):
|
def _ChooseImage(self, manifest):
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
hash_base = hashlib.sha256(hostname.encode('ascii'))
|
hash_base = hashlib.sha256(hostname.encode('ascii'))
|
||||||
for image in manifest:
|
for image in manifest['images']:
|
||||||
hashobj = hash_base.copy()
|
hashobj = hash_base.copy()
|
||||||
hashobj.update(struct.pack('!L', image['timestamp']))
|
hashobj.update(struct.pack('!L', image['timestamp']))
|
||||||
my_bp = struct.unpack('!I', hashobj.digest()[-4:])[0] % self._MAX_BP
|
my_bp = struct.unpack('!I', hashobj.digest()[-4:])[0] % self._MAX_BP
|
||||||
@@ -96,8 +96,12 @@ class Fetcher(object):
|
|||||||
def Fetch(self):
|
def Fetch(self):
|
||||||
manifest = self._GetManifest()
|
manifest = self._GetManifest()
|
||||||
image = self._ChooseImage(manifest)
|
image = self._ChooseImage(manifest)
|
||||||
print(image)
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
fetcher = Fetcher(FLAGS.base_url, FLAGS.image_type, FLAGS.ca_cert)
|
fetcher = Fetcher(FLAGS.base_url, FLAGS.image_type, FLAGS.ca_cert)
|
||||||
fetcher.Fetch()
|
fetcher.Fetch()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
@@ -49,7 +49,12 @@ class Wrapper(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
wrapper = Wrapper(FLAGS.key, FLAGS.cert, FLAGS.other_certs)
|
wrapper = Wrapper(FLAGS.key, FLAGS.cert, FLAGS.other_certs)
|
||||||
wrapped = wrapper.Wrap(sys.stdin.read())
|
wrapped = wrapper.Wrap(sys.stdin.read())
|
||||||
json.dump(wrapped, sys.stdout, sort_keys=True, indent=4)
|
json.dump(wrapped, sys.stdout, sort_keys=True, indent=4)
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user