Ejemplo n.º 1
0
def git_p4_init(options):
    p4w = p4_wrapper()
    #Login to workspace
    p4w.p4_login(options.port, options.user, options.client, options.passwd)
    #Read client spec
    (res, p4conf) = p4w.p4_client_read()
    p4w.save_state()
    
    if not res:
        return
    #Add client to config
    config_wrapper.new_branch_config(options.branch, p4conf)
    #change root & write client config to p4 & config file
    new_root = ""
    if options.root == None:
        new_root = git_wrapper.get_topdir()+"/.git/p4repo_"+options.branch
        os.mkdir(new_root)
    else:
        new_root = options.root

    p4conf._root =  new_root
    p4w.p4_client_write(p4conf)
    
    p4conf._port = options.port
    p4conf._user = options.user
    p4conf._passwd = options.passwd    
    config_wrapper.set_branch_config(options.branch, p4conf)
    
    if options.nosync != True:
        git_p4_sync(options)
    else:        
        print "Initialized empty git-p4 repository"
    #TODO: set p4 head
        
    p4w.p4_logout()
Ejemplo n.º 2
0
def git_p4_init(options):
    p4w = p4_wrapper()
    #Login to workspace
    p4w.p4_login(options.port, options.user, options.client, options.passwd)
    #Read client spec
    (res, p4conf) = p4w.p4_client_read()
    p4w.save_state()

    if not res:
        return
    #Add client to config
    config_wrapper.new_branch_config(options.branch, p4conf)
    #change root & write client config to p4 & config file
    new_root = ""
    if options.root == None:
        new_root = git_wrapper.get_topdir() + "/.git/p4repo_" + options.branch
        os.mkdir(new_root)
    else:
        new_root = options.root

    p4conf._root = new_root
    p4w.p4_client_write(p4conf)

    p4conf._port = options.port
    p4conf._user = options.user
    p4conf._passwd = options.passwd
    config_wrapper.set_branch_config(options.branch, p4conf)

    if options.nosync != True:
        git_p4_sync(options)
    else:
        print "Initialized empty git-p4 repository"
    #TODO: set p4 head

    p4w.p4_logout()
Ejemplo n.º 3
0
def _git_p4_sync_one(path, changelist, file_count):
    p4w = p4_wrapper()
    p4w.load_state()

    if not p4w.is_logged():
        return False
    #TODO: for now track_progress if false
    (res, filelist) = p4w.p4_sync(path, changelist._ch_no, True, False,
                                  file_count)

    if not res:
        return False

    command = ""
    git_topdir = git_wrapper.get_topdir()
    os.chdir(p4w._p4config._root)
    print os.getcwd()
    for synced_file in filelist:
        if synced_file._action == "add" or synced_file._action == "edit":
            command = "cp --parents -f " + p4w.strip_p4root(
                synced_file._real_path)[1:] + " " + git_topdir
        elif synced_file._action == "delete":
            command = "rm -f " + git_topdir + p4w.strip_p4root(
                synced_file._real_path)
            #TODO: add removing empty dirs after this

        cp_proc = subprocess.Popen(command,
                                   stdout=None,
                                   stderr=None,
                                   shell=True)
        print command
        cp_proc.communicate()
        #TODO: add cp process tracker

    os.chdir(git_topdir)
    ret = git_wrapper.add_all_changes()

    if ret != 0:
        return False

    ret = git_wrapper.commit(changelist)

    if ret != 0:
        return False

    ret = git_wrapper.tag_CL(path, changelist)

    return not bool(ret)
Ejemplo n.º 4
0
def _git_p4_sync_one(path, changelist, file_count):
    p4w = p4_wrapper()
    p4w.load_state()
    
    if not p4w.is_logged():
        return False    
    #TODO: for now track_progress if false
    (res, filelist) = p4w.p4_sync(path, changelist._ch_no, True, False, file_count)
    
    if not res:
        return False
    
    command = ""
    git_topdir = git_wrapper.get_topdir()
    os.chdir(p4w._p4config._root)
    print os.getcwd()
    for synced_file in filelist:        
        if synced_file._action == "add" or synced_file._action == "edit":
            command = "cp --parents -f "+p4w.strip_p4root(synced_file._real_path)[1:]+" "+git_topdir
        elif synced_file._action == "delete":
            command = "rm -f "+git_topdir+p4w.strip_p4root(synced_file._real_path)
            #TODO: add removing empty dirs after this
            
        cp_proc = subprocess.Popen(command, stdout=None, stderr=None, shell=True)
        print command
        cp_proc.communicate()
        #TODO: add cp process tracker
    
    os.chdir(git_topdir)
    ret = git_wrapper.add_all_changes()
    
    if ret != 0:
        return False
    
    ret = git_wrapper.commit(changelist)
    
    if ret != 0:
        return False
    
    ret = git_wrapper.tag_CL(path, changelist)
    
    return not bool(ret)
Ejemplo n.º 5
0
    def p4_client_write(self, p4conf):
        if self._logged == False:
            return False
        
        output = ""
        for key, value in p4conf.__dict__.iteritems():
            conf_arg = p4conf.ArgToClient(key)
            if conf_arg == "":
                continue
            output += conf_arg    
            if type(value) == str:
                output += "\t"+value
            elif type(value) == list:
                output += "\t"
                for list_item in value:
                    output += list_item+" "
            elif type(value) == datetime:
                output += "\t"+value.strftime("%Y/%m/%d %H:%M:%S")
            elif type(value) == dict:
                output += "\n"
                for map_in, map_out in value.iteritems():
                    output += "\t"+map_in+" "+map_out+"\n"
            output+="\n"
        
        temp_path = git_wrapper.get_topdir()+"/.git/temp_p4_config"
        
        with open(temp_path, "w") as temp_file:
            temp_file.write(output)
            
        res = subprocess.call('p4 client -i < '+temp_path, shell=True, stdout=subprocess.PIPE)
        os.remove(temp_path)
        
        if res:
            _p4config = p4conf

        return not bool(res)
Ejemplo n.º 6
0
def get_config_path():
    return git_wrapper.get_topdir()+"/.git/p4config"