Exemple #1
0
    def ParseDirectories(self, category, component, branch):
        if not category:
            self.mDirectories.extend(
                Perforce.GetDirectories('//SEABU/ProductSource'))
        else:
            self.mDirectories.append('//SEABU/ProductSource/%s' % category)

        if not component:
            categories = self.mDirectories
            self.mDirectories = []
            for dir in categories:
                self.mDirectories.extend(Perforce.GetDirectories(dir))
        else:
            categories = self.mDirectories
            self.mDirectories = []
            for dir in categories:
                self.mDirectories.append('%s/%s' % (dir, component))

        if not branch:
            components = self.mDirectories
            self.mDirectories = []
            for dir in components:
                self.mDirectories.extend(Perforce.GetDirectories(dir))
        else:
            components = self.mDirectories
            self.mDirectories = []
            for dir in components:
                self.mDirectories.append('%s/%s' % (dir, branch))
Exemple #2
0
def initializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)
    try:
        print "Adding Perforce Menu"
        Perforce.init()
    except:
        sys.stderr.write( "Failed to register command: %s\n" % kPluginCmdName )
        raise
Exemple #3
0
def uninitializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)
    try:
        print "Removing Perforce Menu"
        Perforce.close()
    except Exception as e:
        print e
        sys.stderr.write( "Failed to unregister command: %s\n" % kPluginCmdName )
Exemple #4
0
def GrepFile(search, filename, ignoreCase):
    if not Perforce.IsFileInDepot(filename):
        print(('ERROR: %s is not in the depot.' % filename))
        return

    contents = Perforce.GetFileContents(filename)
    if ignoreCase:
        regex = re.compile(search, re.I | re.S)
    else:
        regex = re.compile(search, re.S)

    for match in regex.finditer(contents):
        print(('%s %s' % (filename, PrintMatch(match))))
    def EliminateIncludes(self):
        pattern = r'(?<!//)#\s*include ["<][^">]*[">].*'
        regex = re.compile(pattern)

        for header in self.mHeaders:
            file = open(header, 'r')
            data = file.read()
            file.close()
            match = regex.search(data)
            if match and Perforce.OpenForEdit(header):
                while match:
                    begin = match.start()

                    file = open(header, 'w')
                    file.write(data[:begin] + '//' + data[begin:])
                    file.close()

                    sourceFile = os.path.join(os.path.dirname(header),
                                              'EliminateIncludes.cpp')
                    file = open(sourceFile, 'w')
                    file.write('#include "%s"\n' % os.path.basename(header))
                    file.close()

                    if self.Compile(sourceFile) == 0:
                        data = data[:begin] + '//' + data[begin:]
                    else:
                        file = open(header, 'w')
                        file.write(data)
                        file.close()

                    os.remove(sourceFile)
                    match = regex.search(data, match.end())
def AddX64Configuration(filename):
    file = open(filename, 'r')
    text = file.read()
    file.close()

    last = 0
    vcproj = ''
    pattern = '(\t+<Platform\n\t+Name=)"Win32"(\n\t+/>\n)'
    regex = re.compile(pattern, re.I | re.S)
    match = regex.search(text)
    if match:
        vcproj += text[:match.end()] + match.group(1) + '"x64"' + match.group(
            2)
        last = match.end()

    pattern = '(?:\t+<(?:file)?configuration\s+name="(?:debug|release)\|win32"\s+)(?:.*?)(?:</(?:file)?configuration>\n)'
    regex = re.compile(pattern, re.I | re.S)
    match = regex.search(text, last)
    found = match != None

    while match:
        vcproj += text[last:match.end()] + CreateX64Configuration(
            text[match.start():match.end()])
        last = match.end()
        match = regex.search(text, last)

    if found and Perforce.OpenForEdit(filename):
        vcproj += text[last:]
        file = open(filename, 'w')
        file.write(vcproj)
        file.close()
