示例#1
0
def download(args):
    """Download/sync/update from remote repositories/places to local repositories / working trees."""

    point = ""
    if len(args) == 0:
        pass
    elif len(args) > 1:
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        download_usage()
        sys.exit(2)
    elif args[0] in ('-h', "--help"):
        download_usage()
        sys.exit()
    elif args[0][0] == '-':
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        download_usage()
        sys.exit(2)
    else:
        point = args[0]

    root = common.get_root()
    git.get_cmg_cfg(root)
    print("---- " + root)
    
    if common.cfgs['online']:
        git.fetch(root)
    else:
        print("Warning: CMG is running under offline mode. No interaction with remote.")
    
    local = remote = tag = ""
    if point == "":
        (local, remote) = git.get_current_br_pair(root)
        if local == "":
            sys.stderr.write("Failed: it's not on a local branch "\
                + "that follow a remote-tracking branch")
            sys.exit(2)
    else:
        if git.is_local_br(root, point):
            local = point
            remote = git.get_remote_br_via_local(root, local)
            if remote == "":
                sys.stderr.write("Failed: can not find local branch "\
                    + local + "'s remote-tracking branch\n")
                sys.exit(2)
        elif git.is_local_br_to_create(root, point):
            local = git.create_default_local_br(root, point)
            remote = "origin/" + local
        elif git.is_remote_br(root, point):
            remote = point
            local = git.get_local_br_via_remote(root, remote)
            if local == "":
                local = git.create_default_local_br(root, point)
        elif git.is_tag(root, point):
            tag = point
        else:
            sys.stderr.write("Failed: '" + point + "' is not a local branch, or "\
                + "remote-tracking branch, or tag.")
            sys.exit(2)

    if tag == "":
        git.cleanup_working_tree(root)
        git.checkout(root, local, "branch")
        if common.cfgs['gitrebase']:
            git.rebase(root, remote)
        else:
            git.merge(root, remote)
    else:
        git.cleanup_working_tree(root)
        git.checkout(root, tag, "tag")

    config = None
    if tag == "":
        config = common.get_stream_cfg(root, local, remote)
    else:
        tag_annotation = git.get_tag_annotation(root, tag)
        config = common.get_baseline_cfg(root, tag, tag_annotation)
        
    for component in config.sections():
        if not config.has_option(component, 'type'):
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("No 'type' option in '" + component + "' section.")
            sys.exit(2)
        
        type = config.get(component, 'type')
        if type.lower() == 'git':
            git.download(root, config, component)
        elif type.lower() == 'svn' or type.lower() == 'subversion':
            svn.download(root, config, component)
        elif type.lower() == 'fl' or type.lower() == 'file':
            file.download(root, config, component, True)
        elif type.lower() == 'dir' or type.lower() == 'directory':
            file.download(root, config, component, False)
        else:
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("type '" + type + "' is not supported.")
            sys.exit(2)
示例#2
0
def upload(args):
    """Upload/deliver local modifications to remote repositories."""

    point = ""
    if len(args) == 0:
        pass
    elif len(args) > 1:
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        upload_usage()
        sys.exit(2)
    elif args[0] in ('-h', "--help"):
        upload_usage()
        sys.exit()
    elif args[0][0] == '-':
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        upload_usage()
        sys.exit(2)
    else:
        point = args[0]

    root = common.get_root()
    git.get_cmg_cfg(root)
    print("---- " + root)
    
    if common.cfgs['online']:
        git.fetch(root)
    else:
        sys.stderr.write("Failed: CMG is running under offline mode. No way to upload.")
        upload_usage()
        sys.exit(2)

    local = remote = tag = ""
    if point == "":
        (local, remote) = git.get_current_br_pair(root)
        if local == "":
            sys.stderr.write("Failed: it's not on a local branch "\
                + "that follow a remote-tracking branch")
            sys.exit(2)
    else:
        if git.is_local_br(root, point):
            local = point
            remote = git.get_remote_br_via_local(root, local)
            if remote == "":
                sys.stderr.write("Failed: can not find local branch "\
                    + local + "'s remote-tracking branch\n")
                sys.exit(2)
        elif git.is_local_br_to_create(root, point):
            local = git.create_default_local_br(root, point)
            remote = "origin/" + local
        elif git.is_remote_br(root, point):
            remote = point
            local = git.get_local_br_via_remote(root, remote)
            if local == "":
                local = git.create_default_local_br(root, point)
        elif git.is_tag(root, point):
            tag = point
        else:
            sys.stderr.write("Failed: '" + point + "' is not a local branch, or "\
                + "remote-tracking branch, or tag.")
            sys.exit(2)

    if local != "" and point != "": #to check if current branch is the given branch
        (local_now, remote_now) = git.get_current_br_pair(root)
        if local_now == "":
            sys.strerr.write("Failed: it's expected to be on local branch '"\
                + local + "' to follow remote-tracking branch '" + remote +"', "\
                + "but currently it's not on a local branch " +\
                "that follow a remote-tracking branch.")
            sys.exit(2)
        elif local_now != local:
            sys.strerr.write("Failed: it's expected to be on local branch '"\
                + local + "' to follow remote-tracking branch '" + remote +"', "\
                + "but currently it's on local branch '" + local_now +\
                "' that follow remote-tracking branch '" + remote_now + "'.")
            sys.exit(2)
            
    
    git.cleanup_working_tree(root)
    
    config = None
    if tag == "":
        config = common.get_stream_cfg(root, local, remote)
    else:
        tag_annotation = git.get_tag_annotation(root, tag)
        config = common.get_baseline_cfg(root, tag, tag_annotation)
        
    for component in config.sections():
        if not config.has_option(component, 'type'):
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("No 'type' option in '" + component + "' section.")
            sys.exit(2)
        
        type = config.get(component, 'type')
        if type.lower() == 'git':
            git.upload(root, config, component)
        elif type.lower() == 'svn' or type.lower() == 'subversion':
            svn.upload(root, config, component)
        elif type.lower() == 'fl' or type.lower() == 'file':
            file.upload(root, config, component)
        elif type.lower() == 'dir' or type.lower() == 'directory':
            file.upload(root, config, component)
        else:
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("type '" + type + "' is not supported.")
            sys.exit(2)

    print("---- (back to) " + root)
    if tag == "":
        if common.cfgs['gitrebase']:
            git.rebase(root, remote)
        else:
            git.merge(root, remote)
        git.push(root, remote)
    else:
        git.push_tag(root, tag)
