{{{#!rst
===========================================
Excluding Version Control Files in Output
===========================================
Intro
=====
It is often very useful to keep output in version control
systems. This allows rollbacks of content without having to actually
change source documents and other binary data. It is also valuable to
keep customizations made to formats in version control as well. This
allows more organized development of new format features and generally
is a good practice for any type of source code.
The problem is when ePublisher processes output, if there are files
associated with a version control system, these files are carried
along with output. This can cause numerous problems because versioning
information associated with custom format changes get passed along
with the format, which will cause a conflict in many version control
systems.
Desired Output
==============
Considering most version control systems have very simple and
relatively unique files associated with them, it can be very easy to
remove the files after generation manually or through a simple script.
For example, this is a simple python script to remove .svn folders
from output.
}}}
{{{#!python
import os
def clean_directories(startdir, pattern='.svn'):
fullpath = os.path.abspath(startdir)
badfolders = []
for root, dirs, files in os.walk(fullpath):
for folder in dirs:
dirpath = os.path.join(root, folder)
if pattern in folder:
badfolders.append(dirpath)
for dn in badfolders:
files_to_remove = []
for root, dirs, files in os.walk(dn):
for name in files:
files_to_remove.append(os.path.join(root, name))
for fn in files_to_remove:
os.remove(fn)
os.rmdir(dn)
}}}
{{{#!rst
While this script *should* work it makes more sense to simply not copy
over the version control files in the first place.
Filtering Output Files
======================
ePubublisher performs a copy operation on files that the format will
use. This includes files such as images, Javascript files and any
custom files such as CSS. This also includes the User Files area. This
copy operation is performed in the common XSLs with::
{Program Files}/Formats/Shared/common/files/copy.xsl
The copy.xsl file simply copies any files necessary from the format
and user files to the output directory. On line 83 is where the copy
operation begins::
In this section the file that is going to be copied is tested to see
if it has changed since the last time the output was generated. If the
file has changed then it is copied to the output using this line::
The 'wwfilesystem' is an extension object that allows you to do things
on the filesystem from within the XSLs.
If you wanted to exclude any files associated with CVS (for example)
you could use the following code::
NOTE: Directories should always include leading and trailing delimiters to prevent issues with filenames such as 'C:\Path\DOCVS2003.txt\' from being excluded. 'DOCVS2003.txt' will match on a simple test for 'CVS'.
Here we test to see if the path contains '\CVS\'. If it does *not*
contain 'CVS' then it is copied to the output folder. This could be a
potential problem if you had directories you required that contained 'CVS' but,
this should make it clear how you could write your own filter to
remove different types of files.
Please review the other `filesystem extension functions `_ to see how you can find different information regarding the files that might
help to create a filter.
}}}