Example #1
0
    def __new__(klass, name, project, which):
        """
        Return the right subclass for kind, if it exists.
        """

        from vcpx import TailorException

        kind = name[:name.index(':')]
        subclass = klass
        subclassname = kind.capitalize() + 'Repository'
        modname = 'vcpx.repository.' + kind
        try:
            concrete = __import__(modname, globals(), locals(), [kind])
            subclass = getattr(concrete, subclassname, klass)
        except SyntaxError, e:
            raise TailorException("Cannot import %r: %s" % (kind, e))
Example #2
0
class Repository(object):
    """
    Collector for the configuration of a single repository.
    """

    METADIR = None
    """
    The name of the "meta" directory used by this kind of repository.
    Subclasses should override this, obviously.
    """

    EXTRA_METADIRS = []
    """
    Other eventual "meta" directories.
    """

    EXECUTABLE = None
    """
    The name of the external command line tool, for some backends.
    """

    EXTRA_RSYNC_FLAGS = None
    """
    Particular flags for rsync, used by disjunct working dirs.
    """

    def __new__(klass, name, project, which):
        """
        Return the right subclass for kind, if it exists.
        """

        from vcpx import TailorException

        kind = name[:name.index(':')]
        subclass = klass
        subclassname = kind.capitalize() + 'Repository'
        modname = 'vcpx.repository.' + kind
        try:
            concrete = __import__(modname, globals(), locals(), [kind])
            subclass = getattr(concrete, subclassname, klass)
        except SyntaxError, e:
            raise TailorException("Cannot import %r: %s" % (kind, e))
        except (AttributeError, ImportError, AssertionError), e:
            raise TailorException("%r is not a known VCS kind: %s" % (kind, e))
Example #3
0
    def workingDir(self):
        """
        Return an instance of the specific WorkingDir for this kind of
        repository.
        """

        from vcpx import TailorException

        try:
            try:
                wdname = self.kind.capitalize() + self.which.capitalize() + 'WorkingDir'
                modname = 'vcpx.repository.' + self.kind + '.' + self.which
                wdmod = __import__(modname, globals(), locals(), [wdname])
                workingdir = getattr(wdmod, wdname)
            except (AttributeError, ImportError), e:
                wdname = self.kind.capitalize() + 'WorkingDir'
                modname = 'vcpx.repository.' + self.kind
                wdmod = __import__(modname, globals(), locals(), [wdname])
                workingdir = getattr(wdmod, wdname)
        except SyntaxError, e:
            self.log.exception("Cannot import %r from %r", wdname, modname)
            raise TailorException("Cannot import %r: %s" % (wdname, e))
Example #4
0
            try:
                wdname = self.kind.capitalize() + self.which.capitalize() + 'WorkingDir'
                modname = 'vcpx.repository.' + self.kind + '.' + self.which
                wdmod = __import__(modname, globals(), locals(), [wdname])
                workingdir = getattr(wdmod, wdname)
            except (AttributeError, ImportError), e:
                wdname = self.kind.capitalize() + 'WorkingDir'
                modname = 'vcpx.repository.' + self.kind
                wdmod = __import__(modname, globals(), locals(), [wdname])
                workingdir = getattr(wdmod, wdname)
        except SyntaxError, e:
            self.log.exception("Cannot import %r from %r", wdname, modname)
            raise TailorException("Cannot import %r: %s" % (wdname, e))
        except (AttributeError, ImportError), e:
            self.log.critical("Cannot import %r from %r", wdname, modname)
            raise TailorException("%r is not a known VCS kind: %s" %
                                  (self.kind, e))

        return workingdir(self)

    def command(self, *args, **kwargs):
        """
        Return the base external command, a sequence suitable to be used
        to init an ExternalCommand instance.

        This return None if the backend uses a different way to execute
        its actions.
        """

        executable = kwargs.get('executable', self.EXECUTABLE)
        if executable:
            cmd = [executable]