A Python Perforce package that doesn't bring in any other packages to work.

Related tags

Miscellaneousp4cmd
Overview

P4CMD 🌴

A Python Perforce package that doesn't bring in any other packages to work. Relies on p4cli installed on the system.

p4cmd

The p4cmd module holds the P4Client class that allows you to interact with the P4 server.

To instantiate a new client, you either pass it the root path of you Perforce workspace or if the "P4ROOT" system variable is set, you can use the from_env class function

from p4cmd import p4cmd

client = p4cmd.P4Client("~/nisse/projects/raw")
from p4cmd import p4cmd
import os

# settings system variable
os.environ["P4ROOT"] = "~/nisse/projects/raw"

# now we can use from_env
client = p4cmd.P4Client.from_env()

Most of the functions are pretty self explanatory and have docstrings about how they work.

There are 2 functions called file_to_p4files and folder_to_p4files that use the P4File class in p4file.

p4file

This module holds the P4File class that allows you to quickly and easily get information about any file on disk or in the depot.

Usage

Some use case examples to help you on your way.

Checking out files or adding new files. You can mix/match local and depot paths. Add a changelist number or description to put the files in that CL. If you add a description of a changelist that doesn't exist, it will be created.

from p4cmd import p4cmd
root = "~/p4/MyGame"

files = [r"~/p4/MyGame/Raw/Characters/info_file.json",
         "//MyGame/Main/Templates/morefiles.json"]

p4 = p4cmd.P4Client(root)
p4.add_or_edit_files(files, changelist="My new changelist")

Seperate edit_files and add_files methods also exist if you need to use them for some reason.

Perforce operations can be quite slow, so if you need to check a bunch of files at once you can use do something like this:

from p4cmd import p4cmd
root = "~/p4/MyGame"

folder = r"~/p4/MyGame/Animations"

p4 = p4cmd.P4Client(root)
p4files = p4.folder_to_p4files(folder)

files_to_sync = []
for p4file in p4files:
    if p4file.get_checked_out_by() is not None: # somebody else other than you checked out the file
        print("depot path:", p4file.get_depot_file_path())
        print("local path:", p4file.get_local_file_path())
        print("status:", p4file.get_status())
        print("Checked out by:", p4file.get_checked_out_by())
    if p4file.needs_syncing():
        files_to_sync.append(p4file.get_local_file_path())

p4.sync_files([files_to_sync])
depot path: //MyGame/Main/MyGame/run.fbx
local path: ~/p4/MyGame/MyGame/run.fbx
status: UP_TO_DATE
Checked out by: [email protected]
depot path: //MyGame/Main/MyGame/dance.json
local path: ~/p4/MyGame/MyGame/dance.json
status: NEED_SYNC

folder_to_p4files returns a list of type p4file. A p4file has a bunch of functions to get information about the file and its status. This will get information back about all the files in one go, instead of you having to make a server call for every file on its own.

Getting all your pending changelists:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
all_changelists = p4.get_pending_changelists()

[35272, 33160, 32756, 30872, 27277]

Getting changelists with shelved files:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
shelved_changelists = [pair[1] for pair in p4.get_shelved_files()]

[30872, 30872, 27277]

Searching in changelist descriptions:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
houdini_cls = p4.get_pending_changelists(description_filter="houdini")

[35272, 33160]

Finding an exact changelist:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
houdini_anim_cl = p4.get_pending_changelists(description_filter="[houdini tools]", perfect_match_only=True, case_sensitive=True)

[33160]

Listing all the files in a changelist by changelist number:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
files = p4.get_files_in_changelist(33160)
//MyGame/Animations/a_pose.fbx
//MyGame/Animations/t_pose.fbx

List all the files in a changelist by changelist description:

from p4cmd import p4cmd
root = "~/p4/MyGame"

p4 = p4cmd.P4Client(root)
files = p4.get_files_in_changelist("[houdini tools]")
//MyGame/Animations/a_pose.fbx
//MyGame/Animations/t_pose.fbx
You might also like...
Canim1 - Simple python tool to search for packages without m1 wheels in poetry lockfiles

canim1 Usage Clone the repo. Run poetry install. Then you can use the tool: ❯ po

Packages of Example Data for The Effect

causaldata This repository will contain R, Stata, and Python packages, all called causaldata, which contain data sets that can be used to implement th

This is a method to build your own qgis configuration packages using osgeo4W.

This is a method to build your own qgis configuration packages using osgeo4W. Then you can automate deployment in your organization with a controled and trusted environnement.

An AI-powered device to stop people from stealing my packages.

Package Theft Prevention Device An AI-powered device to stop people from stealing my packages. Installation To install on a raspberry pi, clone the re

Automatically give thanks to Pypi packages you use in your project!

Automatically give thanks to Pypi packages you use in your project!

Pacman - A suite of tools for manipulating debian packages

Overview Repository is a suite of tools for manipulating debian packages. At a h

A test repository to build a python package and publish the package to Artifact Registry using GCB

A test repository to build a python package and publish the package to Artifact Registry using GCB. Then have the package be a dependency in a GCF function.

