2019-03-28 03:28:51 +03:00
#!/usr/bin/python3
2020-04-25 01:04:10 +03:00
from collections . abc import Iterable
2019-03-28 03:28:51 +03:00
import argparse
2020-04-25 01:04:10 +03:00
import yaml
2020-04-20 14:29:27 +03:00
import sys
2019-03-28 03:28:51 +03:00
2020-04-20 14:29:27 +03:00
import cloud_build
2019-07-08 02:14:01 +03:00
2019-03-28 03:28:51 +03:00
PROG = ' cloud-build '
def parse_args ( ) :
2020-04-25 01:04:10 +03:00
def is_dict ( string ) :
raw_dict = dict ( yaml . safe_load ( string ) )
result = { }
for k , v in raw_dict . items ( ) :
key = k . lower ( )
if not isinstance ( v , Iterable ) or isinstance ( v , str ) :
result [ key ] = [ v ]
else :
result [ key ] = v
return result
2019-03-28 03:28:51 +03:00
parser = argparse . ArgumentParser (
formatter_class = argparse . ArgumentDefaultsHelpFormatter ,
)
parser . add_argument (
' -c ' ,
' --config ' ,
default = f ' /etc/ { PROG } /config.yaml ' ,
help = ' path to config ' ,
)
2019-11-01 16:44:46 +03:00
parser . add_argument (
' --no-tests ' ,
action = ' store_true ' ,
help = ' disable running tests ' ,
)
2020-04-25 01:04:10 +03:00
parser . add_argument (
' --tasks ' ,
default = { } ,
type = is_dict ,
help = ' add tasks to repositories ' ,
)
2019-03-28 03:28:51 +03:00
args = parser . parse_args ( )
return args
def main ( ) :
args = parse_args ( )
2020-04-25 01:04:10 +03:00
cb = cloud_build . CB ( * * dict ( args . _get_kwargs ( ) ) )
2020-04-20 14:29:27 +03:00
cb . create_images ( )
cb . copy_external_files ( )
cb . sign ( )
cb . sync ( )
2019-03-28 03:28:51 +03:00
if __name__ == ' __main__ ' :
2020-04-20 14:29:27 +03:00
try :
main ( )
except cloud_build . Error as e :
print ( e , file = sys . stdout )
exit ( 1 )