python and perforce

on

woot, wrote a python script to connect to a p4 server and create a changelist to add data to:

The idea here would be to open a file, parse it for files that need to be added/updated/revisioned in perforce, then pass this info to p4 via python.

from P4 import P4
p4 = P4()
# p4.port = "perforce-server:XXXX"
# p4.user = "username"
# print p4.env( "P4PORT" ) - this will allow you to get the .env info from p4

# sets the clientspec you want to connect to (otherwise will default to the p4’s default)
p4.client = “clientspec”

# connect to p4
p4.connect()

# setting description for changelist header info
desc = {“Description”: “Updates”, “Change”: “new”}

# calls desc and adds
p4.input = desc

# calls p4 run command and runs it with the changes integrated flag
p4.run(“changelist”, “-i”)

# closes connection to p4
p4.disconnect()

found a bit of info regarding open/reading/writing in python.

open(filename,mode)

1. filename can be a file or path to a file
2. mode can be any of the following

1. ‘r’ for reading
2. ‘r+’ for reading and writing
3. ‘w’ for writing
4. ‘a’ for appending
5. both read and write modes also have a ‘b’ option for binary reading and writing (’rb’, or ‘wb’)

Ex:
myInput = open(‘myfile.txt’,’r’)

This command will open the file “myfile.txt” in the current
directory, in “read” mode. You can access the methods of this file
using the ‘myInput’ variable. In the example, the open command will
open the file indicated in the first argument(’myfile.txt’).
This argument can be a file, or the path to a file. The second
argument, is the file mode.

4 Comments Add yours

  1. Chad says:

    Sweet. Nerdy. I like it!

  2. Chad says:

    Sweet. Nerdy. I like it!

  3. chonny says:

    great, you’re becoming chad.

  4. chonny says:

    great, you’re becoming chad.

Leave a Reply to Chad Cancel reply

Your email address will not be published. Required fields are marked *