checkout-to.py #2

  • //
  • guest/
  • miki_tebeka/
  • p4vaddins/
  • main/
  • checkout-to.py
  • View
  • Commits
  • Open Download .zip Download (2 KB)
'''Checkout to a specific changelist'''

# Copyright (c) 2006 Qualcomm
# Miki Tebeka <[email protected]>

from os import environ
import sys
from os.path import isfile, dirname, join
import wx
from wx.lib.intctrl import IntCtrl

from p4 import P4, P4Error
from p4v_common import make_error, gen_p4, optparser

# Initialize wx (need to be first so that "error" will work)
app = wx.PySimpleApp()
error = make_error("Checkout2 Error")

def is_file(p4, path):
    '''Check is path is a file'''
    return p4.run_fstat(path) != []
    
def walk(p4, path):
    '''Walk over directory tree'''
    if path[-1] != "/":
        path += "/"

    for file in p4.run_files(path + "*"):
        yield file["depotFile"]

    for dir in p4.run_dirs(path + "*"):
        for file in walk(p4, dir["dir"]):
            yield file


def main(argv = None):
    if argv == None:
        import sys
        argv = sys.argv
    # Command line parsing
    parser = optparser("usage: %prog [options] PATH")
    opts, args = parser.parse_args(argv[1:])
    if len(args) != 1:
        error(parser.get_usage())
        raise SystemExit(parser.get_usage())

    # Get arguments
    path = args[0]
    p4 = gen_p4(opts)

    DEFAULT = "default"

    changes = [DEFAULT]
    for change in p4.run_changes("-c", p4.client, "-s", "pending"):
        changes.append("%s (%s)" % (change["change"], change["desc"].strip()))

    dlg = wx.SingleChoiceDialog(None, "Select changelist", 
            "Checkout To Changelist", changes)
    if dlg.ShowModal() == wx.ID_OK:
        change = dlg.GetStringSelection()
    else:
        change = ""
    dlg.Destroy()

    if not change:
        raise SystemExit()

    if change == DEFAULT:
        def edit(path):
            p4.run_edit(path)
    else:
        def edit(path):
            p4.run_edit("-c", change.split()[0], path)

    if is_file(p4, path):
        edit(path)
    else:
        for file in walk(p4, path):
            edit(file)

if __name__ == "__main__":
    try:
        main()
    except P4Error, e:
        error(e)
        raise SystemExit(1)
# Change User Description Committed
#3 5628 Miki Tebeka Initial support for P4V new XML settings file
#2 5382 Miki Tebeka * Start of UNIX - File format and #!
* getvalue returns string (not unicode in some cases)
#1 5280 Miki Tebeka Initial checkin of project