Datamol is a python library to work with molecules.
Datamol is a python library to work with molecules.

Datamol is a python library to work with molecules. It's a layer built on top of RDKit and aims to be as light as possible.

Python module to work with Magneto Database directly without using broken Magento 2 core
Python module to work with Magneto Database directly without using broken Magento 2 core

Python module to work with Magneto Database directly without using broken Magento 2 core

Comments
  • New functions & validation function

    New functions & validation function

    • Added new validate files under perforce root function that raises error if files not under root
    • Removed default list arg for folder sync function
    • Added a delete changelist function
    • Added a revert changelist function (gets all files in a CL and reverts them all)
    opened by ben-hearn-sb 4
  • 10C Patches

    10C Patches

    Raising exception when files are not under client root Adding is_under_client_root validation check in p4_file Setting list for files inputted to function is not list

    opened by ben-hearn-sb 1
Owner
Niels Vaes
Tech animator at Embark Studios in Stockholm by day, flight sim enthusiast at night.
Niels Vaes
Open Source Repository for CFD Solvers

Background and Validation This wiki is built in Notion. Here are all the tips you need to contribute. General Background Flow over a cylinder The proj

1 Dec 30, 2021
Collapse a set of redundant kmers to use IUPAC degenerate bases

kmer-collapse Collapse a set of redundant kmers to use IUPAC degenerate bases Overview Given an input set of kmers, find the smallest set of kmers tha

Alex Reynolds 3 Jan 06, 2022
SWS Filters App - SWS Filters App With Python

SWS Filters App Fun πŸ˜… ... Fun πŸ˜… Click On photo and see πŸ˜‚ πŸ˜‚ πŸ˜‚ Your Video rec

Sagar Jangid 3 Jul 07, 2022
Blender pluggin (python script) that adds a randomly generated tree with random branches and bend orientations

Blender pluggin (python script) that adds a randomly generated tree with random branches and bend orientations

Travis Gruber 2 Dec 24, 2021
p5 is a Python package based on the core ideas of Processing.

p5 p5 is a Python library that provides high level drawing functionality to help you quickly create simulations and interactive art using Python. It c

p5py 645 Jan 04, 2023
A person does not exist image bot

A person does not exist image bot

Fayas Noushad 3 Dec 12, 2021
More granular intermediaries for legacy Minecraft versions

Orinthe/Intermediary mappings This repository contains the match information between different versions of Minecraft created by the Orinthe project, a

4 Jan 11, 2022
Simple tools for the Horse Reality webgame

Realtools (Web Tools for Horse Reality) These tools were made on request from a close friend of mine who plays this game. A live instance can be found

shay 0 Sep 06, 2022
Free Vocabulary Trainer - not only for German, but any language

Bilderraten DOWNLOAD THE EXE FILE HERE! What can you do with it? Vocabulary Trainer for any language Use your own vocabulary list No coding required!

Hans AlemΓ£o 4 Jan 02, 2023
AIST++ API This repo contains starter code for using the AIST++ dataset.

Explainability for Vision Transformers (in PyTorch) This repository implements methods for explainability in Vision Transformers

Google 260 Dec 30, 2022
LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visualization exercises.

libreMind Meditation exercises What is it? LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visua

1 May 24, 2022
PyDy, short for Python Dynamics, is a tool kit written in the Python

PyDy, short for Python Dynamics, is a tool kit written in the Python programming language that utilizes an array of scientific programs to enable the study of multibody dynamics. The goal is to have

PyDy 307 Jan 01, 2023
News-app - This is a news web app for reading news from different sources and topics

News-app - This is a news web app for reading news from different sources and topics

1 Feb 02, 2022
This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

Alexander Bartolomey 1 Dec 31, 2021
Python client library for the Databento API

Databento Python Library The Databento Python client library provides access to the Databento API for both live and historical data, from applications

Databento, Inc. 35 Dec 24, 2022
Get a list of the top-10 rejected libraries in your WhiteSource inventory

WhiteSource Top 10 Rejected Libraries Generate a spreadsheet listing the 10 most common libraries in your WhiteSource inventory that were rejected by

WhiteSource-PS-tools 10 Mar 23, 2022
Visualize Data From Stray Scanner https://keke.dev/blog/2021/03/10/Stray-Scanner.html

StrayVisualizer A set of scripts to work with data collected using Stray Scanner. Usage Installing Dependencies Install dependencies with pip -r requi

Kenneth Blomqvist 45 Dec 30, 2022
Refer'd Resume Scanner

Refer'd Resume Scanner I wanted to share a free resource we built to assist applicants with resume building. Our resume scanner identifies potential s

Refer'd 74 Mar 07, 2022
Python Function to manage users via SCIM

Python Function to manage users via SCIM This script helps you to manage your v2 users. You can add and delete users or groups, add users to groups an

4 Oct 11, 2022
Width-customizer-for-streamlit-apps - Width customizer for Streamlit Apps

🎈 Width customizer for Streamlit Apps As of now, you can only change your Strea

Charly Wargnier 5 Aug 09, 2022