Пример #1
0
def checkout_gitsvn(svn_url, location='.'):
    svn_url = svn_url[-1]=='/' and svn_url[:-1] or svn_url
    root_url = svn.get_package_root_url(svn_url)
    if not svn.isdir(svn_url):
        raise svn.InvalidSubversionURL
    expected_dirs = ('trunk', 'tags', 'branches')
    got_dirs = expected_dirs
    try:
        svn.check_project_layout(svn_url)
    except svn.InvalidProjectLayout:
        # check the directories and print a warning
        dircontent = runcmd('svn ls %s' % svn_url, log=False, respond=True)
        dircontent = [x.strip()[:-1] for x in dircontent]
        got_dirs = []
        missing_dirs = []
        for dir in expected_dirs:
            if dir in dircontent:
                got_dirs.append(dir)
            else:
                missing_dirs.append(dir)
                output.warning('Directory %s missing!' % dir)
    package_name = svn.get_package_name(svn_url)
    cache_path = os.path.join(get_gitsvn_cache_path(), package_name)
    if os.path.exists(package_name):
        raise Exception('%s already existing' % os.path.abspath(package_name))
    gitbranch = svnurl_get_gitbranch(svn_url)
    # clone it
    if os.path.exists(cache_path):
        runcmd('cd %s; git reset --hard' % cache_path)
        runcmd('cd %s; git svn fetch' % cache_path)
        runcmd('cd %s; git svn rebase' % cache_path)
    else:
        if got_dirs==expected_dirs:
            # we have a standard layout
            cmd = 'cd %s; git svn clone --stdlayout %s' % (
                get_gitsvn_cache_path(),
                root_url,
                )
        else:
            # some dirs are missing
            args = ['--%s=%s' % (d,d) for d in got_dirs]
            cmd = 'cd %s; git svn clone %s %s' % (
                get_gitsvn_cache_path(),
                ' '.join(args),
                root_url,
                )
        runcmd(cmd)
    runcmd('cp -r %s %s' % (cache_path, location))
    co_path = os.path.join(location, package_name)
    runcmd('cd %s ; git checkout %s' % (
            co_path,
            gitbranch,
            ))
    runcmd('cd %s ; git reset --hard' % co_path)
    runcmd('cd %s ; git svn rebase' % co_path)
Пример #2
0
    def get_svn_url(self, package_name):
        # what's the svn url?
        svn_url = None
        namespace = package_name.split('.')[0]
        # are there already packages checked out with same namespace?
        dirs = [os.path.abspath(d) for d in os.listdir('.')]
        dirs += [os.path.join(git.get_gitsvn_cache_path(), d)
                 for d in os.listdir(git.get_gitsvn_cache_path())]
        for path in dirs:
            dir = os.path.basename(path)
            if dir.startswith('%s.' % namespace):
                try:
                    tmp_url = '/'.join(
                        scm.get_package_root_url(
                            path).split('/')[:-1])
                    if tmp_url and \
                            '%s/' % package_name in svn.listdir(tmp_url):
                        svn_url = os.path.join(tmp_url, package_name, 'trunk')
                        break
                except scm.NotAScm:
                    pass
        if svn_url:
            print ' * found a package under %s' % svn_url
            msg = 'SVN project trunk url [%s]' % \
                output.colorize(svn_url, output.BOLD_WARNING)

            def input_validator(v):
                if not v:
                    return True
                if not svn.isdir(v.strip()):
                    return 'URL not found'
                return True

            url_input = input.prompt(msg, input_validator)
            if url_input:
                svn_url = url_input.strip()
        else:
            msg = 'SVN project trunk url:'

            def input_validator2(v):
                if not v or not svn.isdir(v.strip()):
                    return 'URL not found'
                return True

            url_input = input.prompt(msg, input_validator2)
            svn_url = url_input.strip()
        # check svn layout, give the user a chance to create the dirs
        svn.check_project_layout(svn_url, raise_exception=False)
        return svn_url
Пример #3
0
 def analyse(self):
     output.part_title('Checking subversion project')
     if not scm.is_scm('.'):
         # without subversion or gitsvn it doesnt work...
         output.error('Current directory is not a repository of type svn, '
         'git-svn, git.',
                      exit=True)
     # update newest remote changes
     if scm.is_git('.') or scm.is_git_svn('.'):
         git.pull_changes('.')
         git.push_committed_changes('.')
     elif scm.is_subversion('.'):
         svn.update('.')
     # remote should be there
     if scm.is_git('.') and not scm.is_git_svn('.'):
         if not git.has_remote('origin'):
             output.error('There is no remote "origin", which is needd',
             exit=True)
     # run it at repo root
     if scm.is_subversion('.') or scm.is_git_svn('.'):
         root_svn = scm.get_package_root_url('.')
         if not svn.check_project_layout(root_svn, raise_exception=False,
         ask_for_creation=False):
             # we should have the folders trunk, tags, branches in the project
             output.error('Project does not have default layout with trunk, ' +\
                              'tags and branches. At least one folder is missing.',
                          exit=True)
         if not self.options.release_egg_only:
             here_url = scm.get_svn_url('.')
             here_root = scm.get_package_root_url('.')
             is_trunk = here_url == here_root +'/trunk'
             is_branch = '/'.join(here_url.split('/')[:-1]) == here_root + '/branches'
             if not is_trunk and not is_branch:
                 # command must be run at the "trunk" folder of a package
                 output.error('Please run this command at the root of the package ' +\
                                  '(trunk/branch folder)', exit=True)
     elif scm.is_git('.'):
         if not os.path.exists('.git'):
             output.error('Please run this command at the root of the package ' +\
                              'checkout', exit=True)
     # .. other checks
     if not os.path.isfile('setup.py'):
         # setup.py is required
         output.error('Could not find the file ./setup.py', exit=True)
     if not os.path.isfile('docs/HISTORY.txt'):
         # docs/HISTORY.txt is required
         output.error('Could not find the file ./docs/HISTORY.txt', exit=True)
     if os.path.isfile('setup.cfg'):
         # setup.cfg is not necessary, it should not be used since the development
         # stuff makes bad distribution versions
         output.error('setup.cfg should not be used anymore')
         if input.prompt_bool('Should I delete setup.cfg?'):
             scm.remove_files('setup.cfg')
             scm.commit_files('Removed setup.cfg', 'setup.cfg')
     version_file = os.path.join(scm.get_package_name('.').replace('.', '/'),
                                 'version.txt')
     if not os.path.isfile(version_file):
         # version.txt is required
         output.error('Could not find the file %s' % version_file, exit=True)
     # check MANIFEST.in
     self.check_manifest()
     # check subversion state
     if scm.has_local_changes('.'):
         output.error('You have local changes, please commit them first.',
                      exit=True)