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