Take rollout percentages from old manifest.
This commit is contained in:
@@ -20,6 +20,10 @@ parser.add_argument(
|
||||
dest='image_type',
|
||||
action='store',
|
||||
required=True)
|
||||
parser.add_argument(
|
||||
'--old-manifest',
|
||||
dest='old_manifest',
|
||||
action='store')
|
||||
FLAGS = parser.parse_args()
|
||||
|
||||
|
||||
@@ -28,23 +32,39 @@ class ManifestBuilder(object):
|
||||
_FILE_REGEX = '^%(image_type)s\.(?P<timestamp>\d+)\.iso$'
|
||||
_BUF_SIZE = 2 ** 16
|
||||
|
||||
def __init__(self, image_dir, image_type):
|
||||
def __init__(self, image_dir, image_type, old_manifest):
|
||||
self._image_dir = image_dir
|
||||
self._file_regex = re.compile(self._FILE_REGEX % {
|
||||
'image_type': image_type,
|
||||
})
|
||||
self._old_manifest = old_manifest
|
||||
|
||||
def _Rollouts(self):
|
||||
if not self._old_manifest:
|
||||
return {}
|
||||
try:
|
||||
with open(self._old_manifest, 'r') as fh:
|
||||
parsed = json.load(fh)
|
||||
return dict(
|
||||
(image['timestamp'], image['rollout_‱'])
|
||||
for image in parsed['images'])
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
|
||||
def BuildManifest(self):
|
||||
ret = {
|
||||
'timestamp': int(time.time()),
|
||||
'images': [],
|
||||
}
|
||||
rollouts = self._Rollouts()
|
||||
for filename in os.listdir(self._image_dir):
|
||||
match = self._file_regex.match(filename)
|
||||
if not match:
|
||||
continue
|
||||
timestamp = int(match.group('timestamp'))
|
||||
image = {
|
||||
'timestamp': match.group('timestamp'),
|
||||
'timestamp': timestamp,
|
||||
'rollout_‱': rollouts.get(timestamp, 0),
|
||||
}
|
||||
with open(os.path.join(self._image_dir, filename), 'rb') as fh:
|
||||
hash_obj = hashlib.sha256()
|
||||
@@ -55,10 +75,11 @@ class ManifestBuilder(object):
|
||||
hash_obj.update(data)
|
||||
image['hash'] = hash_obj.hexdigest()
|
||||
ret['images'].append(image)
|
||||
ret['images'].sort(key=lambda x: x['timestamp'], reverse=True)
|
||||
return ret
|
||||
|
||||
|
||||
builder = ManifestBuilder(FLAGS.image_dir, FLAGS.image_type)
|
||||
builder = ManifestBuilder(FLAGS.image_dir, FLAGS.image_type, FLAGS.old_manifest)
|
||||
manifest = builder.BuildManifest()
|
||||
json.dump(manifest, sys.stdout, indent=4)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
Reference in New Issue
Block a user