예제 #1
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)
예제 #2
0
    def _new_uuid(self):
        """Generate new uuid for Treant.

        *Warning*: A Treant's uuid is used by Groups to identify whether or
        not it is a member. Any Groups a Treant is a part of will cease
        to recognize it when changed.

        """
        new_id = str(uuid4())
        oldfile = self._backend.filename
        olddir = os.path.dirname(self._backend.filename)
        newfile = os.path.join(olddir,
                               filesystem.statefilename(
                                   self.treanttype, uuid))
        os.rename(oldfile, newfile)
        self._regenerate(self.treanttype, olddir)
예제 #3
0
    def location(self, value):
        """Set location of Treant.

        Physically moves the Treant to the given location.
        Only works if the new location is an empty or nonexistent
        directory.

        """
        self._makedirs(value)
        oldpath = self._backend.get_location()
        newpath = os.path.join(value, self.name)
        statefile = os.path.join(newpath,
                                 filesystem.statefilename(
                                     self.treanttype, self.uuid))
        os.rename(oldpath, newpath)
        self._regenerate(self.treanttype, statefile)
예제 #4
0
    def name(self, name):
        """The name of the Treant.

        The name of a Treant need not be unique with respect to other
        Treants, but is used as part of Treant's displayed
        representation.

        """
        olddir = os.path.dirname(self._backend.filename)
        newdir = os.path.join(os.path.dirname(olddir), name)
        statefile = os.path.join(newdir,
                                 filesystem.statefilename(
                                     self.treanttype, self.uuid))

        os.rename(olddir, newdir)
        self._regenerate(self.treanttype, statefile)