def main(options): f = Factory() set_logger(options) options['output_dir']=create_output_dir(options['output_dir']) modules = f.load_modules(options['packages'], options['output_dir']) for m in modules: classes = f.load_classes(m, options['OS'], options['release']) for cl in classes: instance = cl(options) if 'dump' in str(cl): for m in options['dump'].split(','): try: if options['output_type'] in EXTRACT_DUMP[m]: getattr(instance, EXTRACT_DUMP[m])() except Exception: options['logger'].error(traceback.format_exc()) continue for name, method in inspect.getmembers(cl, predicate=inspect.ismethod): if not name.startswith('_'): try: if options['output_type'] in name: getattr(instance, name)() except Exception: options['logger'].error(traceback.format_exc())
def serialize(dest_format, path_file): serializer = Factory.create_serializer(dest_format) try: src_format = Path(path_file).suffix if src_format == dest_format: return deserializer = Factory.create_serializer(src_format) abs_path = Path(path_file) loaded = deserializer.load(path_file) serializer.dump(loaded, Path(abs_path.parent, f"{abs_path.stem}{dest_format}")) except FileNotFoundError: print("wrong path or format")
def main(): factory = Factory.get_instance() car_wash_repo = factory.create_car_wash_repo("json", "car_wash.json") car_repo = factory.create_car_repo("json", "car_wash.json") service = Service(car_repo, car_wash_repo) console = Console(service) console.run()
def test_json_cmplx_func(self): self.s = Factory.create_serializer('.json') old_obj = test_source.cmplx_func old_obj_2 = test_source.simple_lambda new_obj = self.s.loads(self.s.dumps(old_obj)) new_obj_2 = self.s.loads(self.s.dumps(old_obj_2)) self.assertEqual(old_obj(4), new_obj(4)) self.assertEqual(old_obj_2(4), new_obj_2(4))
def test_json_cmplx_class_obj(self): self.s = Factory.create_serializer('.json') old_obj = test_source.ComplexClass() new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj.simple_class.word, new_obj.simple_class.word) self.assertEqual(old_obj.func_with_glob(), new_obj.func_with_glob(new_obj)) self.assertEqual(old_obj.const, new_obj.const) self.assertEqual(old_obj.simple_class.say_kuku(), new_obj.simple_class.say_kuku(new_obj.simple_class))
def main(): # 引数を解析 parser = argparse.ArgumentParser() parser.add_argument("--f") args = parser.parse_args() # 引数を変数に設定 factory_name = args.f # print(factory_name) factory = Factory.get_factory(factory_name) # print(type(factory)) asahi = factory.create_link(caption="朝日新聞", url="http://www.asahi.com/") yomiuri = factory.create_link("読売新聞", "http://www.yomiuri.co.jp/") us_yahoo = factory.create_link("Yahoo!", "http://www.yahoo.com/") jp_yahoo = factory.create_link("Yahoo!Japan", "http://www.yahoo.co.jp/") excite = factory.create_link("Excite", "http://www.excite.com/") google = factory.create_link("Google", "http://www.google.com/") traynews = factory.create_tray("新聞") traynews.add(asahi) traynews.add(yomiuri) trayyahoo = factory.create_tray("Yahoo!") trayyahoo.add(us_yahoo) trayyahoo.add(jp_yahoo) traysearch = factory.create_tray("サーチエンジン") traysearch.add(trayyahoo) traysearch.add(excite) traysearch.add(google) page = factory.create_page("LinkPage", "結城 浩") page.add(traynews) page.add(traysearch) page.output()
def test_json_lambda(self): self.s = Factory.create_serializer('.json') old_obj = test_source.simple_lambda new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj(5), new_obj(5))
def test_yaml_float(self): self.s = Factory.create_serializer('.yaml') old_obj = test_source.float_glob new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)
from view import draw from factory.game import Game from factory.factory import Factory if __name__ == "__main__": game = Game([ Factory(), Factory(100), Factory(200), Factory(300), Factory(400) ], 5) draw(game)
def test_json_simple_class_obj(self): self.s = Factory.create_serializer('.json') old_obj = test_source.SimpleClass() new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj.say_kuku(), new_obj.say_kuku(new_obj)) self.assertEqual(old_obj.word, new_obj.word)
def test_json_simple_func(self): self.s = Factory.create_serializer('.json') old_obj = test_source.simple_func self.s.dump(old_obj, 'test.json') new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj(4), new_obj(4))
def test_json_int(self): self.s = Factory.create_serializer('.json') old_obj = test_source.int_glob new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)
def test_json_dict(self): self.s = Factory.create_serializer('.json') old_obj = test_source.dict_1 new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj['Name'], new_obj['Name'])
from typing import List import argparse import os from factory.factory import Factory if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("class_name") args = parser.parse_args() class_name = args.class_name # listfactory.listfactory.ListFactory factory = Factory.get_factory(class_name) print(factory) google_link = factory.create_link('Google', 'https://www.google.com/') jp_yahoo_link = factory.create_link('Yahoo! JAPAN', 'https://www.yahoo.co.jp/') us_yahoo_link = factory.create_link('Yahoo!', 'https://www.yahoo.com/') yahoo_tray = factory.create_tray('Yahoo!') yahoo_tray.add(jp_yahoo_link) yahoo_tray.add(us_yahoo_link) search_tray = factory.create_tray('サーチエンジン') search_tray.add(yahoo_tray) search_tray.add(google_link) page = factory.create_page('LinkPage', 'Sadistica') page.add(search_tray) page.output()
def test_pickle_cmplx_func(self): self.s = Factory.create_serializer('.pickle') old_obj = test_source.cmplx_func new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj(4), new_obj(4))
def test_pickle_dict(self): self.s = Factory.create_serializer('.pickle') old_obj = test_source.dict_1 new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)
def test_pickle_boolean(self): self.s = Factory.create_serializer('.pickle') old_obj = test_source.boolean_glob new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)
def test_toml_set(self): self.s = Factory.create_serializer('.toml') old_obj = test_source.set_1 new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)
def test_yaml_tuple(self): self.s = Factory.create_serializer('.yaml') old_obj = test_source.tuple_1 new_obj = self.s.loads(self.s.dumps(old_obj)) self.assertEqual(old_obj, new_obj)