示例#1
0
    def create(cls, location, metadata=None, config=None):
        """ Create a new Workflow.

        :param location:    Base directory that the workflow should be created
                            in
        :type location:     unicode or :py:class:`pathlib.Path`
        :param metadata:    Initial metadata for workflow. Must at least
                            contain a `title` item.
        :type metadata:     dict
        :param config:      Initial configuration for workflow
        :type config:       dict or :py:class:`spreads.config.Configuration`
        :return:            The new instance
        :rtype:             :py:class:`Workflow`
        """
        if not isinstance(location, Path):
            location = Path(location)
        if metadata is None or 'title' not in metadata:
            raise ValidationError(
                metadata={'title': 'Please specify at least a title'})
        path = Path(location/util.slugify(metadata['title']))
        if path.exists():
            raise ValidationError(
                name="A workflow with that title already exists")
        wf = cls(path=path, config=config, metadata=metadata)
        return wf
示例#2
0
    def create(cls, location, metadata=None, config=None):
        """ Create a new Workflow.

        :param location:    Base directory that the workflow should be created
                            in
        :type location:     unicode or :py:class:`pathlib.Path`
        :param metadata:    Initial metadata for workflow. Must at least
                            contain a `title` item.
        :type metadata:     dict
        :param config:      Initial configuration for workflow
        :type config:       dict or :py:class:`spreads.config.Configuration`
        :return:            The new instance
        :rtype:             :py:class:`Workflow`
        """
        if not isinstance(location, Path):
            location = Path(location)
        if metadata is None or 'title' not in metadata:
            raise ValidationError(
                metadata={'title': 'Please specify at least a title'})
        path = Path(location/util.slugify(metadata['title']))
        if path.exists():
            raise ValidationError(
                name="A workflow with that title already exists")
        wf = cls(path=path, config=config, metadata=metadata)
        return wf
示例#3
0
    def __init__(self, path, config=None, metadata=None):
        self._logger = logging.getLogger('Workflow')
        self._logger.debug("Initializing workflow {0}".format(path))
        self.status = {
            'step': None,
            'step_progress': None,
            'prepared': False
        }
        if not isinstance(path, Path):
            path = Path(path)
        self.path = path
        is_new = not self.path.exists()
        try:
            self.bag = bagit.Bag(unicode(self.path))
        except bagit.BagError:
            # Convert non-bagit directories from older versions
            self.bag = bagit.Bag.convert_directory(unicode(self.path))
        if not self.slug:
            self.slug = util.slugify(unicode(self.path.name))
        if not self.id:
            self.id = unicode(uuid.uuid4())
        # See if supplied `config` is already a valid ConfigView object
        if isinstance(config, confit.ConfigView):
            self.config = config
        elif isinstance(config, Configuration):
            self.config = config.as_view()
        else:
            self.config = self._load_config(config)
        self._metadata = Metadata(self.path)

        if metadata:
            self.metadata = metadata

        self._capture_lock = threading.RLock()
        self._devices = None
        self._pluginmanager = None
        self._threadpool = concfut.ThreadPoolExecutor(max_workers=1)
        self._pending_tasks = []

        # Filter out subcommand plugins, since these are not workflow-specific
        plugin_classes = [
            (name, cls)
            for name, cls in plugin.get_plugins(*self.config["plugins"]
                                                .get()).iteritems()
            if not cls.__bases__ == (plugin.SubcommandHookMixin,)]
        self.plugins = [cls(self.config) for name, cls in plugin_classes]
        self.config['plugins'] = [name for name, cls in plugin_classes]

        # Save configuration
        self._save_config()

        self.pages = self._load_pages()
        self.table_of_contents = self.load_toc()

        if is_new:
            on_created.send(self, workflow=self)
示例#4
0
 def create(cls, location, metadata=None, config=None):
     if not isinstance(location, Path):
         location = Path(location)
     if metadata is None or not 'title' in metadata:
         raise ValidationError(
             metadata={'title': 'Please specify at least a title'})
     path = Path(location/util.slugify(metadata['title']))
     if path.exists():
         raise ValidationError(
             name="A workflow with that title already exists")
     wf = cls(path=path, config=config, metadata=metadata)
     return wf
示例#5
0
    def __init__(self, path, config=None, metadata=None):
        self._logger = logging.getLogger('Workflow')
        self._logger.debug("Initializing workflow {0}".format(path))
        self.status = {'step': None, 'step_progress': None, 'prepared': False}
        if not isinstance(path, Path):
            path = Path(path)
        self.path = path
        is_new = not self.path.exists()
        try:
            self.bag = bagit.Bag(unicode(self.path))
        except bagit.BagError:
            # Convert non-bagit directories from older versions
            self.bag = bagit.Bag.convert_directory(unicode(self.path))
        if not self.slug:
            self.slug = util.slugify(unicode(self.path.name))
        if not self.id:
            self.id = unicode(uuid.uuid4())
        # See if supplied `config` is already a valid ConfigView object
        if isinstance(config, confit.ConfigView):
            self.config = config
        elif isinstance(config, Configuration):
            self.config = config.as_view()
        else:
            self.config = self._load_config(config)
        if metadata:
            self.metadata = metadata
        self._capture_lock = threading.RLock()
        self._devices = None
        self._pluginmanager = None
        self._pool_executor = None

        # Filter out subcommand plugins, since these are not workflow-specific
        plugin_classes = [
            (name, cls) for name, cls in plugin.get_plugins(
                *self.config["plugins"].get()).iteritems()
            if not cls.__bases__ == (plugin.SubcommandHookMixin, )
        ]
        self.plugins = [cls(self.config) for name, cls in plugin_classes]
        self.config['plugins'] = [name for name, cls in plugin_classes]

        # Save configuration
        self._save_config()

        self.pages = self._load_pages()
        self.table_of_contents = self.load_toc()

        if is_new:
            on_created.send(self, workflow=self)
