Exemplo n.º 1
0
def CreateConfig(config_file='.mu_repo'):
    if config_file is None:  # Mostly for testing.
        contents = ''
    else:
        exists = os.path.exists(config_file)
        if not exists:
            contents = ''
        else:
            with open(config_file, 'r') as f:
                contents = f.read()

    return Config.Create(contents)
Exemplo n.º 2
0
def test_mu_repo():
    contents = '''
    repo=pydev
    repo=studio3
    repo=python-devel
    repo=django
    current_group=pydev-devel
    group=pydev-devel, pydev, studio3
    '''
    config = Config.Create(contents)
    expected_config = mu_repo.Config(
        repos=['pydev', 'studio3', 'python-devel', 'django'],
        current_group='pydev-devel',
        groups={'pydev-devel': ['pydev', 'studio3']},
    )
    assert config == expected_config
Exemplo n.º 3
0
def main(config_file='.mu_repo', args=None):
    '''
    Entry point.
    '''

    if args is None:
        args = sys.argv[1:]

    if len(args) == 0 or (len(args) == 1 and args[0] in ('help', '--help')):
        from string import Template
        from . import __docs__
        msg = __docs__.__doc__ #@UndefinedVariable
        Print(msg)
        return Status(msg, False)

    if config_file is None: #Mostly for testing.
        contents = ''
    else:
        exists = os.path.exists(config_file)
        if not exists:
            contents = ''
        else:
            with open(config_file, 'r') as f:
                contents = f.read()

    config = Config.Create(contents)

    for arg in args:
        if arg.startswith('repo:'):
            args.remove(arg)
            config.repos = arg[len('repo:'):].replace(';', ',').split(',')
            if not args:
                Print('"repo" specified, but no additional args given.')
                return

        elif arg.startswith('repos:'):
            args.remove(arg)
            config.repos = arg[len('repos:'):].replace(';', ',').split(',')
            if not args:
                Print('"repos" specified, but no additional args given.')
                return

        elif arg == '--help':
            #On a help command, don't execute in multiple repos.
            config.repos = ['.']
            break

    else:
        if not config.repos:
            if '.' == args[0]:
                del args[0]
                config.repos.append('.')
            elif os.path.exists('.git'):
                #Allow it to be used on single git repos too.
                config.repos.append('.')


    arg0 = args[0]
    change_to_serial_if_possible = True
    update_repos_from_groups = True

    Run = None

    # actions related to repos or mu itself --------------------------------------------------------
    # This should be executed first, because some of them expect to see config as it was loaded
    if arg0 == 'set-var':
        from .action_set_var import Run #@Reimport
        change_to_serial_if_possible = False
        update_repos_from_groups = False

    elif arg0 == 'get-vars':
        from .action_get_vars import Run #@Reimport
        change_to_serial_if_possible = False

    elif arg0 == 'auto-update':
        from .action_auto_update import Run #@Reimport

    elif arg0 == 'list':
        from .action_list import Run #@Reimport

    elif arg0 == 'register':
        from .action_register import Run #@Reimport
        update_repos_from_groups = False
        
    elif arg0 == 'unregister':
        from .action_unregister import Run #@Reimport
        update_repos_from_groups = False
        
    elif arg0 == 'group':
        from .action_group import Run #@Reimport
        update_repos_from_groups = False

    # change global repos list to the current group, if any
    if update_repos_from_groups:
        group_repos = config.groups.get(config.current_group, None)
        if group_repos is not None:
            config.repos = group_repos

    # acp variants ---------------------------------------------------------------------------------
    if arg0 == 'acp': #Add, commit, push
        def Run(params):
            from .action_add_commit_push import Run #@Reimport
            Run(params, add=True, commit=True, push=True)

    elif arg0 == 'ac': #Add, commit
        def Run(params):
            from .action_add_commit_push import Run #@Reimport
            Run(params, add=True, commit=True, push=False)

    elif arg0 == 'a': #Add
        def Run(params):
            from .action_add_commit_push import Run #@Reimport
            Run(params, add=True, commit=False, push=False)

    elif arg0 == 'c': #Commit
        def Run(params):
            from .action_add_commit_push import Run #@Reimport
            Run(params, add=False, commit=True, push=False)

    elif arg0 == 'p': #Push
        def Run(params):
            from .action_add_commit_push import Run #@Reimport
            Run(params, add=False, commit=False, push=True)




    # related to git actions -----------------------------------------------------------------------
    elif arg0 == 'dd':
        from .action_diff import Run #@Reimport

    elif arg0 == 'up':
        from .action_up import Run #@Reimport

    elif arg0 in ('sync', 'upd'):
        from .action_sync import Run #@Reimport

    elif arg0 == 'st': #Concise status message (branch, changes)
        from .action_st import Run #@Reimport

    elif arg0 == 'rb': #Rebase current_branch origin/current_branch
        from .action_rebase import Run #@Reimport


    # assorted -------------------------------------------------------------------------------------
    elif arg0 == 'install':
        from .action_install import Run #@Reimport

    elif arg0 == 'mu-patch':
        from .action_mu_patch import Run #@Reimport

    elif arg0 == 'post-review':
        from .action_post_review import Run #@Reimport

    elif arg0 == 'fix-eol':
        from .action_fix_eol import Run #@Reimport

    elif arg0 == 'github-request':
        from .action_github_pull_request import Run #@Reimport

    elif arg0 == 'howto':
        from .howto import Run #@Reimport

    elif arg0 == 'shell':
        import subprocess
        try:
            subprocess.call(['sh', '--login', '-i'])
        except:
            #Ignore any error here (if the user pressed Ctrl+C before exit, we'd have an exception).
            import traceback;traceback.print_exc()
        return


    # default action -------------------------------------------------------------------------------
    if Run is None:
        if arg0 == 'stash' and len(args) == 1:
            #Fixing stash: if git stash is provided without arguments, append a '-u' so that it
            #also stashes untracked files.
            args.append('-u')

        from .action_default import Run #@Reimport

    if change_to_serial_if_possible:
        if len(config.repos) == 1:
            config.serial = True

    return Run(Params(config, args, config_file))