문제

소스 코드에 대한 자동 변경 사항을 수행하는 일부 스크립트를 파이썬으로 작성하고 싶습니다. 스크립트에서 파일을 변경해야한다고 결정하면 먼저 Perforce에서 파일을 확인하고 싶습니다. 나는 항상 먼저 구축하고 테스트하고 싶기 때문에 체크인에 신경 쓰지 않습니다.

도움이 되었습니까?

해결책

Perforce에는 C/C ++ 도구 주변의 파이썬 포장지가 있으며 Windows 용 바이너리 형태로 제공되며 다른 플랫폼 용 소스가 있습니다.

http://www.perforce.com/perforce/loadsupp.html#api

스크립팅 API에 대한 문서가 도움이 될 것입니다.

http://www.perforce.com/perforce/doc.current/manuals/p4script/p4script.pdf

Python API 사용은 명령 줄 클라이언트와 매우 유사합니다.

PythonWin 2.5.1 (r251:54863, May  1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> import P4
>>> p4 = P4.P4()
>>> p4.connect() # connect to the default server, with the default clientspec
>>> desc = {"Description": "My new changelist description",
...         "Change": "new"
...         }
>>> p4.input = desc
>>> p4.run("changelist", "-i")
['Change 2579505 created.']
>>> 

명령 줄에서 확인하겠습니다.

P:\>p4 changelist -o 2579505
# A Perforce Change Specification.
#
#  Change:      The change number. 'new' on a new changelist.
#  Date:        The date this specification was last modified.
#  Client:      The client on which the changelist was created.  Read-only.
#  User:        The user who created the changelist.
#  Status:      Either 'pending' or 'submitted'. Read-only.
#  Description: Comments about the changelist.  Required.
#  Jobs:        What opened jobs are to be closed by this changelist.
#               You may delete jobs from this list.  (New changelists only.)
#  Files:       What opened files from the default changelist are to be added
#               to this changelist.  You may delete files from this list.
#               (New changelists only.)

Change: 2579505

Date:   2008/10/08 13:57:02

Client: MYCOMPUTER-DT

User:   myusername

Status: pending

Description:
        My new changelist description

다른 팁

다음은 다음과 같습니다.

import os

def CreateNewChangeList(description):
    "Create a new changelist and returns the changelist number as a string"
    p4in, p4out = os.popen2("p4 changelist -i")
    p4in.write("change: new\n")
    p4in.write("description: " + description)
    p4in.close()
    changelist = p4out.readline().split()[1]
    return changelist

def OpenFileForEdit(file, changelist = ""):
    "Open a file for edit, if a changelist is passed in then open it in that list"
    cmd = "p4 edit "
    if changelist:
        cmd += " -c " + changelist + " "
    ret = os.popen(cmd + file).readline().strip()
    if not ret.endswith("opened for edit"):
        print "Couldn't open", file, "for edit:"
        print ret
        raise ValueError

Perforce의 P4 Python 모듈 또 다른 대답에서 언급 된 방법이지만,이 모듈을 설치하는 것이 옵션이 아닌 경우 -g 플래그를 사용하여 p4.exe 출력을 구문 분석 할 수 있습니다.

p4 [ options ] command [ arg ... ]
    options:
            -c client -C charset -d dir -H host -G -L language
            -p port -P pass -s -Q charset -u user -x file
    The -G flag causes all output (and batch input for form commands
    with -i) to be formatted as marshalled Python dictionary objects.

P4PyThon 소스에서 구축하려면 해당 버전에 권장되는 P4 API를 다운로드하고 추출해야합니다. 예를 들어 ActivePython 2.5 용 P4Python 2008.2의 Windows XP X86 버전을 구축하는 경우 :

  • 둘 다 다운로드하고 추출합니다 p4python 그리고 P4API
  • p4python이 p4api 디렉토리를 가리 키도록 setup.cfg를 수정하십시오.

명령 줄에서 편집 파일을 열려면 (체크 아웃 수행) 'P4 Help Open'을 참조하십시오.

기본 changelist에 파일을 추가하면 Changelist를 만들지 않고 파일을 확인할 수 있지만 Changelist를 먼저 만드는 것이 좋습니다.

P4Python은 현재 Visual Studio 2008없이 ActivePython 2.6을 위해 컴파일하지 않습니다. 제공된 Libs는 2005 년 또는 2003 년으로 제작되었습니다. P4Python을 Mingw에 대항하여 구축하도록 강요하는 것은 Python26.dll의 pexports 및 제공된 .lib 파일을 .A 파일로 재 조립하는 경우에도 거의 불가능합니다.

이 경우 하위 프로세스를 사용하고 P4 결과를 마샬링 된 Python 객체로 반환 할 수 있습니다. Arg 어레이를 취하고 명령을 제작하고 실행하는 자신의 명령 래퍼를 작성하고 결과 사전을 반환 할 수 있습니다.

모든 것을 바꾸고 테스트하고 성공시, 'P4 diff -se // ...'와 동등한 파일을 열 수 있습니다.

p4python 모듈을 확인할 수 있습니다. Perforce 사이트에서 사용할 수 있으며 상황을 매우 간단하게 만듭니다.

P4API 용 Python 용 개발 패키지를 설치하는 사람을 기억하십시오. 그렇지 않으면 누락 된 헤더에 대해 불평 할 것입니다. Ubuntu 10.10에서는 간단하게하십시오.

apt-get install python2.6-dev

또는

apt-get install python3.1-dev
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top