[Zope-Checkins] CVS: Zope3/utilities - ExtensionBuilder.py:1.4.10.2 license_check.py:1.1.2.4

Steve Alexander steve@cat-box.net
Fri, 10 May 2002 05:48:19 -0400


Update of /cvs-repository/Zope3/utilities
In directory cvs.zope.org:/tmp/cvs-serv25323/utilities

Modified Files:
      Tag: Zope-3x-branch
	ExtensionBuilder.py license_check.py 
Log Message:
Converted tabs to spaces, and other minor formatting changes.
Some files had mixed tabs and spaces, and some files used 4 space tabs
and some used 8 space tabs.

I'd really like folks to check in files that use only spaces for
indentation.



=== Zope3/utilities/ExtensionBuilder.py 1.4.10.1 => 1.4.10.2 ===
 
 win32_def="""EXPORTS
-	init%(module)s
+        init%(module)s
 """
 
 win32_mak="""# Microsoft Developer Studio Generated NMAKE File, Format Version 4.00
@@ -510,11 +510,11 @@
 ALL : "$(OUTDIR)\\%(module)s.dll"
 
 CLEAN : 
-	-@erase "$(OUTDIR)\\%(module)s.dll"
-	-@erase "$(OUTDIR)\\%(module)s.obj"%(other_clean_release)s
-	-@erase "$(OUTDIR)\\%(module)s.lib"
-	-@erase "$(OUTDIR)\\%(module)s.exp"
-	-@erase "$(OUTDIR)\\%(module)s.pch"
+        -@erase "$(OUTDIR)\\%(module)s.dll"
+        -@erase "$(OUTDIR)\\%(module)s.obj"%(other_clean_release)s
+        -@erase "$(OUTDIR)\\%(module)s.lib"
+        -@erase "$(OUTDIR)\\%(module)s.exp"
+        -@erase "$(OUTDIR)\\%(module)s.pch"
 
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
@@ -544,10 +544,10 @@
  /pdb:"$(OUTDIR)\\%(module)s.pdb" /machine:I386 /def:".\\%(module)s.def"\\
  /out:"$(OUTDIR)\\%(module)s.dll" /implib:"$(OUTDIR)\\%(module)s.lib" %(libdirs)s
 DEF_FILE= \\
-	".\\%(module)s.def"
+        ".\\%(module)s.def"
 LINK32_OBJS= \\
-	"$(INTDIR)\\%(module)s.obj" \\%(other_link)s
-	"%(pyhome)s\\libs\\%(pythonlib)s"
+        "$(INTDIR)\\%(module)s.obj" \\%(other_link)s
+        "%(pyhome)s\\libs\\%(pythonlib)s"
 
 "$(OUTDIR)\\%(module)s.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
     $(LINK32) @<<
@@ -572,15 +572,15 @@
 ALL : "$(OUTDIR)\\%(module)s.dll"
 
 CLEAN : 
-	-@erase "$(OUTDIR)\\%(module)s.dll"
-	-@erase "$(OUTDIR)\\%(module)s.obj"%(other_clean_debug)s
-	-@erase "$(OUTDIR)\\%(module)s.ilk"
-	-@erase "$(OUTDIR)\\%(module)s.lib"
-	-@erase "$(OUTDIR)\\%(module)s.exp"
-	-@erase "$(OUTDIR)\\%(module)s.pdb"
-	-@erase "$(OUTDIR)\\%(module)s.pch"
-	-@erase "$(OUTDIR)\\pcbuild.pdb"
-	-@erase "$(OUTDIR)\\pcbuild.idb"
+        -@erase "$(OUTDIR)\\%(module)s.dll"
+        -@erase "$(OUTDIR)\\%(module)s.obj"%(other_clean_debug)s
+        -@erase "$(OUTDIR)\\%(module)s.ilk"
+        -@erase "$(OUTDIR)\\%(module)s.lib"
+        -@erase "$(OUTDIR)\\%(module)s.exp"
+        -@erase "$(OUTDIR)\\%(module)s.pdb"
+        -@erase "$(OUTDIR)\\%(module)s.pch"
+        -@erase "$(OUTDIR)\\pcbuild.pdb"
+        -@erase "$(OUTDIR)\\pcbuild.idb"
 
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
@@ -611,10 +611,10 @@
  /pdb:"$(OUTDIR)\\%(module)s.pdb" /debug /machine:I386 /def:".\\%(module)s.def"\\
  /out:"$(OUTDIR)\\%(module)s.dll" /implib:"$(OUTDIR)\\%(module)s.lib" %(libdirs)s
 DEF_FILE= \\
-	".\\%(module)s.def"
+        ".\\%(module)s.def"
 LINK32_OBJS= \\
-	"$(INTDIR)\\%(module)s.obj" \\%(other_link)s
-	"%(pyhome)s\\libs\\%(pythonlib)s"
+        "$(INTDIR)\\%(module)s.obj" \\%(other_link)s
+        "%(pyhome)s\\libs\\%(pythonlib)s"
 
 "$(OUTDIR)\\%(module)s.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
     $(LINK32) @<<


=== Zope3/utilities/license_check.py 1.1.2.3 => 1.1.2.4 ===
 
     def __init__(self, fname, zpl, verbose=0, backup=1):
-	"""\
-	fname -> name of the checked file
-	zpl   -> instance of ZPL, class representing the license
-	"""
-	self.fname = fname
-	self.header_length = 700
-	self.license = zpl.license_text
-	self.verbose = verbose
-	self.backup = backup
+        """\
+        fname -> name of the checked file
+        zpl   -> instance of ZPL, class representing the license
+        """
+        self.fname = fname
+        self.header_length = 700
+        self.license = zpl.license_text
+        self.verbose = verbose
+        self.backup = backup
     
 
     def get_header(self):
-	"""Get a number if lines of the file. The number is an
-	instance attribute"""
+        """Get a number if lines of the file. The number is an
+        instance attribute"""
         header = open(self.fname,'r').read(self.header_length)
         return header
-	
+        
 
     def has_some_license(self):
-	"""Search the file for some license text. If the text is
-	found, return 1"""
-	header = self.get_header()
+        """Search the file for some license text. If the text is
+        found, return 1"""
+        header = self.get_header()
         if not re.search("ZPL", header, re.I):
-	    return 0
-	else:
-	    return 1
+            return 0
+        else:
+            return 1
 
 
     def has_license(self):
-	"""Fast check for the exact license text in the header"""
+        """Fast check for the exact license text in the header"""
         header = self.get_header()
-	if header.find(self.license) == -1:
-	    return 0
+        if header.find(self.license) == -1:
+            return 0
         else:
-	    return 1
-	    
+            return 1
+            
 
     def include(self):
-	"""Put a license text at the top of the lines. If the first line
-	starts with a bang-path start inserting at the second line"""
-	lines = open(self.fname,'r').readlines()
-	start = 0
-	if lines and re.match('#!', lines[0]):
-	    start=1
-	lines.insert(start, self.license)
-	# keep the current stat_mod
-	fmode = os.stat(self.fname)[0]
-	# There can already be a backup file from the removal pass
-	if self.backup and not os.path.isfile(self.fname+'.no_license'):
-	    os.rename(self.fname, self.fname+'.no_license')
-	open(self.fname, 'w').write(''.join(lines))
-	os.chmod(self.fname, fmode)
+        """Put a license text at the top of the lines. If the first line
+        starts with a bang-path start inserting at the second line"""
+        lines = open(self.fname,'r').readlines()
+        start = 0
+        if lines and re.match('#!', lines[0]):
+            start=1
+        lines.insert(start, self.license)
+        # keep the current stat_mod
+        fmode = os.stat(self.fname)[0]
+        # There can already be a backup file from the removal pass
+        if self.backup and not os.path.isfile(self.fname+'.no_license'):
+            os.rename(self.fname, self.fname+'.no_license')
+        open(self.fname, 'w').write(''.join(lines))
+        os.chmod(self.fname, fmode)
         if self.verbose:
-	    print 'License included: %s' % self.fname
+            print 'License included: %s' % self.fname
         return 
  
 
     def change(self):
-	"""Try to change the license text in the file, raise an exception
-	if not possible. 
-	"""
-	if self.has_some_license():
-	    # try to remove the old license
-	    try:
-		self.remove()
-		self.include()
-	    except ZLicenseCheckError:
-	        open(self.fname+'.pathological','w')
+        """Try to change the license text in the file, raise an exception
+        if not possible. 
+        """
+        if self.has_some_license():
+            # try to remove the old license
+            try:
+                self.remove()
+                self.include()
+            except ZLicenseCheckError:
+                open(self.fname+'.pathological','w')
                 raise ZLicenseCheckError('License could not be changed',
                                          self.fname)
 
-	else:
-	    self.include()
-	return
+        else:
+            self.include()
+        return
 
 
     def remove(self):
-	lines = open(self.fname, 'r').readlines()
-	if not lines:
-	    return
-	start = 0
-	save = []
-	if re.match('#!',lines[0]):
-	    start = 1
-	    save.extend(lines[0])
-	end=start
-	for line in lines[start:]:
-	    if line[0] == '#' or line.isspace():
-	        end += 1
-	    else:
-		break
-
-	license = ''.join(lines[start:end])
-	# test if we really have the license
-	lookfor = 'copyright|Zope Public|license|All rights reserved'
-	if not re.search(lookfor, license, re.I):
-	    raise ZLicenseCheckError('No clear license text', self.fname)
-	else:
-	    save.extend(lines[end:])
-	    # keep the current stat_mod
-	    fmode = os.stat(self.fname)[0]
-	    if self.backup:
-		os.rename(self.fname, self.fname+'.no_license')
-	    if self.verbose:
-		print 'License removed: %s' % self.fname
+        lines = open(self.fname, 'r').readlines()
+        if not lines:
+            return
+        start = 0
+        save = []
+        if re.match('#!',lines[0]):
+            start = 1
+            save.extend(lines[0])
+        end=start
+        for line in lines[start:]:
+            if line[0] == '#' or line.isspace():
+                end += 1
+            else:
+                break
+
+        license = ''.join(lines[start:end])
+        # test if we really have the license
+        lookfor = 'copyright|Zope Public|license|All rights reserved'
+        if not re.search(lookfor, license, re.I):
+            raise ZLicenseCheckError('No clear license text', self.fname)
+        else:
+            save.extend(lines[end:])
+            # keep the current stat_mod
+            fmode = os.stat(self.fname)[0]
+            if self.backup:
+                os.rename(self.fname, self.fname+'.no_license')
+            if self.verbose:
+                print 'License removed: %s' % self.fname
             open(self.fname,'w').write(''.join(save))
-	    os.chmod(self.fname, fmode)
-	return
-	
+            os.chmod(self.fname, fmode)
+        return
+        
 
     def warn(self):
-	print 'File %s has no license text' % self.fname
+        print 'File %s has no license text' % self.fname
 
 class Config:
     """Container to keep configuration options"""
     def __init__(self, **kws):
-	self.verbose = 0
-	self.warning = 0
-	self.strict = 0
-	self.backup = 1
-	self.undo = 0
-	self.include_init = 0
+        self.verbose = 0
+        self.warning = 0
+        self.strict = 0
+        self.backup = 1
+        self.undo = 0
+        self.include_init = 0
         self.license_path='./'
 
-	if kws:
-	    for key,value in kws:
-		setattr(self, key, value)
+        if kws:
+            for key,value in kws:
+                setattr(self, key, value)
 
-	return
+        return
 
 
 class ZPL:    
     def __init__(self, path='./'):
-	self.path = path
-	self.license_text = self.get_text()
+        self.path = path
+        self.license_text = self.get_text()
 
     def get_text(self):
-	zhome = os.environ.get('ZOPE_HOME', self.path)
-	try:
+        zhome = os.environ.get('ZOPE_HOME', self.path)
+        try:
             data = open(os.path.join(zhome,'zpl.py'),'r').read()
-	except IOError:
-	    sys.exit('Could not open license file zpl.py')
+        except IOError:
+            sys.exit('Could not open license file zpl.py')
 
-	license = data[:data.find('"""')]
-	return license
+        license = data[:data.find('"""')]
+        return license
 
 
 class CheckerApp:
     def __init__(self, config):
