Date: | 2015-05-10 |
---|---|
Author: | Roland Smith |
The Creo Parametric software (f.k.a. Pro/Engineer) saves its files as numbered versions. While this is in itself commendable (it's nice to be able to roll-back to a previously known good version of a file) it is an old-fashioned approach in the age of modern revision control software such as e.g. git. If you save often when working in Creo (which is generally a good idea) you end up with lots of versions of the same file.
So I wrote a script to help clean up this mess. For obvious reasons it is
called creoclean
.
Note
On posix
platforms like Linux, BSD and OSX, the script is installed
without an extension. On MS windows platforms, the scripts needs to be
installed as creoclean.py
so that it is linked to the Python program
that has to run it. So of you are on the windows platform, please read
creoclean.py
whereever you see creoclean
.
This program is licensed under the BSD 2-clause license. See the top of
creoclean.py
for the full text.
Note
You should probably close all open files in the directory and purge them from the Creo session before running this script in a directory!
You can use this program basically in two ways:
creoclean
This cleans up the current working directory. Or you can use:
creoclean <dir1> <dir2> ...
This cleans up the directories named on the command line.
The -h
option displays the online help.:
> creoclean -h usage: creoclean [-h] [-d] [-v] [--log {debug,info,warning,error}] [dir [dir ...]] Cleans up Creo versioned files in the named diratories or in the current working directory. Removes all versions except the last one, and renames that to version 1. positional arguments: dir one or more directories to process optional arguments: -h, --help show this help message and exit -d dry run; show what would be done but don't delete files -v, --version show program's version number and exit --log {debug,info,warning,error} logging level (defaults to 'warning')
The -d
option makes the program perform a dry run. This means that all
actions are listed but not carried out.:
> creoclean -d ~/tmp/spam-eggs/ INFO: DRY RUN, no files will be deleted or renamed INFO: cleaning in '/home/jdoe/tmp/spam-eggs/' INFO: found 21 files INFO: not enough 'asm' files; skipping INFO: found 9 'prt' files INFO: found 2 unique 'prt' file names INFO: removing 'spamshaper.prt.10' INFO: removing 'spamshaper.prt.11' INFO: removing 'spamshaper.prt.12' INFO: renaming 'spamshaper.prt.13' to 'spamshaper.prt.1' INFO: removing 'eggcontainer.prt.5' INFO: removing 'eggcontainer.prt.6' INFO: removing 'eggcontainer.prt.7' INFO: removing 'eggcontainer.prt.8' INFO: renaming 'eggcontainer.prt.9' to 'eggcontainer.prt.1'
You can see the same information during a real run by specifying the
--log info
option.
This script requires Python 3. It has been developed and tested on Python 3.4. It has no further dependencies outside of the Python standard library.
Copy the file creoclean.py
to the Scripts
subdirectory of your Python
installation. You can then call it from a cmd.exe
window, if the .py
extension is associated with a filetype, and the filetype has an appropriate
action defined. If trying to run creoclean.py
gives an error, try
executing the following commands in a cmd.exe
window:
assoc .py=Python.File ftype Python.File="C:\Anaconda3\python.exe" "%1" %*
Note that C:\Anaconda3
is just an example! You should of course substitute
the real path to your python.exe
.
Copy creoclean.py
to any directory in your PATH, and set the permissions
to executable, e.g. using the install
program:
install creoclean.py ~/bin/creoclean