示例#6
0
    def __init__(self, path, config=None, metadata=None):
        self._logger = logging.getLogger('Workflow')
        self._logger.debug("Initializing workflow {0}".format(path))

        self.status = {
            'step': None,
            'step_progress': None,
            'prepared': False
        }
        if not isinstance(path, Path):
            path = Path(path)
        self.path = path
        is_new = not self.path.exists()
        try:
            self.bag = bagit.Bag(unicode(self.path))
        except bagit.BagError:
            # Convert non-bagit directories from older versions
            self.bag = bagit.Bag.convert_directory(unicode(self.path))
        if not self.slug:
            self.slug = util.slugify(unicode(self.path.name))
        if not self.id:
            self.id = unicode(uuid.uuid4())
        # See if supplied `config` is already a valid ConfigView object
        if isinstance(config, confit.ConfigView):
            self.config = config
        elif isinstance(config, Configuration):
            self.config = config.as_view()
        else:
            self.config = self._load_config(config)
        #: :py:class:`spreads.metadata.Metadata` instance that backs the
        #: corresponding getter and setter
        self._metadata = Metadata(self.path)

        # This will invoke the setter
        if metadata:
            self.metadata = metadata

        #: Lock that is held when a shot is being executed during the capture
        #: phase
        self._capture_lock = threading.RLock()
        #: List of :py:class:`spreads.plugin.DeviceDriver` instances that
        #: backs the corresponding getters and setters
        self._devices = None
        # Thread pool for background tasks
        self._threadpool = concfut.ThreadPoolExecutor(max_workers=1)
        # List of unfinished :py:class:`concurrent.futures.Future` instances
        self._pending_tasks = []

        # Filter out subcommand plugins, since these are not workflow-specific
        plugin_classes = [
            (name, cls)
            for name, cls in plugin.get_plugins(*self.config["plugins"]
                                                .get()).iteritems()
            if not cls.__bases__ == (plugin.SubcommandHooksMixin,)]
        self._plugins = [cls(self.config) for name, cls in plugin_classes]
        self.config['plugins'] = [name for name, cls in plugin_classes]
        self._save_config()

        self.pages = self._load_pages()
        self.table_of_contents = self._load_toc()

        if is_new:
            on_created.send(self, workflow=self)
示例#7
0
    def __init__(self, path, config=None, metadata=None):
        self._logger = logging.getLogger('Workflow')
        self._logger.debug("Initializing workflow {0}".format(path))

        self.status = {
            'step': None,
            'step_progress': None,
            'prepared': False
        }
        if not isinstance(path, Path):
            path = Path(path)
        self.path = path
        is_new = not self.path.exists()

        # See if supplied `config` is already a valid ConfigView object
        if isinstance(config, confit.ConfigView):
            self.config = config
        elif isinstance(config, Configuration):
            self.config = config.as_view()
        else:
            self.config = self._load_config(config)

        try:
            self.bag = bagit.Bag(unicode(self.path))
        except bagit.BagError:
            if self.config['core']['convert_old'].get(bool):
                # Convert non-bagit directories from older versions
                self.bag = bagit.Bag.convert_directory(unicode(self.path))
                self.pages = [Page(img)
                              for img in (self.path/'data'/'raw').iterdir()]
                self._save_pages()
            else:
                raise bagit.BagError(
                    "Specified workflow directory is not structured according "
                    "to BagIt convertions and automatic conversion has been "
                    "disabled (check `convert_old` setting)")
        if not self.slug:
            self.slug = util.slugify(unicode(self.path.name))
        if not self.id:
            self.id = unicode(uuid.uuid4())
        #: :py:class:`spreads.metadata.Metadata` instance that backs the
        #: corresponding getter and setter
        self._metadata = Metadata(self.path)

        # This will invoke the setter
        if metadata:
            self.metadata = metadata

        #: Lock that is held when a shot is being executed during the capture
        #: phase
        self._capture_lock = threading.RLock()
        #: List of :py:class:`spreads.plugin.DeviceDriver` instances that
        #: backs the corresponding getters and setters
        self._devices = None
        # Thread pool for background tasks
        self._threadpool = concfut.ThreadPoolExecutor(max_workers=1)
        # List of unfinished :py:class:`concurrent.futures.Future` instances
        self._pending_tasks = []

        # Filter out subcommand plugins, since these are not workflow-specific
        plugin_classes = [
            (name, cls)
            for name, cls in plugin.get_plugins(*self.config["plugins"]
                                                .get()).iteritems()
            if not cls.__bases__ == (plugin.SubcommandHooksMixin,)]
        self._plugins = [cls(self.config) for name, cls in plugin_classes]
        self.config['plugins'] = [name for name, cls in plugin_classes]
        self._save_config()

        self.pages = self._load_pages()
        self.table_of_contents = self._load_toc()

        if is_new:
            on_created.send(self, workflow=self)