-	self.conf = config
-	self.zpl = ZPL()
-	self.pathological = []
-	
-	# Which test (uses unbound methods)
-	if self.conf.strict:
-	    self.condition = HeaderCheck.has_license
-	else:
-	    self.condition = HeaderCheck.has_some_license
+        self.conf = config
+        self.zpl = ZPL()
+        self.pathological = []
+        
+        # Which test (uses unbound methods)
+        if self.conf.strict:
+            self.condition = HeaderCheck.has_license
+        else:
+            self.condition = HeaderCheck.has_some_license
 
-	# Wich action
+        # Wich action
         if self.conf.warning:
-	    self.action = HeaderCheck.warn
-	else:
-	    if self.conf.strict:
-		self.action = HeaderCheck.change
-	    else:
-		self.action = HeaderCheck.include
-	    
+            self.action = HeaderCheck.warn
+        else:
+            if self.conf.strict:
+                self.action = HeaderCheck.change
+            else:
+                self.action = HeaderCheck.include
+            
     def run(self):
-	if self.conf.undo:
-	    for fname in GlobDirectoryWalker(self.conf.path,"*.no_license"):
-		old_name = os.path.splitext(fname)[0]
-		os.rename(fname, old_name)
-        else:
-	    for fname in GlobDirectoryWalker(".", "*.py"):
-		if (os.path.split(fname)[-1] == '__init__.py') and \
-		        not self.conf.include_init:
+        if self.conf.undo:
+            for fname in GlobDirectoryWalker(self.conf.path,"*.no_license"):
+                old_name = os.path.splitext(fname)[0]
+                os.rename(fname, old_name)
+        else:
+            for fname in GlobDirectoryWalker(".", "*.py"):
+                if (os.path.split(fname)[-1] == '__init__.py') and \
+                        not self.conf.include_init:
                     if self.conf.verbose:
