Created
April 1, 2020 20:01
-
-
Save theodox/a7cd918dae5e5429f56d9aa2a8e9b355 to your computer and use it in GitHub Desktop.
Edit P4 xm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_tool(name, exe, commandline, shortcut=''): | |
''' | |
Adds a command entry to a tools list container node. | |
* tool_list_element is ElementTree node representing the tools list | |
* exe is the path to the executable | |
* commandline is the arguments passed to the commandline. | |
* shortcut is a key shortcut | |
If a tool with the same name already exists, it will be overwritten | |
Perforce supports special characters in the command lines, which | |
will be replaced at call time. see | |
www.perforce.com/manuals/p4v/Content/P4V/advanced_options.custom.html | |
for the full list. Useful ones include | |
$c current client | |
%c current changelist | |
''' | |
existing = get_tool_by_name(name) | |
if existing is not None: | |
remove_tool(name) | |
''' | |
This is an example of the schema | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!--perforce-xml-version=1.0--> | |
<CustomToolDefList varName="customtooldeflist"> | |
<CustomToolDef> | |
<Definition> | |
<Name>example</Name> | |
<Command>python.exe</Command> | |
<Arguments>C:/Users/Steve/Desktop/dummy.py --client $c --changelist %c</Arguments> | |
<Shortcut></Shortcut> | |
</Definition> | |
<Console> | |
<CloseOnExit>false</CloseOnExit> | |
</Console> | |
<Refresh>true</Refresh> | |
</CustomToolDef> | |
</CustomToolDefList> | |
''' | |
definition = ETree.SubElement(_CATALOG, 'CustomToolDef') | |
tool_def = ETree.SubElement(definition, 'Definition') | |
name_node = ETree.SubElement(tool_def, 'Name') | |
name_node.text = name | |
command = ETree.SubElement(tool_def, 'Command') | |
command.text = exe | |
args = ETree.SubElement(tool_def, 'Arguments') | |
args.text = commandline | |
shortcut_node = ETree.SubElement(tool_def, 'Shortcut') | |
shortcut_node.text = shortcut | |
console = ETree.SubElement(tool_def, 'Console') | |
# this one force-closes p4v's console window, if present | |
# if somebody turns that on, they probably want to see the | |
# debug spew so default it to false | |
close_on_exit = ETree.SubElement(console, 'CloseOnExit') | |
close_on_exit.text = 'false' | |
refresh = ETree.SubElement(tool_def, 'Refresh') | |
refresh.text = 'true' | |
# this makes the tool available in a changelist context menu | |
# note that it's a child of 'definition' and not 'tool_def' | |
add_to_ctx = ETree.SubElement(definition, 'AddToContext') | |
add_to_ctx.text = 'true' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to find the location: