forked from mozilla-releng/balrog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3to4.py
59 lines (47 loc) · 2.04 KB
/
3to4.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
#!/usr/bin/env python
import logging
from os import path
import site
mydir = path.dirname(path.abspath(__file__))
site.addsitedir(path.join(mydir, ".."))
site.addsitedir(path.join(mydir, "..", "vendor/lib/python"))
from auslib.blobs.apprelease import ReleaseBlobV4
from auslib.config import AdminConfig
from auslib.db import AUSDatabase
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--db", dest="db", help="The database to use, in URI format. Incompatible with --ini.")
parser.add_argument("--ini", dest="ini", help="The config file to look for the database in. Incompatible with --db.")
parser.add_argument("--name", dest="name", required=True, help="The name of the person/script doing the migrations.")
parser.add_argument("releases", metavar="release", nargs="+", help="The releases (aka blob names) to migrate.")
args = parser.parse_args()
if args.db and args.ini:
parser.error("Cannot specify --db and --ini!")
if args.ini:
cfg = AdminConfig(args.ini)
db = AUSDatabase(cfg.getDburi())
db.setDomainWhitelist(cfg.getDomainWhitelist())
else:
db = AUSDatabase(args.db)
for release in args.releases:
try:
rel = db.releases.getReleases(name=release)[0]
blob = rel["data"]
except:
log.debug("No such release '%s', skipping", release)
if blob["schema_version"] == 4:
log.debug("%s is already schema 4, skipping", release)
continue
elif blob["schema_version"] != 3:
log.debug("%s is not schema 3, can't upgrade it", release)
continue
try:
log.debug("Upgrading %s", release)
v4Blob = ReleaseBlobV4.fromV3(blob)
db.releases.updateRelease(release, args.name, rel["data_version"], blob=v4Blob)
log.debug("Done")
except:
log.exception("Failed to upgrade %s", release)