Example #1
0
    def _regenerate(self, treanttype, treant):
        """Re-generate existing Treant object.

        """
        self._placeholders()

        # convenient to give only name of object (its directory name)
        if os.path.isdir(treant):
            statefile = filesystem.glob_treant(treant)

            # if only one state file, load it; otherwise, complain loudly
            if len(statefile) == 1:
                self._backend = persistence.treantfile(
                        statefile[0])
            elif len(statefile) == 0:
                raise NoTreantsError('No Treants found in directory.')
            else:
                raise MultipleTreantsError('Multiple Treants found in '
                                           'directory. Give path to a '
                                           'specific state file.')

        # if a state file is given, try loading it
        elif os.path.exists(treant):
            self._backend = persistence.treantfile(treant)

        self._start_logger(treanttype, self.name)
        self._backend._start_logger(self._logger)

        self._placeholders()
Example #2
0
    def _generate(self, treanttype, treant, location='.',
                  coordinator=None, categories=None, tags=None):
        """Generate new generic Treant object.

        """
        self._placeholders()

        # process keywords
        if not categories:
            categories = dict()
        if not tags:
            tags = list()

        # generate state file
        # TODO: need try, except for case where Treant already exists

        # TODO: need to raise exception where invalid characters used for
        # directory
        os.makedirs(os.path.join(location, treant))
        filename = filesystem.statefilename(treanttype, str(uuid4()))

        statefile = os.path.join(location, treant, filename)
        self._start_logger(treanttype, treant)

        self._backend = persistence.treantfile(
                statefile, self._logger, name=treant,
                coordinator=coordinator, categories=categories, tags=tags)