示例#3
0
def status(args):
    """Show status/diff information of container and each component"""

    point = ""
    if len(args) == 0:
        pass
    elif len(args) > 1:
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        status_usage()
        sys.exit(2)
    elif args[0] in ('-h', "--help"):
        status_usage()
        sys.exit()
    elif args[0][0] == '-':
        sys.stderr.write("Failed: wrong format of command line paramaters.")
        status_usage()
        sys.exit(2)
    else:
        point = args[0]
        
    root = common.get_root()
    git.get_cmg_cfg(root)
    print("---- " + root)
    
    if common.cfgs['online']:
        git.fetch(root)
    else:
        print("Warning: CMG is running under offline mode. No interaction with remote.")
    
    local = remote = tag = ""
    if point == "":
        (local, remote) = git.get_current_br_pair(root)
        if local == "":
            print("Warning: it's expected to be on a local branch "\
                + "that follow a remote-tracking branch, but currently not.")
    else:
        if git.is_local_br(root, point):
            local = point
            remote = git.get_remote_br_via_local(root, local)
            if remote == "":
                print("Warning: can not find local branch "\
                    + local + "'s remote-tracking branch.\n")
        elif git.is_local_br_to_create(root, point):
            local = git.create_default_local_br(root, point)
            remote = "origin/" + local
        elif git.is_remote_br(root, point):
            remote = point
            local = git.get_local_br_via_remote(root, remote)
            if local == "":
                local = git.create_default_local_br(root, point)
        elif git.is_tag(root, point):
            tag = point
        else:
            print("Warning: '" + point + "' is not a local branch, or "\
                + "remote-tracking branch, or tag.")

    if local != "" and remote != "" and point != "": #to check if current branch is the given branch
        (local_now, remote_now) = git.get_current_br_pair(root)
        if local_now == "":
            print("Warning: it's expected to be on local branch '"\
                + local + "' to follow remote-tracking branch '" + remote +"', "\
                + "but currently it's not on a local branch " \
                + "that follow a remote-tracking branch.")
        elif local_now != local:
            print("Warning: it's expected to be on local branch '"\
                + local + "' to follow remote-tracking branch '" + remote +"', "\
                + "but currently it's on local branch '" + local_now\
                + "' that follow remote-tracking branch '" + remote_now + "'.")
        
    elif tag != "": # to check if HEAD is on the given tag
        if not git.is_on_tag(root, tag):
            print("Warning: it's expected to be on tag '" + tag\
                + "', but currently it's not.")

    if local != "" and remote != "": #to check if remote-tracking branch has multiple local branch
        git.remind_multi_local(root, remote)
        
    git.get_status(root)
            
    config = None
    if tag == "":
        config = common.get_stream_cfg(root, local, remote)
    else:
        tag_annotation = git.get_tag_annotation(root, tag)
        config = common.get_baseline_cfg(root, tag, tag_annotation)
        
    for component in config.sections():
        if not config.has_option(component, 'type'):
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("No 'type' option in '" + component + "' section.")
            sys.exit(2)
        
        type = config.get(component, 'type')
        if type.lower() == 'git':
            git.status(root, config, component)
        elif type.lower() == 'svn' or type.lower() == 'subversion':
            svn.status(root, config, component)
        elif type.lower() == 'fl' or type.lower() == 'file':
            file.status(root, config, component)
        elif type.lower() == 'dir' or type.lower() == 'directory':
            file.status(root, config, component)
        else:
            sys.stderr.write("Failed: bad format of stream/baseline config: ")
            sys.stderr.write("type '" + type + "' is not supported.")
            sys.exit(2)