[Checkins] SVN: zope.assetvaluation/ Quick wrapper around sloccount, using checkouts from svn.zope.org.
Tres Seaver
tseaver at palladion.com
Tue Nov 30 11:30:50 EST 2010
Log message for revision 118646:
Quick wrapper around sloccount, using checkouts from svn.zope.org.
Changed:
A zope.assetvaluation/
A zope.assetvaluation/trunk/
A zope.assetvaluation/trunk/.bzrignore
A zope.assetvaluation/trunk/CHANGES.txt
A zope.assetvaluation/trunk/COPYRIGHT.txt
A zope.assetvaluation/trunk/LICENSE.txt
A zope.assetvaluation/trunk/README.txt
A zope.assetvaluation/trunk/bootstrap.py
A zope.assetvaluation/trunk/buildout.cfg
A zope.assetvaluation/trunk/setup.py
A zope.assetvaluation/trunk/src/
A zope.assetvaluation/trunk/src/zope/
A zope.assetvaluation/trunk/src/zope/__init__.py
A zope.assetvaluation/trunk/src/zope/assetvaluation/
A zope.assetvaluation/trunk/src/zope/assetvaluation/__init__.py
A zope.assetvaluation/trunk/src/zope/assetvaluation/repository.py
A zope.assetvaluation/trunk/src/zope/assetvaluation/valuation.py
-=-
Added: zope.assetvaluation/trunk/.bzrignore
===================================================================
--- zope.assetvaluation/trunk/.bzrignore (rev 0)
+++ zope.assetvaluation/trunk/.bzrignore 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,6 @@
+./.installed.cfg
+./bin
+./develop-eggs
+./eggs
+./parts
+*.egg-info
Added: zope.assetvaluation/trunk/CHANGES.txt
===================================================================
--- zope.assetvaluation/trunk/CHANGES.txt (rev 0)
+++ zope.assetvaluation/trunk/CHANGES.txt 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1 @@
+...
Added: zope.assetvaluation/trunk/COPYRIGHT.txt
===================================================================
--- zope.assetvaluation/trunk/COPYRIGHT.txt (rev 0)
+++ zope.assetvaluation/trunk/COPYRIGHT.txt 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1 @@
+Zope Foundation and Contributors
\ No newline at end of file
Added: zope.assetvaluation/trunk/LICENSE.txt
===================================================================
--- zope.assetvaluation/trunk/LICENSE.txt (rev 0)
+++ zope.assetvaluation/trunk/LICENSE.txt 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,44 @@
+Zope Public License (ZPL) Version 2.1
+
+A copyright notice accompanies this license document that identifies the
+copyright holders.
+
+This license has been certified as open source. It has also been designated as
+GPL compatible by the Free Software Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions in source code must retain the accompanying copyright
+notice, this list of conditions, and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying copyright
+notice, this list of conditions, and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to endorse or promote
+products derived from this software without prior written permission from the
+copyright holders.
+
+4. The right to distribute this software or to use it for any purpose does not
+give you the right to use Servicemarks (sm) or Trademarks (tm) of the
+copyright
+holders. Use of them is covered by separate agreement with the copyright
+holders.
+
+5. If any files are modified, you must cause the modified files to carry
+prominent notices stating that you changed the files and the date of any
+change.
+
+Disclaimer
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Added: zope.assetvaluation/trunk/README.txt
===================================================================
--- zope.assetvaluation/trunk/README.txt (rev 0)
+++ zope.assetvaluation/trunk/README.txt 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,15 @@
+Methodology for ``zope.assetvaluation``
+=======================================
+
+
+This package provides a ``zope-org-valuation`` script that is run
+against the zope.org Subversion repository. The script checks out the
+``trunk`` or ```develop`` branches of all top level subversion projects,
+with the exception of ``Sandbox``. For each project, the script runs the
+``sloccount`` script[1] against its checkout, and aggregates the total
+lines of code / valuation, based on the "Organic" COCOMO model[1].
+
+
+[1] http://www.dwheeler.com/sloccount/sloccount.html
+
+[2] http://www.dwheeler.com/sloccount/sloccount.html#cocomo
Added: zope.assetvaluation/trunk/bootstrap.py
===================================================================
--- zope.assetvaluation/trunk/bootstrap.py (rev 0)
+++ zope.assetvaluation/trunk/bootstrap.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 90478 2008-08-27 22:44:46Z georgyberdyshev $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+try:
+ import pkg_resources
+except ImportError:
+ ez = {}
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+
+if is_jython:
+ import subprocess
+
+ assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+ quote(tmpeggs), 'zc.buildout'],
+ env=dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Added: zope.assetvaluation/trunk/buildout.cfg
===================================================================
--- zope.assetvaluation/trunk/buildout.cfg (rev 0)
+++ zope.assetvaluation/trunk/buildout.cfg 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts = egg
+
+[egg]
+recipe = zc.recipe.egg
+eggs = zope.assetvaluation
+interpreter = py
Added: zope.assetvaluation/trunk/setup.py
===================================================================
--- zope.assetvaluation/trunk/setup.py (rev 0)
+++ zope.assetvaluation/trunk/setup.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from setuptools import setup, find_packages
+
+README = open('README.txt').read()
+CHANGES = open('CHANGES.txt').read()
+
+setup(
+ name='zope.assetvaluation',
+ version='0.1dev',
+ author='Zope Foundation and Contributors',
+ author_email='zope-dev at zope.org',
+ url='http://pypi.python.org/pypi/zope.assetvaluation',
+ description="""\
+ Compute COCOMO valuation of projects in svn.zope.org
+ """,
+ long_description = '\n\n'.join([README, CHANGES]),
+ packages=find_packages('src'),
+ package_dir={'': 'src'},
+ include_package_data=True,
+ zip_safe=False,
+ license='ZPL 2.1',
+ namespace_packages=['zope'],
+ install_requires=[
+ 'setuptools',
+ 'subvertpy',
+ ],
+ entry_points="""
+ [console_scripts]
+ zope-org-valuation = zope.assetvaluation.repository:main
+ """,
+)
Added: zope.assetvaluation/trunk/src/zope/__init__.py
===================================================================
--- zope.assetvaluation/trunk/src/zope/__init__.py (rev 0)
+++ zope.assetvaluation/trunk/src/zope/__init__.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
Added: zope.assetvaluation/trunk/src/zope/assetvaluation/__init__.py
===================================================================
--- zope.assetvaluation/trunk/src/zope/assetvaluation/__init__.py (rev 0)
+++ zope.assetvaluation/trunk/src/zope/assetvaluation/__init__.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1 @@
+# Make this a Python package
Added: zope.assetvaluation/trunk/src/zope/assetvaluation/repository.py
===================================================================
--- zope.assetvaluation/trunk/src/zope/assetvaluation/repository.py (rev 0)
+++ zope.assetvaluation/trunk/src/zope/assetvaluation/repository.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,128 @@
+# Copyright (c) 2010 Zope Foundation and Contributors
+# See also LICENSE.txt
+""" zope-org-valuation [OPTIONS] [project_name]*
+
+Print SLOC and COCOMO valuation of projects on standard output as a CSV file.
+
+Options:
+
+--help, -h, -? Print this usage message and exit.
+
+--quiet, -q Suppress inessential output (on standard error).
+
+--verbose, -v Add more noisy output (on standard error).
+
+--source-dir, -s Use the supplied value as the directory into which
+ checkouts are made for each project. Defaults to 'src'.
+ This directory must exist.
+
+--data-dir, -d Use the supplied value as the directory into which
+ 'sloccount' stores its computed information.
+ Defaults to 'data'. This directory must not exist:
+ it will be removed and recreated during the run.
+"""
+import os
+import sys
+import getopt
+
+from subvertpy.client import Client
+from subvertpy.ra import RemoteAccess
+
+from zope.assetvaluation.valuation import Assessor
+
+
+class Checker(object):
+
+ root = 'svn://svn.zope.org/repos/main'
+
+ def __init__(self, src_dir, data_dir, projects, verbosity):
+ self.repos = RemoteAccess(self.root)
+ self.src_dir = src_dir
+ self.data_dir = data_dir
+ self.projects = projects
+ self.verbosity = verbosity
+
+ def run(self):
+ branches = {}
+ for project, branch in self.list_projects_branches():
+ branches[project] = branch
+ c = Client()
+ p_dir = os.path.join(self.src_dir, project)
+ c.checkout(url='%s/%s/%s' % (self.root, project, branch),
+ path=p_dir, rev='HEAD', ignore_externals=True)
+ assessor = Assessor(p_dir, self.data_dir)
+ sloc, cost = assessor()
+ yield project, branch, sloc, cost
+
+ def log(self, message, level=1):
+ if level <= self.verbosity:
+ print >> sys.stderr, message
+
+ def list_projects_branches(self):
+ projects = self.projects or self.repos.get_dir('/')[0].keys()
+ for project in projects:
+ if project == 'README.txt':
+ continue
+ self.log('Project: %s' % project)
+ top = self.repos.get_dir(project)[0].keys()
+ if 'trunk' in top:
+ self.log(' branch: trunk', 2)
+ yield project, 'trunk'
+ elif 'develop' in top:
+ self.log(' branch: develop', 2)
+ yield project, 'develop'
+
+
+CSV_HEADER = '"Project","Branch","SLOC","Cost"'
+CSV_ROW = '"%s","%s",%d,%d'
+
+def usage(error='', rc=1):
+ print >>sys.stderr, __doc__
+ if error:
+ print >>sys.stderr
+ print >>sys.stderr, error
+ sys.exit(rc)
+
+def main():
+ src_dir = 'src'
+ data_dir = 'data'
+ verbosity = 1
+
+ try:
+ options, args = getopt.gnu_getopt(sys.argv[1:],
+ 'h?qvs:d:',
+ ['help',
+ 'quiet',
+ 'verbose',
+ 'source-dir=',
+ 'data-dir=',
+ ]
+ )
+ except getopt.GetoptError:
+ usage(rc=1)
+
+ for k, v in options:
+ if k in ('-h', '-?', '--help'):
+ usage(rc=2)
+ if k in ('-q', '--quiet'):
+ verbosity = 0
+ if k in ('-v', '--verbose'):
+ verbosity += 1
+ if k in ('-s', '--source-dir'):
+ src_dir = v
+ if k in ('-d', '--data-dir'):
+ data_dir = v
+
+ src_dir = os.path.abspath(os.path.normpath(src_dir))
+ if not os.path.isdir(src_dir):
+ usage(error='No such source directory: %s' % src_dir)
+
+ data_dir = os.path.abspath(os.path.normpath(data_dir))
+ if not os.path.isdir(data_dir):
+ usage(error='No such data directory: %s' % data_dir)
+
+ print CSV_HEADER
+
+ checker = Checker(src_dir, data_dir, args, verbosity)
+ for project, branch, sloc, cost in checker.run():
+ print CSV_ROW % (project, branch, sloc, cost)
Added: zope.assetvaluation/trunk/src/zope/assetvaluation/valuation.py
===================================================================
--- zope.assetvaluation/trunk/src/zope/assetvaluation/valuation.py (rev 0)
+++ zope.assetvaluation/trunk/src/zope/assetvaluation/valuation.py 2010-11-30 16:30:49 UTC (rev 118646)
@@ -0,0 +1,39 @@
+# Copyright (c) 2010 Zope Foundation and Contributors
+# See also LICENSE.txt
+
+import subprocess
+
+TOTAL_SLOC = 'Total Physical Source Lines of Code (SLOC)'
+TOTAL_COST = 'Total Estimated Cost to Develop'
+
+
+class Assessor(object):
+
+ def __init__(self, src_dir, data_dir):
+ self.src_dir = src_dir
+ self.data_dir = data_dir
+
+ def __call__(self):
+ command_line = ['sloccount',
+ '--datadir',
+ self.data_dir,
+ self.src_dir,
+ ]
+ pipe = subprocess.Popen(command_line, shell=False,
+ stdout=subprocess.PIPE).stdout
+ sloc = cost = None
+ while True:
+ line = pipe.readline()
+ if not line:
+ break
+ if line.startswith(TOTAL_SLOC):
+ sloc_str = line.rsplit('=', 1)[1].strip()
+ sloc_str = sloc_str.replace(',', '')
+ sloc = int(sloc_str)
+ if line.startswith(TOTAL_COST):
+ cost_str = line.rsplit('=', 1)[1].strip()
+ if cost_str.startswith('$'):
+ cost_str = cost_str[1:].strip()
+ cost_str = cost_str.replace(',', '')
+ cost = int(cost_str)
+ return sloc, cost
More information about the checkins
mailing list