-			print 'Skipping: %s' % fname
+                        print 'Skipping: %s' % fname
                     continue
 
-		hc = HeaderCheck(fname, self.zpl, 
-				 verbose=self.conf.verbose,
-				 backup=self.conf.backup)
-
-		# unbound methods need an instance
-		if not self.condition(hc):
-		    try:
-			self.action(hc)
+                hc = HeaderCheck(fname, self.zpl, 
+                                 verbose=self.conf.verbose,
+                                 backup=self.conf.backup)
+
+                # unbound methods need an instance
+                if not self.condition(hc):
+                    try:
+                        self.action(hc)
                     except ZLicenseCheckError, error:
-			print error, '(%s)' %error.fname
-			self.pathological.append(fname)
+                        print error, '(%s)' %error.fname
+                        self.pathological.append(fname)
 
         if self.conf.verbose:
-	    for fname in self.pathological:
-		print 'Could not be changed: %s' % fname
-	    print 'Number of pathological files: %s' % \
-		   len(self.pathological) 
+            for fname in self.pathological:
+                print 'Could not be changed: %s' % fname
+            print 'Number of pathological files: %s' % \
+                   len(self.pathological) 
 
 
 def print_usage(msg=0):
     print usage % (sys.argv[0], sys.argv[0])
     if msg:
