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.

   1   import os
   2 
   3   def clean_directories(startdir, pattern='.svn'):
   4       fullpath = os.path.abspath(startdir)
   5       badfolders = []
   6       for root, dirs, files in os.walk(fullpath):
   7         for folder in dirs:
   8             dirpath = os.path.join(root, folder)
   9             if pattern in folder:
  10                 badfolders.append(dirpath)
  11         for dn in badfolders:
  12             files_to_remove = []
  13             for root, dirs, files in os.walk(dn):
  14                 for name in files:
  15                     files_to_remove.append(os.path.join(root, name))
  16             for fn in files_to_remove:
  17                 os.remove(fn)
  18             os.rmdir(dn)

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:

<!-- Copy -->
<!--      -->
<xsl:variable name="VarUpToDate" select="wwfilesext:UpToDate($VarDestinationPath, '', $VarFilesNode/@groupID, '', concat($GlobalActionChecksum, ':', $VarSourcePath))" />
<xsl:if test="not($VarUpToDate)">
 <xsl:variable name="VarIgnore" select="wwfilesystem:CopyFile($VarSourcePath, $VarDestinationPath)" />
</xsl:if>

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:

<xsl:variable name="VarIgnore" select="wwfilesystem:CopyFile($VarSourcePath, $VarDestinationPath)" />

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:

<!-- Copy -->
<!--      -->
<xsl:variable name="VarUpToDate" select="wwfilesext:UpToDate($VarDestinationPath, '', $VarFilesNode/@groupID, '', concat($GlobalActionChecksum, ':', $VarSourcePath))" />
<xsl:if test="not($VarUpToDate)">
 <xsl:variable name="VarSourceDirectory" select="wwfilesystem:GetDirectoryName($VarCopyFile/@source)" />
 <xsl:if test="contains($VarSourceDirectory, '\CVS\') = false()">
  <xsl:variable name="VarIgnore" select="wwfilesystem:CopyFile($VarSourcePath, $VarDestinationPath)" />
 </xsl:if>
</xsl:if>

NOTE: Directories should always include leading and trailing delimiters to prevent issues with filenames such as 'C:PathDOCVS2003.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.

HelpCenter/Tips/VersionControl/ExcludeVCFilesInOutput (last edited 2008-02-13 06:18:28 by localhost)