-
Notifications
You must be signed in to change notification settings - Fork 0
/
amp_build.py
executable file
·63 lines (53 loc) · 2.19 KB
/
amp_build.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
61
62
63
#!/bin/env python3
from amp.package import *
import argparse
import logging
from pathlib import Path
import subprocess
import sys
import tempfile
import shutil
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--debug", default=False, action="store_true", help="Turn on debugging")
parser.add_argument("--package", default=False, action="store_true", help="Build package instead of install")
parser.add_argument("destination", help="Destination for build (should be an AMP_ROOT for non-package)")
args = parser.parse_args()
logging.basicConfig(format="%(asctime)s [%(levelname)-8s] (%(filename)s:%(lineno)d) %(message)s",
level=logging.DEBUG if args.debug else logging.INFO)
# Build the container
# Just some scripts, nothing to build.
# Install the container
destdir = Path(args.destination)
if args.package:
# create a temporary directory for the build.
tempdir = tempfile.TemporaryDirectory()
destdir = Path(tempdir.name)
target = destdir / "data/MediaProbe"
target.mkdir(parents=True, exist_ok=True)
logging.info(f"Copying files to {target!s}")
try:
for file in ('media_probe/__init__.py',
'LICENSE',
'media_probe_schema.json',
'media_probe.py',
'README.md'):
dfile = target / file
if not dfile.parent.exists():
dfile.parent.mkdir(parents=True)
shutil.copyfile(file, dfile)
shutil.copystat(file, dfile)
except Exception as e:
logging.error(f"Failed to copy file: {e}")
exit(1)
# Package it, if needed
if args.package:
try:
new_package = create_package("mediaprobe", "1.0.1", "data/MediaProbe",
Path(args.destination), target)
logging.info(f"New package in {new_package}")
except Exception as e:
logging.error(f"Failed to build backage: {e}")
exit(1)
if __name__ == "__main__":
main()