2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-23 04:29:02 +00:00
bench/vm/build.py

61 lines
1.3 KiB
Python
Raw Normal View History

2015-12-24 00:25:55 +00:00
"""
Builds a vm and puts it in ~/public with a latest.json that has its filename and md5sum
"""
# imports - standard imports
import os
import json
import stat
from subprocess import check_output
2015-12-24 00:25:55 +00:00
OUTPUT_DIR = 'output-virtualbox-ovf'
PUBLIC_DIR = os.path.join(os.path.expanduser('~'), 'public')
def main():
install_virtualbox()
install_packer()
2015-12-24 00:25:55 +00:00
build_vm()
update_latest()
move_to_public()
cleanup()
def install_virtualbox():
check_output(['bench', 'install', 'virtualbox'])
def install_packer():
check_output(['bench', 'install', 'packer'])
2015-12-24 00:25:55 +00:00
def build_vm():
2018-03-03 21:31:41 +00:00
check_output("/opt/packer build vm.json", shell=True)
2015-12-24 00:25:55 +00:00
def move_to_public():
src = get_filepath()
dest = os.path.join(PUBLIC_DIR, os.path.join(PUBLIC_DIR, get_filename()))
os.rename(src, dest)
st = os.stat(dest)
os.chmod(dest, st.st_mode | stat.S_IROTH)
def update_latest():
with open(os.path.join(PUBLIC_DIR, "latest.json"), 'w') as f:
json.dump(get_latest(), f)
def get_latest():
md5 = check_output("md5sum {}".format(get_filepath()), shell=True).split()[0]
2015-12-24 00:25:55 +00:00
return {
"filename": get_filename(),
"md5": md5
}
def get_filename():
return os.listdir(OUTPUT_DIR)[0]
def get_filepath():
filename = os.listdir(OUTPUT_DIR)[0]
return os.path.join(OUTPUT_DIR, filename)
def cleanup():
os.rmdir(OUTPUT_DIR)
if __name__ == "__main__":
main()