PKrnMPbarbacoa/__init__.py# -*- coding: utf-8 -*- """ Asynchronous task manager using asyncio """ import json import os import subprocess import sys import barbacoa.plugins.struct VERSION_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'version.json') GIT_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '.git') def version(v): return tuple(map(int, [num for num in v.replace('-', '.').split('.') if num.isdigit()])) def get_version_data(): if not os.path.isdir(GIT_PATH ): return {'version': '0.0.0'} return {'version': subprocess.run(['git', 'describe'], stdout=subprocess.PIPE).stdout.strip().decode()} def write_version_data(version_data): version_data['version'] = '.'.join(map(str, version(version_data['version']))) with open(VERSION_FILE, 'w') as vfile: json.dump(version_data, vfile) def read_version_data(): with open(VERSION_FILE, 'r') as vfile: version_data = json.load(vfile) return version_data if os.path.isfile(VERSION_FILE): version_data = read_version_data() new_version_data = get_version_data() if version(new_version_data['version']) > version(version_data['version']): write_version_data(new_version_data) version_data = new_version_data else: version_data = get_version_data() write_version_data(version_data) __version__ = version_data['version'] # setup hub hub = barbacoa.plugins.struct.Hub() hub.tools.pack.add('backends') hub.tools.pack.add('storage') hub.tools.pack.add('queues') hub.tools.pack.add('tasks') PKnMJc_barbacoa/version.json{"version": "0.2.1"}PK \Muhbarbacoa/backends/__init__.py# -*- coding: utf-8 -*- PKrnMuhbarbacoa/plugins/__init__.py# -*- coding: utf-8 -*- PKrnMӶbarbacoa/plugins/dirs.pyimport os import importlib try: import pkg_resources except ImportError: HAS_PKGRESOURCES = False else: HAS_PKGRESOURCES = True def dir_list(pypath=None): ret = [] if pypath is None: pypath = [] if isinstance(pypath, str): pypath = pypath.split(',') for path in pypath: try: mod = importlib.import_module(path) ret.append(os.path.dirname(mod.__file__)) except ImportError: if HAS_PKGRESOURCES: for entry in pkg_resources.iter_entry_points('barbacoa.loader', path): ret.append(os.path.dirname(entry.load().__file__)) return ret PKrnMVbarbacoa/plugins/exc.py# -*- coding: utf-8 -*- class PackBaseException(Exception): ''' Base exception where all of Pack's exceptions derive ''' class PackError(PackBaseException): ''' General purpose pack exception to signal an error ''' class PackLoadError(PackBaseException): ''' Exception raised when a pack module fails to load ''' class PackLookupError(PackBaseException): ''' Exception raised when a pack module lookup fails ''' PKrnMBbarbacoa/plugins/loader.py# -*- coding: utf-8 -*- # Import Python Libs import importlib import os def load_mod(modname, path): ''' Attempt to load the named python modules ''' return importlib.machinery.SourceFileLoader(modname, path).load_module() def load_virtual(parent, virtual, mod, bname): base_name = os.path.basename(bname) if '.' in base_name: base_name = base_name.split('.')[0] name = getattr(mod, '__virtualname__', base_name) if not virtual: return {'name': base_name} if not hasattr(mod, '__virtual__'): return {'name': name} ret = mod.__virtual__(parent) if isinstance(ret, tuple): vret, vmsg = ret else: vret, vmsg = ret, 'Failed to load {0}'.format(mod.__name__) if vret is True: return {'name': name} if vret is False: return {'name': base_name, 'vname': name, 'error': vmsg} return {'name': base_name, 'vname': name, 'error': 'Invalid response from __virtual__'} PKrnM?barbacoa/plugins/scanner.py# -*- coding: utf-8 -*- # Import Python Libs import os import collections PY_END = ('.py', '.pyc', '.pyo') SKIP_DIRNAMES = ('__pycache__',) def scan(directories, recurse=False): ''' Return a list of importable files ''' ret = collections.OrderedDict() for dir_ in directories: if recurse: for dir_, dirs_, files in os.walk(dir_): for fn_ in files: _apply_scan(ret, dir_, fn_) ret.update(scan(dirs_, recurse=True)) else: for fn_ in os.listdir(dir_): _apply_scan(ret, dir_, fn_) return ret def _apply_scan(ret, dir_, fn_): ''' Convert the scan data into ''' if fn_.startswith('_'): return if os.path.basename(dir_) in SKIP_DIRNAMES: return full = os.path.join(dir_, fn_) if '.' not in full: return bname = full[:full.rindex('.')] if fn_.endswith(PY_END): ret[bname] = {'path': full} PKrnMdNbarbacoa/plugins/struct.py# -*- coding: utf-8 -*- # Import Python Libs import collections import inspect import os # Import Plugins Libs import barbacoa.plugins.dirs import barbacoa.plugins.exc import barbacoa.plugins.loader import barbacoa.plugins.scanner class Hub(object): context = {} def __init__(self): self._subs = collections.OrderedDict() self._add_subsystem('tools', pypath='barbacoa.plugins.mods.tools') def _add_subsystem(self, modname, subname=None, pypath=None, virtual=True, recurse=False, mod_basename='hub.pack'): subname = subname or modname self._subs[modname] = Pack(self, modname, subname, pypath, virtual, recurse) def _remove_subsystem(self, subname): if subname in self._systems: self._subs.pop(subname) return True return False def __getattr__(self, item): if item.startswith('_'): return self.__getattribute__(item) if item in self._subs: return self._subs[item] return self.__getattribute__(item) def __iter__(self): return iter(self._subs.keys()) @property def _(self): ''' This function allows for hub to pack introspective calls. This should only ever be called from within a hub module, otherwise it should stack trace, or return heaven knows what... ''' dirname = os.path.dirname(inspect.stack()[1].filename) for sub in self._subs: if dirname in self._subs[sub]._dirs: return self._subs[sub] raise barbacoa.plugins.exc.PackLookupError('Called from outside a hub!') class Pack(object): def __init__(self, parent, modname, subname=None, pypath=None, virtual=True, recurse=False, mod_basename='hub.pack'): self._parent = parent self._modname = modname self._subname = subname or modname self._pypath = pypath self._virtual = virtual self._recurse = recurse self._loaded_all = False self._loaded = {} self._vmap = {} self._load_errors = {} self._mod_basename = mod_basename self.__prepare__() def __prepare__(self): self._dirs = barbacoa.plugins.dirs.dir_list(self._pypath or self._subname) self._scan = barbacoa.plugins.scanner.scan(self._dirs, self._recurse) @property def __name__(self): return '{}.{}'.format(self._mod_basename, self._modname) def __iter__(self): if self._loaded_all is False: self._load_all() return iter(self._loaded.values()) def _load_all(self): if self._loaded_all is True: return for bname in self._scan: if self._scan[bname].get('loaded'): continue self._load_item(bname) self._loaded_all = True @property def _(self): fn = inspect.stack()[1].filename vname = self._vmap[fn] return getattr(self, vname.split('.')[-1]) def __getattr__(self, item): if item.startswith('_'): return self.__getattribute__(item) if item in self._loaded: return self._loaded[item] return self._find_mod(item) def __contains__(self, item): try: return hasattr(self, item) except barbacoa.plugins.exc.PackLookupError: return False def _apply_wrapper(self, mod): for func_name, func in inspect.getmembers(mod, inspect.isfunction): if func_name.startswith('_'): continue setattr(mod, func_name, Wrapper(self._parent, func)) self._vmap[mod.__file__] = mod.__name__ return mod def _find_mod(self, item): ''' find the module named item ''' for bname in self._scan: if self._scan[bname].get('loaded'): continue self._load_item(bname) if item in self._loaded: return self._loaded[item] # Let's see if the module being lookup is in the load errors dictionary if item in self._load_errors: # Return the LoadError raise barbacoa.plugins.exc.PackLoadError(self._load_errors[item]) def _load_item(self, bname): mname = '.'.join([self.__name__, os.path.basename(bname).split(".")[0]]) if bname not in self._scan: raise Exception('Bad call to load item: {mname}') mod = barbacoa.plugins.loader.load_mod(mname, self._scan[bname]['path']) vret = barbacoa.plugins.loader.load_virtual(self._parent, self._virtual, mod, bname) if 'error' in vret: self._load_errors[vret['name']] = vret['error'] return self._loaded[vret['name']] = self._apply_wrapper(mod) self._scan[bname]['loaded'] = True class Wrapper(object): def __init__(self, parent, func): self.parent = parent self.func = func self.func_name = func.__name__ self.__name__ = func.__name__ def __call__(self, *args, **kwargs): if args and (args[0] is self.parent or isinstance(args[0], self.parent.__class__)): # The hub(parent) is being passed directly, remove it from args # since we'll inject it further down args = list(args)[1:] args = [self.parent] + list(args) return self.func(*args, **kwargs) def __repr__(self): return '<{} func={}.{}>'.format(self.__class__.__name__, self.func.__module__, self.func_name) PKrnMuh!barbacoa/plugins/mods/__init__.py# -*- coding: utf-8 -*- PKrnMuh'barbacoa/plugins/mods/tools/__init__.py# -*- coding: utf-8 -*- PKrnMW#barbacoa/plugins/mods/tools/loop.py# -*- coding: utf-8 -*- ''' The main interface for management of the aio loop ''' # Import python libs import asyncio import functools __virtualname__ = 'loop' def __virtual__(hub): return True def create(hub): ''' Create the loop at hub.loop.loop ''' if not hasattr(hub.tools, '_loop'): hub.tools._loop = asyncio.get_event_loop() return hub.tools._loop def call_soon(hub, fun, *args, **kwargs): ''' Schedule a coroutine to be called when the loop has time. This needs to be called after the creation fo the loop ''' hub._._.call_soon(functools.partial(fun, *args, **kwargs)) def ensure_future(hub, fun, *args, **kwargs): ''' Schedule a coroutine to be called when the loop has time. This needs to be called after the creation fo the loop ''' asyncio.ensure_future(fun(*args, **kwargs)) def entry(hub): ''' The entry coroutine to start a run forever loop ''' hub._._.create().run_forever() def close(hub): hub._._.create().close() def start(hub, fun, *args, **kwargs): ''' Start a loop that will run until complete ''' return hub._._.create().run_until_complete(fun(*args, **kwargs)) PKrnM#barbacoa/plugins/mods/tools/pack.py# -*- coding: utf-8 -*- ''' Control and add subsystems to the running hub ''' # pylint: disable=protected-access def add(hub, modname, **kwargs): ''' Add a new subsystem to the hub ''' # Make sure that unintended funcs are not called with the init if kwargs.get('init') is True: kwargs['init'] = 'init.new' hub._add_subsystem(modname, **kwargs) def remove(hub, packname): ''' Remove a pack from the hub, run the shutdown if needed ''' if hasattr(hub, packname): hub._remove_subsystem(packname) def load_all(hub, packname): ''' Load al modules under a given pack ''' if hasattr(hub, packname): pack = getattr(hub, packname) pack._load_all() return True else: return False PKrnM[ii%barbacoa/plugins/mods/tools/pinger.pydef tools_test(hub): return hub.tools.test.ping() def this_test(hub): return hub._.test.ping() PKrnM l#barbacoa/plugins/mods/tools/test.pydef ping(hub): return True def this_this(hub): return hub._._.ping() def tools_this(hub): return hub.tools._.ping() PK7Muhbarbacoa/queues/__init__.py# -*- coding: utf-8 -*- PK7Muhbarbacoa/storage/__init__.py# -*- coding: utf-8 -*- PK7Muhbarbacoa/tasks/__init__.py# -*- coding: utf-8 -*- PK!Hn @s)barbacoa-0.2.1.dist-info/entry_points.txtNJ,JJLOOLI-SRm20T$ $(1=!*I,FRrqPK~M]{],], barbacoa-0.2.1.dist-info/LICENSE Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. PK!Hd BUcbarbacoa-0.2.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!H !barbacoa-0.2.1.dist-info/METADATAoo0S>-ѤE$&J[Ay{IEl\oϹ*Rgbl1F>hg]gk4B_a0;kfI-1GEmyg] ~A-yA0e|AA<5XjgeC_[lz[gEyKzacMpNu9-K {OMJ-z A5My0xw&݋뎠t{ֻ֣16J;ɻ {Nofo/v~!SCddYPאöGk%-=- !;&eL&[k=U$kn$+dmʾJ8ܠ$ӣ5Ώ,(G$^ :UdhS'Y02e,9*[>Fл$(H7PK!H]@}barbacoa-0.2.1.dist-info/RECORDK:p, `rGP $@Xq{ճW7; FQ Ef57LΦQzYRӲa_H<6/S,̏;vO;\ 8+1naO[xRׂM7i(F*IVNq/x\v>= Kh:4*^so6U𯐗/cFAf@x[`9m5t, 6m A K if]^Є}H /ȱx^"j. ŗ{-#JM(y=>[Hpդ}|BI"QI o\t sЂ iFk^;| L7$?"VtBl_Z=9ۜ0흭 ns.62`?5;W5/apwzK4ǍqbjT1/^l|oY띔}uaԞׯĮФ".`[pv)מZWYxhaAqV'=F|VEvI릅f1@š1ʥYb>o}@LPw$ƷH33n.&t33Ȼ_nxjd6o VLe쵵|wwf>XP*Z(q;`쫲w{|m+k(]r{sdSl=}u)IegY:\= o։q5C)4 UJAk-y}6PKrnMPbarbacoa/__init__.pyPKnMJc_@barbacoa/version.jsonPK \Muhbarbacoa/backends/__init__.pyPKrnMuhbarbacoa/plugins/__init__.pyPKrnMӶ,barbacoa/plugins/dirs.pyPKrnMV barbacoa/plugins/exc.pyPKrnMB barbacoa/plugins/loader.pyPKrnM?barbacoa/plugins/scanner.pyPKrnMdN#barbacoa/plugins/struct.pyPKrnMuh! *barbacoa/plugins/mods/__init__.pyPKrnMuh'a*barbacoa/plugins/mods/tools/__init__.pyPKrnMW#*barbacoa/plugins/mods/tools/loop.pyPKrnM#/barbacoa/plugins/mods/tools/pack.pyPKrnM[ii%3barbacoa/plugins/mods/tools/pinger.pyPKrnM l#3barbacoa/plugins/mods/tools/test.pyPK7Muhy4barbacoa/queues/__init__.pyPK7Muh4barbacoa/storage/__init__.pyPK7Muh5barbacoa/tasks/__init__.pyPK!Hn @s)l5barbacoa-0.2.1.dist-info/entry_points.txtPK~M]{],], 5barbacoa-0.2.1.dist-info/LICENSEPK!Hd BUcbbarbacoa-0.2.1.dist-info/WHEELPK!H !cbarbacoa-0.2.1.dist-info/METADATAPK!H]@}ebarbacoa-0.2.1.dist-info/RECORDPKh