def RemoveWin64Configuration( filename ):
    file = open( filename, 'r' )
    text = file.read()
    file.close()
    
    pattern = '\t+StripPrivateSymbols *= *"[^"]+"\n'
    regex = re.compile( pattern, re.I |re.S )
    newtext = regex.sub('', text)

    if text != newtext and Perforce.OpenForEdit( filename ):
        file = open( filename, 'w' )
        text = file.write(newtext)
        file.close()
def RemoveDetect64BitPortabilityProblems( filename ):
    file = open( filename, 'r' )
    text = file.read()
    file.close()
    
    pattern = r'\t+Detect64BitPortabilityProblems="[^"]+"[^\n]*\n'
    regex = re.compile( pattern, re.I |re.S )
    newtext = regex.sub('', text)
    
    if newtext != text and Perforce.OpenForEdit( filename ):
        file = open( filename, 'w' )
        file.write( newtext )
        file.close()
Exemple #9
0
def UpdateVcProj(filename, compilerRegex, linkerRegex):
    file = open( filename, 'r' )
    org_text = file.read()
    file.close()
    new_text = org_text
    
    boost = FindBoostPath(filename)
    new_text = UpdateCompilerSettings(new_text, boost, compilerRegex)
    new_text = UpdateLinkerSettings(new_text, boost, linkerRegex)
    if new_text != org_text:
        print(('Updating %s' % filename))
        Perforce.OpenForEdit(filename)
        file = open( filename, 'w' )
        file.write(new_text)
        file.close()
    def __init__(self, path, cfg):
        self.mName = os.path.basename(path)
        self.mPath = path
        self.mConfig = cfg
        self.mProjects = {}

        regex = re.compile('^.*\.(?:h|hpp|c|cpp)$', re.I)
        devdir = os.path.join(self.mPath, 'Dev')

        for root, dirs, files in os.walk(devdir):
            for dir in dirs:
                if dir.lower() == cfg.lower():
                    keyname = root.lower
                    self.mProjects[keyname] = Project(root, cfg)
                    print(root)
                    for file in files:
                        filename = os.path.join(root, file)
                        if regex.match(filename) and Perforce.IsFileInDepot(
                                filename):
                            self.mProjects[keyname].AddFile(filename)
def RemoveWin64Configuration( filename ):
    file = open( filename, 'r' )
    text = file.read()
    file.close()
    
    #pattern = '(?P<pre><(?:file)?configuration\s+name="(?:debug|release)\|x64"\s+)(?P<config>.*?)(?P<post></(?:file)?configuration>)'
    pattern = '(?:\t+<(?:file)?configuration\s+name="win64 (?:debug|release)\|win32"\s+)(?:.*?)(?:</(?:file)?configuration>\n)'
    regex = re.compile( pattern, re.I |re.S )
    match = regex.search( text )
    found = match != None

    while match:
        begin = match.start()
        end = match.start() + len( match.group(0) )
        text = text[ : begin ] + text[ end : ]
        match = regex.search( text )

    if found and Perforce.OpenForEdit( filename ):
        file = open( filename, 'w' )
        file.write( text )
        file.close()
Exemple #12
0
def UpdateVCProj(filename):
    file = open(filename, 'r')
    lines = file.readlines()
    file.close()

    basename = filename[filename.rfind('\\') + 1:len(filename)]

    if Perforce.OpenForEdit(filename) == False:
        return

    print(('Processing file "' + basename + '"'))
    file = open(filename, 'w')

    insideConfig = False
    insideFileConfig = False
    insideWin64 = False

    for line in lines:

        if line.strip().lower() == '<configuration':
            insideConfig = True

        elif line.strip().lower() == '<fileconfiguration':
            insideFileConfig = True

        elif( insideConfig or insideFileConfig ) and \
             line.strip().lower().find( 'name="win64' ) != -1:
            insideWin64 = True
            insideConfig = False
            insideFileConfig = False

        elif insideWin64 and \
             ( line.strip().lower() == '</configuration>' or \
               line.strip().lower() == '</fileconfiguration>' ):
            insideWin64 = False
            insideConfig = False
            insideFileConfig = False

        elif insideWin64:
            continue

        elif insideConfig or insideFileConfig:
            if insideConfig:
                file.write('\t\t<Configuration\n')
                insideConfig = False
            elif insideFileConfig:
                file.write('\t\t\t\t<FileConfiguration\n')
                insideFileConfig = False

            if line.strip().find('x64'):
                line = line.replace('x64', 'Win64-x64')

            file.write(line)

        elif not insideWin64 and line.strip().find('x64'):
            line = line.replace('x64', 'Win64-x64')
            file.write(line)

        else:
            file.write(line)

    file.close()
Exemple #13
0
def UpdateMainCpp(filename):
    file = open(filename, 'r')
    lines = file.readlines()
    file.close()

    if Perforce.OpenForEdit(filename) == False:
        return

    print(('Processing file "' + filename + '"'))
    file = open(filename, 'w')
    updated = False
    deleteBlankSpaces = False
    foundUnitMain = False

    for line in lines:

        if not updated and line.strip().lower(
        ) == '#include "base/dev/cppunit/cppunitmain.h"':
            file.write('#define _CRTDBG_MAP_ALLOC\n')
            file.write('#include <stdlib.h>\n')
            file.write('#include <crtdbg.h>\n')
            file.write(line)
            foundInclude = True

        elif not updated and deleteBlankSpaces and line.strip() == '':
            continue

        elif not updated and deleteBlankSpaces and line.strip().lower(
        ) == 'int main( int argc, char * argv[] )':
            file.write(line)
            deleteBlankSpaces = False
            continue

        elif not updated and line.strip().lower(
        ) == '#include "base/dev/timing.h"':
            file.write(line + '\n')
            deleteBlankSpaces = True

        #elif foundInclude and line.strip() == '':
        #    file.write( '#include "Base/Dev/Timing.h"\n' )
        #    file.write( line )
        #    foundInclude = False

        elif line.strip().lower().find( '_crtdbg_map_alloc' ) != -1 or \
             line.strip().lower().startswith( '_crtsetdbgflag' ):
            file.write(line)
            updated = True

        elif not updated and line.strip().lower(
        ) == 'cleartimers(log_if_data, "before testrunner");':
            if not foundUnitMain:
                file.write(
                    '\t_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );\n\n'
                )
            else:
                line = line.replace('Before', 'After')
                foundUnitMain = False
            file.write(line)

        elif not updated and line.strip().lower(
        ) == 'cppunitmain( argc, argv );':
            file.write(line)
            foundUnitMain = True

        #elif not updated and line.strip().lower() == 'return 0;':
        #    file.write( '\tClearTimers(LOG_IF_DATA, "Before TestRunner");\n' )
        #    file.write( '\tg_pTimingManager->PreserveTransientTimers();\n' )
        #    file.write( line )

        else:
            file.write(line)

    file.close()
Exemple #14
0
def UpdateVCProj(filename):
    file = open(filename, 'r')
    lines = file.readlines()
    file.close()

    basename = filename[filename.rfind('\\') + 1:len(filename)]
    if basename.lower().startswith('z_'):
        return

    if Perforce.OpenForEdit(filename) == False:
        return

    print(('Processing file "' + basename + '"'))
    file = open(filename, 'w')

    bInsideConfig = False
    bFoundConfig = False
    release = False
    bInsideCompilerTool = False
    bInsideLinkerTool = False
    bInsideLibrarianTool = False
    foundCompilerOptimizations = False
    foundLinkerOptimizations = False
    foundLibrarianOptimizations = False

    for line in lines:

        if bFoundConfig == False and line.strip().upper() == '<CONFIGURATION':
            #print 'Found a configuration section'
            file.write(line)
            bFoundConfig = True

        elif bFoundConfig and line.strip().upper().startswith('NAME="'):
            file.write(line)
            if line.strip().upper() == 'NAME="RELEASE|WIN32"':
                #print 'Found the release win32 configuration section'
                bInsideConfig = True
            else:
                #print 'Not a valid configuration section'
                bInsideConfig = False
            bFoundConfig = False

        elif bInsideConfig and line.strip().upper() == '</CONFIGURATION>':
            file.write(line)
            release = False
            bInsideCompilerTool = False
            bInsideLinkerTool = False
            bInsideConfig = False
            bInsideLibrarianTool = False

        elif bInsideConfig and line.strip() == 'Name="VCLinkerTool"':
            #print 'Found begin of linker tool'
            file.write(line)
            bInsideLinkerTool = True
            bInsideCompilerTool = False
            bInsideLibrarianTool = False

        #elif bInsideConfig and bInsideLinkerTool and \
        #     line.strip().startswith( 'LinkIncremental=' ):
        #    #print 'Found LinkIncremental in linker tool'
        #    if line.strip().endswith( '"2"' ):
        #        line = line.replace( '2', '1' )
        #    file.write( line )

        elif bInsideConfig and bInsideLinkerTool and \
             line.strip().startswith( 'LinkTimeCodeGeneration=' ):
            #print 'Removing LinkTimeCodeGeneration in linker tool'
            #file.write( line )
            foundLinkerOptimizations = True

        elif bInsideConfig and bInsideLinkerTool and line.strip().find(
                '/>') != -1:
            #print 'Found end of linker tool'
            if foundLinkerOptimizations == False:
                print('Didn\'t find any linker optimizations')
            #    file.write( '\t\t\t\tLinkTimeCodeGeneration="1"\n' )
            file.write(line)
            bInsideCompilerTool = False
            bInsideLinkerTool = False

        elif bInsideConfig and line.strip() == 'Name="VCLibrarianTool"':
            #print 'Found begin of compiler tool'
            file.write(line)
            bInsideCompilerTool = False
            bInsideLinkerTool = False
            bInsideLibrarianTool = True

        elif bInsideConfig and bInsideLibrarianTool and \
             line.strip().startswith( 'AdditionalOptions=' ):
            #print 'Found LinkTimeCodeGeneration in librarian tool'
            if line.strip().upper().find('/LTCG') == -1:
                print(
                    'Didn\'t find LinkTimeCodeGeneration in librarian tool additional options'
                )
                file.write(line)
            else:
                if line.strip().upper().find(' /LTCG') != -1:
                    line = line.replace(' /LTCG', '')
                    file.write(line)
                #    print line
                #else:
                #    print 'AdditionalOptions="/LTCG" removed'
                foundLibrarianOptimizations = True

        elif bInsideConfig and bInsideLibrarianTool and line.strip().find(
                '/>') != -1:
            #print 'Found end of librarian tool'
            if foundLibrarianOptimizations == False:
                print('Didn\'t find any librarian optimizations')
            #    file.write( '\t\t\t\tAdditionalOptions="/LTCG"\n' )
            file.write(line)
            bInsideCompilerTool = False
            bInsideLinkerTool = False
            bInsideLibrarianTool = False

        elif bInsideConfig and line.strip() == 'Name="VCCLCompilerTool"':
            #print 'Found begin of compiler tool'
            file.write(line)
            bInsideCompilerTool = True
            bInsideLinkerTool = False
            bInsideLibrarianTool = False

        elif bInsideConfig and bInsideCompilerTool and \
             line.strip().startswith( 'WholeProgramOptimization=' ):
            #print 'Removing WholeProgramOptimization in compiler tool'
            #print 'Found WholeProgramOptimization in compiler tool'
            #file.write( line )
            foundCompilerOptimizations = True

        elif bInsideConfig and bInsideCompilerTool and line.strip().find(
                '/>') != -1:
            #print 'Found end of compiler tool'
            if foundCompilerOptimizations == False:
                print(
                    'Didn\'t find WholeProgramOptimization in the compiler tool'
                )
                #file.write( '\t\t\t\tWholeProgramOptimization="true"\n' )
            file.write(line)
            bInsideCompilerTool = False
            bInsideLinkerTool = False
            bInsideLibrarianTool = False

        #if line.strip().lower().startswith( 'additionalincludedirectories' ) and \
        #   line.lower().find( 'boost' ) == -1 and \
        #   line.lower().find( 'vs.net' ) != -1:
        #    index = line.lower().find( 'vs.net' )
        #    addition = ';' + line[ line.rfind( ';', 0, index ) + 1 : index ] + 'Boost'
        #    line = line[ 0 : line.rfind('"') ] + addition + line[ line.rfind('"') : len( line ) ]
        #    file.write( line )
        #    print line.strip()

        else:
            file.write(line)

    file.close()
import os, sys, re, Perforce, Utils
import win32api, win32file


def IsFileWritable(file):
    return win32api.GetFileAttributes(
        file) & win32file.FILE_ATTRIBUTE_READONLY == 0


def IsFileOpened(name):
    return IsFileWritable(name) and Perforce.IsFileInDepot(name)


if __name__ == '__main__':
    dir = os.getcwd()
    files = Perforce.GetOpenedFiles(dir, Utils.FindSandbox(dir))
    for i in range(len(files)):
        files[i] = files[i].lower()

    for name in Utils.RecurseDirectory(dir, IsFileOpened):
        if not name.lower() in files:
            attribs = win32api.GetFileAttributes(name)
            win32api.SetFileAttributes(
                name, attribs | win32file.FILE_ATTRIBUTE_READONLY)
            print(('Resetting read-only on the file %s.' % name))
Exemple #16
0
    #print 'version = %s' % version
    #print 'branch = %s' % branch
    #print 'category = %s' % category
    #print 'path = %s' % path
    #print 'ignoreCase = %s' % ignoreCase
    #print 'componentsTxt = %s' % componentsTxt

    startTime = datetime.datetime.now()
    Utils.PrintTiming(startTime, None, verbose)

    locations = SearchLocations()
    if path:
        locations.AddDirectory(path)
    else:
        locations.ParseDirectories(category, component, branch)

    if componentsTxt:
        for dir in locations.GetDirectories():
            path = dir
            if not path.endswith('/'):
                path += '/'
            if not path.lower().endswith('components.txt'):
                path += 'Components.txt'
            GrepFile(search, path, ignoreCase)
    else:
        for dir in locations.GetDirectories():
            for file in Perforce.GetFiles(dir):
                GrepFile(search, file, ignoreCase)

    Utils.PrintTiming(startTime, datetime.datetime.now(), verbose)
def IsFileOpened(name):
    return IsFileWritable(name) and Perforce.IsFileInDepot(name)
        sys.exit(2)

    return os.path.normpath(
        os.path.abspath(dir)), backup, change, restore, revert, exceptions


#def IsNotReadOnly( file ):
#    return win32api.GetFileAttributes( file ) & win32file.FILE_ATTRIBUTE_READONLY == 0

if __name__ == '__main__':

    PrintHeader(sys.stdout)

    dir, backup, change, restore, revert, exceptions = ParseArgs(sys.argv)
    sandbox = FindSandbox(os.getcwd())
    perforce = Perforce.Perforce()

    if backup:
        CreateDestination(dir)
        if change:
            files = perforce.GetChangeListFiles(change, os.getcwd(), sandbox)
        else:
            files = perforce.GetOpenedFiles(os.getcwd(), sandbox)
        for file in files:
            #for file in RecurseDirectory( os.getcwd(), IsNotReadOnly ):
            if file.lower() not in exceptions:
                CopyOpenedFile(perforce, file, sandbox, dir, False)
                if revert:
                    perforce.Revert(file)
    else:
        for file in RecurseDirectory(dir):
Exemple #19
0
import os, sys, re, Utils, Perforce

def IsProjectFile( file ):
    return not re.search('wsfiles', file, re.I) and re.match(r'^.*\.vcproj$', file, re.I)

if __name__ == '__main__':
    
    for file in Utils.RecurseDirectory( os.getcwd(), IsProjectFile, False ):
        Perforce.OpenForEdit(file)