コード例 #1
0
ファイル: branch.py プロジェクト: neuroidss/timeflux
    def load(self, graph):
        """Initialize the graph.

        Args:
            graph (dict): The graph.

        """
        try:
            validate(graph, 'graph')
        except:
            raise ValueError('Invalid branch')
        worker = Worker(graph)
        path, nodes = worker.load()
        self._scheduler = Scheduler(path, nodes, 0)
コード例 #2
0
ファイル: manager.py プロジェクト: vijpandaturtle/timeflux
    def __init__(self, config):
        """Load configuration

        Args:
            config (string|dict): The configuration can either be a path to a YAML or JSON file or a dict.

        """

        # Initialize logger
        self.logger = logging.getLogger(__name__)

        # Hold the names of the imported applications
        self._imports = []

        # Hold the graphs
        self._graphs = []

        # Hold the children processes
        self._processes = []

        # Load application
        if isinstance(config, dict):
            app = config
            path = os.getcwd()
        elif isinstance(config, str):
            app = self._load_file(config)
            self._imports.append(os.path.abspath(config))
            path = os.path.dirname(self._imports[0])
        else:
            raise ValueError("Could not load application file")

        # Validate
        validate(app)

        # Populate the graph list
        if "graphs" in app:
            self._graphs = app["graphs"]

        # Import sub applications
        self._import(app, path)

        # Update the search path
        for app in self._imports:
            path = os.path.dirname(app)
            if path not in sys.path:
                sys.path.append(path)
コード例 #3
0
ファイル: manager.py プロジェクト: vijpandaturtle/timeflux
 def _import(self, app, path):
     if not "import" in app:
         return
     old_path = os.getcwd()
     os.chdir(path)
     for filename in app["import"]:
         filename = os.path.abspath(filename)
         if filename in self._imports:
             self.logger.debug("Application %s will not be loaded twice", filename)
             continue
         self.logger.debug("Importing %s", filename)
         self._imports.append(filename)
         sub = self._load_file(filename)
         try:
             validate(sub)
         except ValueError as error:
             raise ValueError(f"Validation failed ({filename})")
         if "graphs" in sub:
             self._graphs += sub["graphs"]
         self._import(sub, os.path.dirname(filename))
     os.chdir(old_path)