Skip to content

Instantly share code, notes, and snippets.

@givanse
Last active May 2, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save givanse/8c69f55f8243733702cf7bcb0e9290a9 to your computer and use it in GitHub Desktop.
Save givanse/8c69f55f8243733702cf7bcb0e9290a9 to your computer and use it in GitHub Desktop.
python script that tells you which local files are not part of a perforce depot
#! /usr/bin/env python
# For this script to work you have to install `p4` (Helix command line client)
# This script will tell you if you have local files that are not part of the depot.
#
# Usage example:
# tools$ p4-local-status.py
# folder: tools
# p4-local-status.cmd - no such file(s).
# p4-local-status.py - no such file(s).
# foobar.md - no such file(s).
import sys
import os
from os import path
import subprocess
if len(sys.argv) > 1:
targetFolder = sys.argv[1]
else:
targetFolder = os.getcwd()
print 'folder: %s' % targetFolder
def p4fstat(filePath):
arguments = ['p4', 'fstat', filePath]
subprocess.check_output(arguments)
def isInP4Ignore(filename):
p4Ignore = ['yarn-error.log', 'yarn-cache', 'node_modules', '.cache-loader']
return filename in p4Ignore
for root, dirnames, filenames in os.walk(targetFolder):
for dirname in dirnames:
if isInP4Ignore(dirname):
dirnames.remove(dirname)
for filename in filenames:
if not isInP4Ignore(filename):
filePath = os.path.join(root, filename)
p4fstat(filePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment