PK]IH(iigallium-0.1.7.data/scripts/g2#!python # -*- coding: utf-8 -*- from gallium.starter import main if __name__ == '__main__': main() PK]IH(iigallium-0.1.7.data/scripts/g3#!python # -*- coding: utf-8 -*- from gallium.starter import main if __name__ == '__main__': main() PK]IH(ii"gallium-0.1.7.data/scripts/gallium#!python # -*- coding: utf-8 -*- from gallium.starter import main if __name__ == '__main__': main() PK+Hs`gallium/console.py""" Prototype for Tori 4.0+ and Imagination 1.10+ :Author: Juti Noppornpitak """ import argparse import json import sys from .interface import ICommand class Console(object): CONST_CONF_KEY_CMD_SETTINGS = 'settings' def __init__(self, name, core, config_path=None, loaders=[]): self.name = name self.core = core self.config = {} if config_path: with open(config_path) as f: self.config.update(json.load(f)) if 'db' in self.config: self._prepare_db_connections() self.loaders = loaders def activate(self): main_parser = argparse.ArgumentParser(self.name) subparsers = main_parser.add_subparsers(help='sub-commands') commands = {} for loader in self.loaders: key = loader.configuration_section_name() if key in self.config and self.config[key]: for identifier, kind, command in loader.all(self.config[key]): self._register_command(subparsers, identifier, kind, command) command.set_core(self.core) command.set_settings( self.config[self.CONST_CONF_KEY_CMD_SETTINGS] if self.CONST_CONF_KEY_CMD_SETTINGS in self.config else {} ) commands[identifier] = command if not commands: print('No commands available') sys.exit(15) args = main_parser.parse_args() try: args.func(args) except KeyboardInterrupt as e: sys.exit(15) def _register_command(self, subparsers, identifier, cls, instance): documentation = cls.__doc__ command_parser = subparsers.add_parser(identifier, help=documentation) instance.define(command_parser) command_parser.set_defaults(func=instance.execute) def _prepare_db_connections(self): self.core.prepare_db_connections(self.config['db']) PKIHCCgallium/starter.pyimport codecs import json import os import sys from gallium import Console, Core from gallium.loader.basic import Loader as BasicLoader from gallium.loader.imagination import Loader as ImaginationLoader base_path = os.path.abspath(os.getcwd()) def __p(path): return os.path.join(base_path, path) def main(): if base_path not in sys.path: sys.path.append(base_path) console_name = __package__ or sys.argv[0] config_path = os.getenv('GALLIUM_CONF') or __p('cli.json') service_config_paths = [] with codecs.open(config_path, 'r') as f: pre_config = json.load(f) if 'paths' in pre_config: sys.path.extend(pre_config['paths']) if 'services' in pre_config: service_config_paths.extend([ __p(service_config_path) for service_config_path in pre_config['services'] ]) framework_core = Core() framework_core.load(*service_config_paths) basic_loader = BasicLoader() imagination_loader = ImaginationLoader(framework_core) enabled_loaders = [ basic_loader, imagination_loader ] console = Console( name = console_name, core = framework_core, config_path = config_path, loaders = enabled_loaders ) console.activate() PK(*Htc[[gallium/__init__.pyfrom .console import Console from .core import Core from .interface import ICommand PK(*HRgallium/interface.py""" Carbon Interfaces ################# :Author: Juti Noppornpitak This is similar to controllers. """ class ICommand(object): @property def settings(self): return self.__settings @property def core(self): return self.__core def set_settings(self, settings): self.__settings = settings def set_core(self, core): self.__core = core def identifier(self): """ Define the identifier of the command. This will be overridden by the imagination entity ID if the command is loaded with the integration with Imagination Framework. :return: the identifier (ID) for the command :rtype: str """ raise NotImplementedError('Interface method') def define(self, parser): """ Define the arguments for this command. :param argparse.ArgumentParser parser: the argument parser of the command :return: nothing """ raise NotImplementedError('Interface method') def execute(self, args): """ The main method of the command """ raise NotImplementedError('Interface method') PK*H+2 2 gallium/core.py""" Carbon Core ########### :Author: Juti Noppornpitak """ from contextlib import contextmanager from imagination.helper.assembler import Assembler from imagination.helper.data import Transformer from imagination.entity import CallbackProxy from imagination.entity import Entity from imagination.loader import Loader from imagination.locator import Locator class Core(object): """ The Core of the Framework This relies on Imagination Framework. """ def __init__(self, locator=None): self.locator = locator or Locator() self.transformer = Transformer(self.locator) self.assembler = Assembler(self.transformer) self.default_services = [ #('db', 'passerine.db.manager.ManagerFactory', [], {}), ] self.cache_map = None self._register_default_services() @contextmanager def passive_mode(self): self.assembler.activate_passive_loading() yield self.assembler.deactivate_passive_loading() def get(self, id): return self.locator.get(id) def load(self, *paths): with self.passive_mode(): [ self.assembler.load(path) for path in paths ] self.cache_map = None def all(self): if not self.cache_map: self.cache_map = { i: self.locator.get(i) for i in self.locator.entity_identifiers } return self.cache_map def prepare_db_connections(self, db_config): manager_config = db_config['managers'] service_locator = self.container.locator em_factory = service_locator.get('db') for alias in manager_config: url = manager_config[alias]['url'] em_factory.set(alias, url) def callback(em_factory, db_alias): return em_factory.get(db_alias) callback_proxy = CallbackProxy(callback, em_factory, alias) service_locator.set('db.{}'.format(alias), callback_proxy) def _register_default_services(self): for entity_id, package_path, args, kwargs in self.default_services: try: entity = self._create_entity(entity_id, package_path, *args, **kwargs) self.locator.set(entity_id, entity) except ImportError as exception: if entity_id == "db": self.logger.info('Ignored {} as package "passerine" is neither available or loadable (containing errors).'.format(package_path)) continue raise ImportError('Failed to register {} ({})'.format(entity_id, package_path)) def _create_entity(self, id, package_path, *args, **kwargs): loader = Loader(package_path) return Entity(id, loader, *args, **kwargs) PK(*Hgallium/loader/__init__.pyPK(*H"gallium/loader/basic.pyimport importlib import inspect import re from .common import ILoader from ..interface import ICommand class Loader(ILoader): """ The default loader without the integration with the Imagination framework """ def configuration_section_name(self): return 'imports' def all(self, module_paths): for module_path in module_paths: try: module = importlib.import_module(module_path) for cls in self._retrieve_command_classes(module): yield self._logical_group(cls) except ImportError as e: parts = re.split('\.', module_path) alternative_path = '.'.join(parts[:-1]) class_name = parts[-1] if not alternative_path: raise RuntimeError('Unable to import {}'.format(module_path)) module = importlib.import_module(alternative_path) cls = self._get_command_class(module, class_name) yield self._logical_group(cls) def _logical_group(self, cls): cli = cls() return (cli.identifier(), cls, cli) def _retrieve_command_classes(self, module): for property_name in dir(module): if '_' in property_name[0]: continue ClassType = self._get_command_class(module, property_name) if ClassType == ICommand: continue if not inspect.isclass(ClassType): continue if not issubclass(ClassType, ICommand): continue yield ClassType def _get_command_class(self, module, property_name): return eval('module.{}'.format(property_name)) PK(*Hgallium/loader/common.pyclass ILoader(object): def configuration_section_name(self): """ The configuration section name :rtype: str """ raise NotImplemented('Please implement this method.') def all(self, *largs, **kwargs): """ The configuration section name :return: a list or iterator of with a tuple/list of identifier, class type, and class instance. """ raise NotImplemented('Please implement this method.') PK(*H_%%gallium/loader/imagination.pyfrom .common import ILoader from ..interface import ICommand class Loader(object): """ The default loader integrated with the core of the framework. """ def __init__(self, core): self.core = core def configuration_section_name(self): return 'services' def all(self, imagination_config): for identifier in self.core.all(): service = self.core.get(identifier) if not isinstance(service, ICommand): continue yield (identifier, type(service), service) PK]IH^- 'gallium-0.1.7.dist-info/DESCRIPTION.rstUNKNOWN PK]IH5">>%gallium-0.1.7.dist-info/metadata.json{"classifiers": ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries"], "extensions": {"python.details": {"contacts": [{"email": "juti_n@yahoo.co.jp", "name": "Juti Noppornpitak", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/shiroyuki/carbon"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "license": "MIT", "metadata_version": "2.0", "name": "gallium", "run_requires": [{"requires": ["imagination", "kotoba"]}], "summary": "A micro CLI development framework", "version": "0.1.7"}PK]IH1%gallium-0.1.7.dist-info/top_level.txtgallium PK]IHndnngallium-0.1.7.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PK]IHG> gallium-0.1.7.dist-info/METADATAMetadata-Version: 2.0 Name: gallium Version: 0.1.7 Summary: A micro CLI development framework Home-page: https://github.com/shiroyuki/carbon Author: Juti Noppornpitak Author-email: juti_n@yahoo.co.jp License: MIT Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Software Development :: Libraries Requires-Dist: imagination Requires-Dist: kotoba UNKNOWN PK]IH]gallium-0.1.7.dist-info/RECORDgallium/__init__.py,sha256=FUSQPLhzkn6izGi3PrjO3YpdvZyXjb-CYc4J4ZEjwhw,91 gallium/console.py,sha256=Fy5Osbv91WakXBPMAp2pMmyHmylVQHHa0Ew1pSezDqo,2062 gallium/core.py,sha256=hZ_QRh5ApWxMSyAm1iB939Fc9u2wazOuwm_ft_Yg8h0,2866 gallium/interface.py,sha256=pr4OkoymTWhsvK6AlClTa5hW9MYUJAttQ-M0ibwQHao,1172 gallium/starter.py,sha256=52L6XujP2MN9I486ZbvreeK-cKvYTcOhCvVioLiX5Kw,1347 gallium/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 gallium/loader/basic.py,sha256=dSQ561NGiHg0S0IFz4yvCePS8nPSzAdY6WYY74njoV4,1745 gallium/loader/common.py,sha256=eTNtsrmEX9AUpXHKphJHjIVJd8D0r-8exbsGuZdHTNM,471 gallium/loader/imagination.py,sha256=venQGgFgMR-OBVa0GCF6_QdQnRFTSVTmoCVnLVynF70,549 gallium-0.1.7.data/scripts/g2,sha256=gXRxEBHRzo2hPaVoQkdX6rTB-2HWYlA0QFXzhmPMx8s,105 gallium-0.1.7.data/scripts/g3,sha256=gXRxEBHRzo2hPaVoQkdX6rTB-2HWYlA0QFXzhmPMx8s,105 gallium-0.1.7.data/scripts/gallium,sha256=gXRxEBHRzo2hPaVoQkdX6rTB-2HWYlA0QFXzhmPMx8s,105 gallium-0.1.7.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10 gallium-0.1.7.dist-info/METADATA,sha256=5XBK5HFnA8JEQzdWtqmJa4DA4_ViSKmSEwPDgT9yY0Q,685 gallium-0.1.7.dist-info/RECORD,, gallium-0.1.7.dist-info/WHEEL,sha256=GrqQvamwgBV4nLoJe0vhYRSWzWsx7xjlt74FT0SWYfE,110 gallium-0.1.7.dist-info/metadata.json,sha256=swN4CGFshy4ydXVlxcoubmML1sf2ZLhkRaJPF8gi3gI,830 gallium-0.1.7.dist-info/top_level.txt,sha256=EbbByS_UcGb3ewap25_KDDrkOgKr3v_HY3JXr3w-Cuw,8 PK]IH(iigallium-0.1.7.data/scripts/g2PK]IH(iigallium-0.1.7.data/scripts/g3PK]IH(ii"Hgallium-0.1.7.data/scripts/galliumPK+Hs`gallium/console.pyPKIHCC/ gallium/starter.pyPK(*Htc[[gallium/__init__.pyPK(*HR.gallium/interface.pyPK*H+2 2 gallium/core.pyPK(*HS gallium/loader/__init__.pyPK(*H" gallium/loader/basic.pyPK(*H'gallium/loader/common.pyPK(*H_%%)gallium/loader/imagination.pyPK]IH^- '+gallium-0.1.7.dist-info/DESCRIPTION.rstPK]IH5">>%M,gallium-0.1.7.dist-info/metadata.jsonPK]IH1%/gallium-0.1.7.dist-info/top_level.txtPK]IHndnn0gallium-0.1.7.dist-info/WHEELPK]IHG> 0gallium-0.1.7.dist-info/METADATAPK]IH]3gallium-0.1.7.dist-info/RECORDPK$9