-	print msg
-	msg=1
+        print msg
+        msg=1
     sys.exit(msg)
 
     
 def main():
     import getopt
     try:
-	opts, args = getopt.getopt(sys.argv[1:], "vwcshl:",
-	["nobackup","undo","include_init"])
+        opts, args = getopt.getopt(sys.argv[1:], "vwcshl:",
+        ["nobackup","undo","include_init"])
     except getopt.GetoptError, error:
-	print_usage(str(error).capitalize())
+        print_usage(str(error).capitalize())
 
     if not opts:
-	print_usage('Need at least optin -w OR -c OR --undo')
+        print_usage('Need at least optin -w OR -c OR --undo')
 
     if (('-w','') in opts) and (('-c','') in opts):
-	print_usage('Only option -w OR -c can be used')
-	
+        print_usage('Only option -w OR -c can be used')
+        
     conf=Config()
     for o,a in opts:
-	if o == '-v' : conf.verbose = 1
-	elif o == '-c': conf.change = 1
-	elif o == '-w': conf.warning = 1
-	elif o == '-s': conf.strict = 1
-	elif o == '-h': print_usage()
+        if o == '-v' : conf.verbose = 1
+        elif o == '-c': conf.change = 1
+        elif o == '-w': conf.warning = 1
+        elif o == '-s': conf.strict = 1
+        elif o == '-h': print_usage()
         elif o == '--include_init': conf.include_init = 1
         elif o == '--nobackup': conf.backup = 0
         elif o == '--undo': conf.undo = 1
         elif o == '-l':
-	    if not a:
-		print_usage('Need to get a path for option -l')
+            if not a:
+                print_usage('Need to get a path for option -l')
             conf.license_path = a
 
     if not args:
-	conf.path = os.getcwd()
+        conf.path = os.getcwd()
     else:
-	conf.path = args[0]
+        conf.path = args[0]
 
     # test presence of working directory
     if not os.path.isdir(conf.path):
-	print_usage('Can not find directory %s' % conf.path)
-	
+        print_usage('Can not find directory %s' % conf.path)
+        
     checker = CheckerApp(conf)
     checker.run()