Workspace Projects Builder Script

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
mgag
Posts: 70
Joined: Tue Jun 24, 2008 9:09 pm

Workspace Projects Builder Script

Post by mgag » Tue Dec 22, 2009 4:41 pm

Something I use to create a Zeus Workspace that has multiple "projects" that are actually the same project that is sync'd to a different changelist - basically each project is a different clientspec (to use perforce nomenclature). This script also helps if you need to create a project that has a filespec that is a much smaller subset of the total files available (Zeus Workspace Builder wasn't great for this, but with 3.97t it might be a lot better).

Note that you need to edit the script for your particular path/client setup.

Code: Select all

# ZeusCreateProject
# Purpose: create workspace file from a list of directories.
# This script is helpful IF you have a large amount of source
# directories and you only want a small subset of those directories.
# Zeus itself provides the WorkSpace Builder which does a good job, but
# it can be tedious to remove a lot of directories it finds.
#
# To use this script you must provide a list of directories - see the
# EDIT section below.  Note this script will add sub-directories of
# the directory list.
#
# After this script completes, open Zeus and open the Workspace file you created.
# It may take a long time to load as Zeus will create a tags database for the WorkSpace.
#
# Within the WorkSpace project, the files will be organized by directory,
# making source file browsing similiar to browsing a dir tree.
#
import glob, os, sys
from xml.dom.minidom import Document

if not len(sys.argv) == 2:
    print("Usage: ZeusCreateProject workSpaceName")
    exit(0)

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ===========================================================================
# EDIT THIS SECTION FOR YOUR PARTICULAR SETUP
#
# List your clients:
#           p4 client : path
clients = { "p4"      : "e:\\p4",
            "p41"     : "e:\\p41",
          }

# list common paths of interest - exclude the client prefix path
dirCommonStr = "\\depot\\"  # common prefix for paths in dirPath

# list the directories to include in the project (all files are taken)
# (remove the dirCommonStr common part)
dirPath = [ "src\\common",
            "src\\drivers",
            "inc\\",
          ]
#
# dir path = clients[ <p4Client> ] + dirCommonStr + dirPath[ i ]
#
# End of User Edit
# ===========================================================================
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

def makenode(path):
    "Return a document node contains a directory tree for the path."
    node = doc.createElement('Folder')
    node.setAttribute('name', path)
    for f in os.listdir(path):
        fullname = os.path.join(path, f)
        if os.path.isdir(fullname):
            elem = makenode(fullname)
        else:
            elem = doc.createElement('file')
            ee1 = doc.createTextNode( fullname )
            elem.appendChild(ee1)
            #elem.appendChild( e )
            #elem = doc.createElement('file')
            #elem.setAttribute('name', fullname)
        node.appendChild(elem)
    return node

workSpaceName = sys.argv[1]

for client in clients.keys():
    i = 0
    for line in dirPath:  # line = directory path
        istr = "_%s_%d" % (client, i)
        i += 1
        line = clients[client] + dirCommonStr + line
        print line+"\n"
        file_FileList = open(client+istr+".xlst", "w")
        doc = Document()
        doc.appendChild(makenode(line.rstrip("\n")))
        doc.writexml(file_FileList, addindent=' ', newl='\n')
        file_FileList.close()

# create the final files list file
i = 0
for client in clients.keys():
    outFile = open(client+".zlst", "w")
    i = inSubFolder = 0
    outFile.write('<Project name="%s" sorted="Yes">\n' % client)
    for line in dirPath:  # line = directory path
        istr = "_%s_%d" % (client, i)
        i += 1
        file_FileList = open(client+istr+".xlst", "r")
        inSubFolder = 0
        for ll in file_FileList:
            # next we will chop some of the redundancy out of the folder names
            if ll.find("</Folder>") >= 0:
                inSubFolder -= 1
                if inSubFolder < 0:
                    inSubFolder = 0
            if ll.find("Folder name") >= 0:
                inSubFolder += 1
                ll = ll.replace( clients[client]+dirCommonStr, "...")
                # subfolders only have last directory entry
                if inSubFolder >=2:
                    ll = ll[:ll.index("=")+2] + ll[ll.rindex("\\")+1:]
            # delete these lines
            if not ll.find("?xml version") > 0:
                outFile.write( ll )
        file_FileList.close()
    outFile.write('</Project>\n')
    outFile.close()

activeSet = False
#now create the workspace file
fWorkSpace = open(workSpaceName+".zwi", "w")
fWorkSpace.write('<!-- Workspace file for the Zeus for Windows IDE - http://www.zeusedit.com -->\n')
fWorkSpace.write('<Workspace name="%s" sorted="Yes">\n' % workSpaceName)
fWorkSpace.write('    <Mode>Debug</Mode>\n')
for client in clients.keys():
    if not activeSet:
        fWorkSpace.write('    <Active>%s</Active>\n' % client)
        activeSet = True
    fWorkSpace.write('    <Project name="%s">%s</Project>\n' % (client,client+".zlst")  )
fWorkSpace.write('</Workspace>')
fWorkSpace.close()

#remove all the temp files
for client in clients.keys():
   i = 0
   for line in dirPath:  # line = directory path
       istr = "_%s_%d" % (client, i)
       os.remove(client+istr+".xlst")
       i += 1


Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests