• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Script to add/change prefixes projectwide (AGAIN)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Script to add/change prefixes projectwide (AGAIN)


  • Subject: Script to add/change prefixes projectwide (AGAIN)
  • From: Drew McCormack <email@hidden>
  • Date: Sat, 3 May 2003 19:55:40 +0200

Sorry, I didn't realize attachments could not be sent to the list. Here is the script in text:




#!/usr/bin/env python

import os
import re
import string

#------------------
# Config
#------------------
oldPrefix = "" # Set to empty string if there is no old prefix
newPrefix = "NRT"

# Must be fully matched, and distinct (ie not a part of another alphanumeric string) to be prefixed
# Typically you put all classes, protocols, and informal protocols here.
fullStringsToPrefix = string.split( """AffineTransform CompositeTransform Linear1DTransform PlotViewComponent
Annotation CoordinateIdentifiers OHLCClusterGraphic ScatterPlot
Axis DataClusterGraphic OrthogonalTransform StraightAxis AxisLabel
DataClusterIdentifiers Plot StraightTick AxisTick Defines PlotArea
SymbolClusterGraphic AxisTitle Discretizer PlotAreaComponent Transform
BarClusterGraphic FloatRange PlotDataSource XYChart ChainedTransform
FloatRangeDiscretizer PlotObject Chart GeneralIdentifiers PlotView
ChartAttributeStrings IrreducibleTransform PlotViewAnnotation PlotDataSourceInformalProtocol""" )

# Must match beginning of title to be prefixed
# This may be used if you have strings that all begin in the same way, for example, and which
# require prefixing.
stringBeginningsToPrefix = string.split( """PlotAreaFrame PlotAreaBackground ChartBackground
Title BottomXAxis TopXAxis LeftYAxis RightYAxis""" )

# Must match end of title to be prefixed
# This may be used if you have strings that all end in the same way, for example, and require
# prefixing.
stringEndingsToPrefix = [ ]

# Files matching this expression will can have their name prefixed
prefixFileExpr = r'\w+\.(h|m|mm|c)'

# Root directories
origRootDir = "/Users/drew/Python/Prefixer/Narrative"
newRootDir = "/Users/drew/Python/Prefixer/NarrativeNew"

#------------------
# Algorithm
#------------------

# Prefix strings in files in a single directory
def treatDirectory(arg, dirName, names):

dirRelativeToRoot = dirName[len(origRootDir):]
destDir = newRootDir + dirRelativeToRoot

if not os.path.exists(destDir): os.mkdir(destDir)

for fileName in names:
fromPath = dirName + "/" + fileName

if re.match(prefixFileExpr, fileName) and oldPrefix == fileName[0:len(oldPrefix)]:
toPath = destDir + "/" + newPrefix + fileName[len(oldPrefix):]
else:
toPath = destDir + "/" + fileName

if os.path.isfile(fromPath):
fromFile = open(fromPath, 'r')
toFile = open(toPath, 'w')

for line in fromFile.readlines():
newline = line

for fullString in fullStringsToPrefix:
matchString = r'\b' + oldPrefix + fullString + r'\b'
newline = re.sub( matchString, newPrefix + fullString, newline )

for beginString in stringBeginningsToPrefix:
matchString = r'\b' + oldPrefix + beginString
newline = re.sub( matchString, newPrefix + beginString, newline )

for endString in stringEndingsToPrefix:
matchString = r'\b' + oldPrefix + r'(\w+)' + endString + r'\b'
newline = re.sub( matchString, newPrefix + r'\1' + endString, newline )

toFile.write(newline)

fromFile.close()
toFile.close()



# Create new dir if necessary
if not os.path.exists(newRootDir): os.mkdir(newRootDir)

# Walk over all files in original directory
os.path.walk(origRootDir, treatDirectory, None)



----------------------------------
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Stock Market strategy design platform for Mac OS X.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Script to add/change prefixes projectwide
  • Next by Date: Printing documents
  • Previous by thread: Script to add/change prefixes projectwide
  • Next by thread: Printing documents
  • Index(es):
    • Date
    • Thread