コード例 #1
0
ファイル: admin.py プロジェクト: picsldev/zual
def load():
    ldr = AddonLoader(verbose=True,
                      logger=app.logger,
                      recursive=False,
                      lazy_load=False)
    ldr.set_addon_dirs([os.path.join(BASE_DIR, app.config['DASHBOARD_MODS'])])
    ldr.set_addon_methods(['execute', 'template', 'get_data', 'name'])
    ldr.load_addons()
    return ldr, ldr.get_loaded_addons(list_all=True)
コード例 #2
0
 def start(self):
     self.curr_dir = os.path.abspath('.')
     print("Starting activity in module " + __name__ + "from dir " + self.curr_dir)
     print("Lets call another addon from here ... 'PingAddon'")
     plol = AddonLoader.get_loaded_addon_instance('PingAddon')
     if plol is not None:
         plol.start()
コード例 #3
0
 def start(self):
     self.curr_dir = os.path.abspath('.')
     print("Starting activity in module " + __name__ + "from dir " +
           self.curr_dir)
     print("Lets call another addon from here ... 'PingAddon'")
     plol = AddonLoader.get_loaded_addon_instance('PingAddon')
     if plol is not None:
         plol.start()
コード例 #4
0
ファイル: algoexpy.py プロジェクト: ninadmhatre/pylrn
 def load(self, verbose_flag):
     """
     Load algorithms using addonpy module
     :param verbose_flag: make it verbose?
     """
     self.loader = AddonLoader(verbose=verbose_flag, recursive=True)
     self.loader.set_addon_methods(["execute", "info", "logic", "info_online", "show_code", "__addon__"])
     self.loader.set_addon_dirs(self.search_dirs)
     self.loader.load_addons()
コード例 #5
0
ファイル: BucketSortAddon.py プロジェクト: ninadmhatre/pylrn
    def logic(self, data, output=True, reverse=False, very_verbose=False):
        """
        Algorithm logic
        :param data: Array to be sorted
        :param output: Show output or not
        :param reverse: Sort in reverse
        :return: Sorted array
        """
        count = len(data)

        bucket_list = [list() for _ in range(count)]
        biggest = data[0]
        for i in range(1, count):
            if biggest < data[i]:
                biggest = data[i]

        divisor = self.divide_to_get_int(biggest, count, to_floor=False)

        for idx in range(count):
            self.loop_count += 1
            new_idx = self._get_index(data[idx], divisor)
            bucket_list[new_idx].append(data[idx])

        #
        # Assuming insertion sort is already loaded..
        #

        insertion_sort = AddonLoader.get_loaded_addon_instance("InsertionSortAddon")

        j = 0
        if reverse:
            first = len(bucket_list) - 1
            last = -1
            step = -1
        else:
            first = 0
            last = len(bucket_list)
            step = 1

        for b_idx in range(first, last, step):
            if insertion_sort is not None:
                insertion_sort.execute(bucket_list[b_idx], reverse=reverse, output=False, very_verbose=False)
            else:
                bucket_list[b_idx].sort(reverse=reverse)

            for i in range(len(bucket_list[b_idx])):
                data[j] = bucket_list[b_idx][i]
                j += 1

        return data
コード例 #6
0
    def test_get_loaded_addon_instance(self):
        # addon_loader = AddonLoader(verbose, logger, recursive, lazy_load)
        # self.assertEqual(expected, addon_loader.get_loaded_addon_instance())
        """
        test to check if addons loaded can load/call another addons. static method call
        which gets other addons instances
        """

        from addonpy.addonpy import AddonLoader
        expected_name = 'CommandLineAddon'
        expected_version = '1.0.5'

        actual = AddonLoader.get_loaded_addon_instance('CommandLineAddon')
        self.assertEqual(expected_name, actual.get_name())
        self.assertEqual(expected_version, actual.get_version())
コード例 #7
0
ファイル: test_addonpy.py プロジェクト: ninadmhatre/addonpy
    def test_get_loaded_addon_instance(self):
        # addon_loader = AddonLoader(verbose, logger, recursive, lazy_load)
        # self.assertEqual(expected, addon_loader.get_loaded_addon_instance())
        """
        test to check if addons loaded can load/call another addons. static method call
        which gets other addons instances
        """

        from addonpy.addonpy import AddonLoader
        expected_name = 'CommandLineAddon'
        expected_version = '1.0.5'

        actual = AddonLoader.get_loaded_addon_instance('CommandLineAddon')
        self.assertEqual(expected_name, actual.get_name())
        self.assertEqual(expected_version, actual.get_version())
コード例 #8
0
ファイル: algoexpy.py プロジェクト: ninadmhatre/pylrn
class AlgorithmsDemo(object):
    def __init__(self):
        self.loader = None
        self.search_dirs = list()
        self.search_dirs.append(os.path.curdir)

    def add_search_dirs(self, search_dirs):
        """
        Append to existing search locations
        :param search_dirs: list of additional search locations
        """
        [self.search_dirs.append(_dir) for _dir in search_dirs if os.path.isdir(_dir)]

    def load(self, verbose_flag):
        """
        Load algorithms using addonpy module
        :param verbose_flag: make it verbose?
        """
        self.loader = AddonLoader(verbose=verbose_flag, recursive=True)
        self.loader.set_addon_methods(["execute", "info", "logic", "info_online", "show_code", "__addon__"])
        self.loader.set_addon_dirs(self.search_dirs)
        self.loader.load_addons()

    def get_instance(self, algorithm):
        """
        Get instance of addon by name
        :param algorithm: name of addon / algorithm
        :return: instance of algorithm addon
        """
        if not algorithm.endswith("Addon"):
            algorithm += "Addon"
        return self.loader.get_instance(algorithm)

    def list_all_algorithms(self, by_type=None):
        if by_type is None:
            [print(_addon) for _addon in self.loader.get_loaded_addons(list_all=True)]
        else:
            [print(_addon) for _addon in self.loader.get_loaded_addons(by_type=by_type)]
コード例 #9
0
    def test_no_extension_load(self):
        # addon_loader = AddonLoader(verbose, logger, recursive, lazy_load)
        # self.assertEqual(expected, addon_loader.get_loaded_addon_instance())
        """
        test to check if addons loaded can load/call another addons. static method call
        which gets other addons instances
        """

        from addonpy.addonpy import AddonLoader
        expected_name = 'CommandLine'
        expected_version = '1.0.5'

        self.load_mgr.set_addon_methods(['execute_user', 'start_user', 'stop_user'])
        self.load_mgr.set_addon_identifier(None, ignore_suffix=True)
        self.load_mgr.load_addons()

        actual = AddonLoader.get_loaded_addon_instance('CommandLine', "")
        self.assertEqual(expected_name, actual.get_name())
        self.assertEqual(expected_version, actual.get_version())

        expected = 1
        actual = len(self.load_mgr.get_loaded_addons(by_type='Type-2'))
        self.assertEqual(expected, actual)
コード例 #10
0
ファイル: admin.py プロジェクト: Msms-NJ/zual
def load():
    ldr = AddonLoader(verbose=True, logger=app.logger, recursive=False, lazy_load=False)
    ldr.set_addon_dirs([os.path.join(BASE_DIR, app.config['DASHBOARD_MODS'])])
    ldr.set_addon_methods(['execute', 'template', 'get_data', 'name'])
    ldr.load_addons()
    return ldr, ldr.get_loaded_addons(list_all=True)