Odd COM problems with VC
Harry George
hgg9140 at seanet.com
Wed Mar 8 18:45:42 EST 2000
Interesting script. I have something similar. I wonder how many
there are out there?
roger.burnham at gte.net (Roger Burnham) writes:
>
> I have a script to automate building all my projects:
> ----------------------------------------------------------
Here's another one:
#!/usr/bin/env python
#
#/* mkpythonproj
# * Copyright (C) %(year)d %(author)s
# *
# * This library is free software; you can redistribute it and/or
# * modify it under the terms of the GNU Library General Public
# * License as published by the Free Software Foundation; either
# * version 2 of the License, or (at your option) any later version.
# *
# * This library is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# * Library General Public License for more details.
# *
# * You should have received a copy of the GNU Library General Public
# * License along with this library; if not, write to the
# * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# * Boston, MA 02111-1307, USA.
# */
"""
NAME:
mkpythonproj
USAGE:
mkpythonproj [options] projname
OPTIONS:
-h, --help this message
-v, --version print version
-a:xyz, --author=xyz set author to xyz
-p, --proj make a full project, not just a script
-s, --setup just make a new setup.py
EXAMPLES:
mkpythonproj myproj
make a simple script:
myproj.py
mkpythonproj -p --author="John Doe" myproj
make a full project:
AUTHORS
COPYING
MANIFEST
RCS
README
VERSION
myproj.py
setup.py
go
doc/
go
deshist.pdx,html
devguide.pdx,html
manual.prd,html
index.pdx,html
test/
go
mkpythonproj -s --author="Joe Doe" myproj
make a new setup.py (needed if the setup process has changed)
"""
#===imports=================
import sys,os,time,getopt,string,commands;
from cStringIO import StringIO
#==globals==================
modname="mkpythonproj"
__version__="0.3"
author="anonymous"
projname=""
progname=""
rootdir=os.getcwd()
project_p=0
setup_p=0 # setup.py only
(year,month,day,hour,minute,second,
weekday,julianday,daylight)=time.localtime(time.time())
timestamp="%04.4d-%02.2d-%02.2d" % (year,month,day)
#===utilities===============
def debug(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':',txt,'\n'],''))
sys.stdout.flush()
def fatal(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':FATAL:',txt,'\n'],''))
sys.stdout.flush()
sys.exit(1)
def usage():
print __doc__
#===functions===============
def mkdirs():
ftn= "mkdirs"
os.mkdir(projname,0755)
os.chdir(projname)
os.mkdir("RCS",0755)
def mkcopying():
f=open("COPYING","w")
msg="""
(GPL statement goes here)
"""
f.write(msg)
f.close()
def mkauthors():
ftn="mkauthors"
f=open("AUTHORS","w")
msg="""
AUTHORS
Name E-mail Role
---------------- ------------------------- -------------------------------
%(author)s initial development
"""
f.write(msg % {'author':author})
f.close()
#-----------------
def mkreadme():
ftn="mkreadme"
f=open("README","w")
msg="""
README for %(projname)s
"""
f.write(msg % {'projname':projname})
f.close()
#-----------------
def mkversion():
ftn="mkversion"
f=open("VERSION","w")
f.write("0.1")
f.close()
#-----------------
def mkmanifest():
ftn="mkmanifest"
f=open("MANIFEST","w")
msg="""
AUTHORS
COPYING
MANIFEST
README
VERSION
setup.py
%(progname)s
doc/go
doc/devguide.pdx
doc/devguide.html
doc/manual.pdx
doc/manual.html
doc/deshist.pdx
doc/deshist.html
test/go
"""
f.write(msg % {'progname':progname})
f.close()
#-----------------
def mktest():
ftn = "mktest"
currdir=os.getcwd()
os.mkdir("test")
os.chdir("test")
file=open("go","w")
file.write("../"+progname+"\n")
file.close()
os.chmod("go",0755)
os.chdir(currdir)
#-----------------
def mksetup(filename='setup.py'):
ftn = "mksetup"
file=open(filename,"w")
msg="""
\"\"\"
Name:
setup.py
Usage:
python setup.py [--help] [--prefix=path] [--exec_prefix=path]
[build | test | install | doc]
Options:
--help this message
--prefix=xyz path prefix for lib/python1.5
--exec_prefix=xyz path prefix for bin/
build make the package
test test the package
install (typically done as root) install in site-packages
doc generate the documents
mkdist make a versioned distribution tar.gz file
Examples:
cd mydir
(cp myfile.tar.gz here)
gzip -cd myfile.tar.gz | tar xvf -
cd myfile
python setup.py build
python setup.py test
python setup.py install
python setup.py doc
python setup.py mkdist
\"\"\"
#===configuration=============
import os,sys,re,string,getopt,shutil,commands
from cStringIO import StringIO
pkgname='%(projname)s'
modname='setup.py'
prefix=sys.prefix
exec_prefix=sys.exec_prefix
site_packages_suffix='lib/python1.5/site-packages'
pkgfiles=['__init__.py','%(progname)s']
binscripts=['%(progname)s']
#=============================
#--------------------
def debug(ftn,txt):
sys.stdout.write(modname+'.'+ftn+':'+txt+'\\n')
sys.stdout.flush()
#--------------------
def fatal(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':FATAL:',txt,'\\n'],''))
sys.stdout.flush()
sys.exit(1)
#--------------------
def usage():
print __doc__
#--------------------
def do_build():
ftn="do_build"
debug(ftn,"begin")
for script in binscripts:
os.chmod(script,0755)
os.chmod("doc/go",0755)
os.chmod("test/go",0755)
#--------------------
def do_test():
ftn="do_test"
debug(ftn,"begin")
os.chdir("test")
os.system("go")
#--------------------
def do_install():
ftn="do_install"
debug(ftn,"begin")
#---scripts go to bin---
bindir=os.path.join(exec_prefix,"bin")
for script in binscripts:
shutil.copy(script,bindir)
#---package files go to site-packages---
ispackage="__init__.py" in pkgfiles
sitedir=os.path.join(prefix,site_packages_suffix)
if ispackage:
pkgdir=os.path.join(sitedir,pkgname)
else:
pkgdir=sitedir
if not os.path.exists(pkgdir):
os.makedirs(pkgdir)
if ispackage:
pthname=os.path.join(sitedir,pkgname,".pth")
pthfile=open(pthname,'w')
pthfile.write(pkgname+'\\n')
pthfile.close()
for pkgfile in pkgfiles:
shutil.copy(pkgfile,pkgdir)
#----------------------
def do_doc():
ftn="do_doc"
debug(ftn,"begin")
os.system("cd doc; go")
#----------------------
def do_dist():
ftn="do_dist"
debug(ftn,"begin")
#---get version and make names---
version=string.strip(open("VERSION","r").readline())
pkgversion=pkgname+'-'+version
tarname=pkgversion+'.tar'
gzipname=tarname+'.gz'
#---freeze RCS---
if os.path.exists("RCS"):
still_locked=commands.getoutput("rlog -L -R RCS/*")
if len(still_locked) > 0:
debug(ftn,"files still locked\\n"+`still_locked`)
fatal(ftn,"checkin files before doing mkdist")
rcs_version=re.sub('\.','_',version)
cmd="rcs -sStab -Nv"+rcs_version+": RCS/*"
#debug(ftn,"cmd="+cmd)
os.system(cmd)
#---clear out the old dir---
if os.path.exists(pkgversion):
shutil.rmtree(pkgversion)
#---copy manifest files into newdir---
f=open("MANIFEST","r")
files=f.readlines()
f.close()
for file in files:
file=string.strip(file)
if os.path.exists(file):
newfile=os.path.join(pkgversion,file)
head,tail=os.path.split(newfile)
if not os.path.exists(head):
os.makedirs(head)
shutil.copyfile(file,newfile)
#---make the tar file---
cmd1="tar cvfp "+tarname+" "+pkgversion
os.system(cmd1)
#---gzip it---
if os.path.exists(gzipname):
os.remove(gzipname)
cmd2='gzip '+tarname
os.system(cmd2)
#==============================
if __name__ == '__main__':
opts,pargs=getopt.getopt(sys.argv[1:],'hve:p:',
['help','version','exec_prefix=','prefix'])
for opt in opts:
if opt[0]=='-h' or opt[0]=='--help':
usage()
sys.exit(0)
elif opt[0]=='-v' or opt[0]=='--version':
print modname+": version="+version
elif opt[0]=='-e' or opt[0]=='--exec_prefix':
exec_prefix=opt[1]
elif opt[0]=='-p' or opt[0]=='--prefix':
prefix=1
for arg in pargs:
if arg=='build':
do_build()
elif arg=='test':
do_test()
elif arg=='install':
do_install()
elif arg=='doc':
do_doc()
elif arg=='mkdist':
do_dist()
else:
debug(ftn,"unknown arg |"+arg+'|')
usage()
sys.exit(0)
"""
file.write(msg % {'projname':projname,'progname':progname})
file.close()
os.chmod(filename,0755)
#-----------------
def mkdoc():
ftn = "mkdoc"
currdir=os.getcwd()
os.mkdir("doc")
os.chdir("doc")
file=open("go","w")
progpath=os.path.join(os.pardir,progname)
file.write("%s -h > %s.help\n" % (progpath,projname))
file.write("pdx2html.py index.pdx\n")
file.write("pdx2html.py deshist.pdx\n")
file.write("pdx2html.py manual.pdx\n")
file.write("pdx2html.py devguide.pdx\n")
file.close()
os.chmod("go",0755)
#---index.pdx---
file=open("index.pdx","w")
msg = """\
=include default_cfg.pdx
=cfg
title=%(projname)s Home page
toc_p=0
=end cfg
=include article_style.pdx
=head1 NAME
%(progname)s
=head1 USAGE
=verbatim
%(progname)s [options] args
=end verbatim
=head1 DESCRIPTION
(fill in...)
=head1 OPTIONS
#=include_verbatim %(projname)s.help
=head1 EXAMPLES
=verbatim
%(progname)s --help
=end verbatim
=head1 SEE ALSO
=list *
=item L<"manual.html","User manual">
=item L<"devguide.html","Developer's Guide">
=item L<"deshist.html","Design History">
=end list
"""
file.write(msg % {'progname':progname,'projname':projname,'timestamp':timestamp});
file.close()
#---default_cfg.pdx---
file=open("default_cfg.pdx","w")
msg = """\
=cfg
banner==<Center>%(projname)s</CENTER>
author = %(author)s
author_email= %(author)s at www.com
body==<BODY BGCOLOR="#ffffff" TEXT="#000000" LINK="#0000ff" VLINK="#990099" ALINK="#FF0000">
robots==none
toc_p=1
=end cfg
"""
file.write(msg % {'author':author,'projname':projname,'timestamp':timestamp});
file.close()
#---design history---
file=open("deshist.pdx","w")
msg = """\
=include default_cfg.pdx
=cfg
title=%(projname)s Design History
toc_p=1
=end cfg
=include article_style.pdx
=head1 %(timestamp)s
"""
file.write(msg % {'projname':projname,'timestamp':timestamp});
file.close()
#---user manual---
file=open("manual.pdx","w")
msg = """\
=include default_cfg.pdx
=cfg
title=%(projname)s User Manual
toc_p=1
=end cfg
=include article_style.pdx
=head1 Overview
=head1 Installation
=head1 Quick Start
=head1 Tutorial
=head1 Reference
"""
file.write(msg % {'projname':projname,'timestamp':timestamp});
file.close()
#---developer's guide---
file=open("devguide.pdx","w")
msg = """\
=include default_cfg.pdx
=cfg
title=%(projname)s Developer's Guide
toc_p=1
=end cfg
=include article_style.pdx
=head1 Overview
=head1 Architecture
"""
file.write(msg % {'projname':projname,'timestamp':timestamp});
file.close()
#---return to rootdir---
os.chdir(currdir)
#-----------------------------------
def mkmodule():
ftn="mkmodule"
file=open(progname,"w")
body="""#!/usr/bin/env python
#/* %(progname)s
# * Copyright (C) %(year)d %(author)s
# *
# * This library is free software; you can redistribute it and/or
# * modify it under the terms of the GNU Library General Public
# * License as published by the Free Software Foundation; either
# * version 2 of the License, or (at your option) any later version.
# *
# * This library is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# * Library General Public License for more details.
# *
# * You should have received a copy of the GNU Library General Public
# * License along with this library; if not, write to the
# * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# * Boston, MA 02111-1307, USA.
# */
\"\"\"
NAME:
%(progname)s
Usage:
%(progname)s [options] filename
OPTIONS:
-h,--help this message
-v,--version version
-a,--aa set boolean 'a'
-b,--bb set option bb to xyz
EXAMPLES:
%(progname)s --aa --bb=xyz myfile
\"\"\"
#===imports======================
import sys,os,getopt,time,re,string,exceptions
#import parentclass
#===globals======================
modname=\"%(projname)s\"
__version__="0.1"
#---to use the VERISON file, uncomment next line
#__version__=open("VERSION","r").readline()[:-1]
#===utilities====================
def debug(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':',txt,'\\n'],''))
sys.stdout.flush()
def fatal(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':FATAL:',txt,'\\n'],''))
sys.stdout.flush()
sys.exit(1)
def usage():
print __doc__
#====================================
#class %(projname)s(parentclass):
class %(projname)s:
#---class variables---
#--------------------------
def __init__(self):
ftn="%(projname)s"+".__init__"
#parentclass.__init__(self)
#---instance variables---
(self.year,self.month,self.day,self.hour,self.minute,self.second,
self.weekday,self.julianday,self.daylight)=time.localtime(time.time())
debug(ftn,"hello, world")
#---main-----------
#exemplars; tweak as needed
opt_a=0 #boolean arg, default is false
opt_b=None #string arg, default is undefined
#positional args, default is empty
pargs=[]
if __name__ == '__main__':
ftn = "main"
opts,pargs=getopt.getopt(sys.argv[1:],'hvab:',
['help','version','aa','bb='])
for opt in opts:
if opt[0]=='-h' or opt[0]=='--help':
print modname+": version="+__version__
usage()
sys.exit(0)
elif opt[0]=='-v' or opt[0]=='--version':
print modname+": version="+__version__
sys.exit(0)
elif opt[0]=='-a' or opt[0]=='--aa':
opt_a=1
elif opt[0]=='-b' or opt[0]=='--bb':
opt_b=opt[1]
#---make the object and run it---
x=%(projname)s()
#===Revision Log===
#Created by mkpythonproj:
#%(timestamp)s %(author)s
#
#$Log: mkpythonproj.py,v $
#Revision 1.4 2000/03/03 19:25:20 hgg9140
#*** empty log message ***
#
#Revision 1.3 2000/03/03 19:23:46 hgg9140
#*** empty log message ***
#
#Revision 1.2 2000/03/03 19:15:57 hgg9140
#rcs fix in mkdist
#
"""
msg=body % {'author':author,'projname':projname,\
'progname':progname,'year':year,'timestamp':timestamp}
file.write(msg)
file.close()
os.chmod(progname,0755)
if os.path.exists("RCS"):
os.system("ci -m'initial' "+progname)
os.system("co -l "+progname)
#---main-----------
def main(pargs):
ftn = "main"
global projname,progname
if len(pargs)!=1:
usage()
fatal(ftn,"need 1 (and only 1) projname; pargs="+`pargs`)
else:
projname=pargs[0]
progname=projname+".py"
if project_p:
#---fullblown development project---
mkdirs()
mkcopying()
mkauthors()
mkreadme()
mkversion()
mkdoc()
mkmanifest()
mksetup()
mktest()
mkmodule()
elif setup_p:
#---just a setup.py---
mksetup("newsetup.py")
else:
#---just a script---
mkmodule()
if __name__ == '__main__':
ftn="main"
opts,pargs=getopt.getopt(sys.argv[1:],'hva:ps',
['help','version','author=','proj','setup'])
for opt in opts:
if opt[0]=='-h' or opt[0]=='--help':
print modname+": version="+__version__
usage()
sys.exit(0)
elif opt[0]=='-v' or opt[0]=='--version':
print modname+": version="+__version__
sys.exit(0)
elif opt[0]=='-a' or opt[0]=='--author':
author=opt[1]
elif opt[0]=='-p' or opt[0]=='--proj':
project_p=1
elif opt[0]=='-s' or opt[0]=='--setup':
#debug(ftn,"setup found")
setup_p=1
main(pargs)
#===Revision Log==============
#$Log: mkpythonproj.py,v $
--
Harry George
hgg9140 at seanet.com
More information about the Python-list
mailing list