7 class ModifiedParser(argparse.ArgumentParser):
9 modified error handling to print help
11 def error(self, message):
12 sys.stderr.write('error: %s\n' % message)
17 def create_blacklist(config_file):
19 Generate a list of images which needs to be excluded from docker_image_list
20 :param config_file: application_configuration file where images are.
23 with open(config_file, 'r') as f:
24 file = yaml.load(f, Loader=yaml.SafeLoader)
27 for name, _ in file['runtime_images'].items():
28 path = file['runtime_images'][name]['path']
29 blacklist.append(path[1:])
33 def should_remove_line(line, blacklist):
35 Helping function to match image in blacklist
36 :param line: line in datalist file
37 :param blacklist: list of images to be removed
40 return any([image in line for image in blacklist])
43 def update_datalist(config_file, datalist):
45 remove local images from datalist.
46 :param config_file: application_configuration file where images are.
47 :param datalist: docker_image_list to be updated
50 blacklist = create_blacklist(config_file)
52 with open(datalist, 'r') as f:
54 if not should_remove_line(line, blacklist):
56 with open(datalist, 'w') as f:
66 parser = ModifiedParser(description='Remove runtime images from docker_image_list')
68 parser.add_argument('config_file',
69 help='application_configuration file where images are')
70 parser.add_argument('datalist',
71 help='docker_image_list from where images should be removed')
72 args = parser.parse_args()
74 update_datalist(args.config_file, args.datalist)
77 if __name__ == '__main__':