-
Notifications
You must be signed in to change notification settings - Fork 0
/
write-mercury-nohash-metadata.py
executable file
·60 lines (45 loc) · 2.19 KB
/
write-mercury-nohash-metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# 1st-party
import datetime
import logging
import os
# 2nd-party
from metadatawriter import MetadataWriter, write
from nouns import MERCURY_NOHASH_DIRECTORY,
MERCURY_NOHASH_DIRTY_PROJECTS_CACHE_FILEPATH, \
MERCURY_NOHASH_METADATA_PATCH_LENGTH_CACHE_FILEPATH, \
MERCURY_NOHASH_METADATA_DIRECTORY
from repository import MercuryAlphabeticalRepository
class MercuryMetadataWriter(MetadataWriter):
def make_snapshot_administrator_metadata(self, timestamp):
if len(self.repository.projects.dirty) > 0:
meta = {}
# project developers
for project_name in self.repository.projects.names:
# TODO: Really should not be hardcoding file paths. Instead, each
# metadata object should know where it lives on disk.
filename = 'packages/{}.json'.format(project_name)
meta[filename] = \
self.repository.projects.get_project_version(project_name)
# Commit the snapshot metadata to memory.
keyids = self.repository.snapshot_administrator_keyids
version = self.repository.snapshot_administrator_version
self.snapshot_administrator_metadata = \
self.make_release_metadata(keyids=keyids,
meta=meta,
timestamp=timestamp,
version=version)
self.snapshot_administrator_metadata_json = \
self.jsonify(self.snapshot_administrator_metadata)
else:
logging.debug('No new snapshot metadata, '\
'because no new package metadata.')
def project_metadata_identifier(self, project_name):
return self.repository.projects.get_project_version(project_name)
if __name__ == '__main__':
log_filename = os.path.join(MERCURY_NOHASH_METADATA_DIRECTORY,
'write-mercury-nohash-metadata.log')
write(log_filename, MERCURY_NOHASH_DIRTY_PROJECTS_CACHE_FILEPATH,
MERCURY_NOHASH_METADATA_PATCH_LENGTH_CACHE_FILEPATH,
MercuryAlphabeticalRepository, MercuryMetadataWriter,
MERCURY_NOHASH_DIRECTORY)