Ejemplo n.º 1
0
def copydir_run_2to3(src,
                     dest,
                     template=None,
                     fixer_names=None,
                     options=None,
                     explicit=None):
    """Recursively copy a directory, only copying new and changed files,
    running run_2to3 over all newly copied Python modules afterward.

    If you give a template string, it's parsed like a MANIFEST.in.
    """
    from distutils.dir_util import mkpath
    from distutils.file_util import copy_file
    from distutils.filelist import FileList
    filelist = FileList()
    curdir = os.getcwd()
    os.chdir(src)
    try:
        filelist.findall()
    finally:
        os.chdir(curdir)
    filelist.files[:] = filelist.allfiles
    if template:
        for line in template.splitlines():
            line = line.strip()
            if not line: continue
            filelist.process_template_line(line)
    copied = []
    for filename in filelist.files:
        outname = os.path.join(dest, filename)
        mkpath(os.path.dirname(outname))
        res = copy_file(os.path.join(src, filename), outname, update=1)
        if res[1]: copied.append(outname)
    run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
             fixer_names=fixer_names,
             options=options,
             explicit=explicit)
    return copied
Ejemplo n.º 2
0
def _data_files():
    """List files to be copied to the TAU Commander installation.

    Start with the files listed in MANIFEST.in, then exclude files that should not be installed.
    """
    from distutils.filelist import FileList
    from distutils.text_file import TextFile
    from distutils.errors import DistutilsTemplateError
    filelist = FileList()
    template = TextFile(os.path.join(PACKAGE_TOPDIR, 'MANIFEST.in'),
                        strip_comments=1,
                        skip_blanks=1,
                        join_lines=1,
                        lstrip_ws=1,
                        rstrip_ws=1,
                        collapse_join=1)
    try:
        while True:
            line = template.readline()
            if line is None:
                break
            try:
                filelist.process_template_line(line)
            except (DistutilsTemplateError, ValueError) as err:
                print "%s, line %d: %s" % (template.filename,
                                           template.current_line, err)
    finally:
        template.close()
    excluded = ['Makefile', 'VERSION', 'MANIFEST.in', '*Miniconda*']
    data_files = []
    for path in filelist.files:
        for excl in excluded:
            if fnmatch.fnmatchcase(path, excl):
                break
        else:
            data_files.append((os.path.dirname(path), [path]))
    return data_files
Ejemplo n.º 3
0
	def run_htmlhelp(self):
		"""Generate MS HTMLHelp documentation"""
		self.make_file(['build/doc/manual.xml'],
		               'build/doc/htmlhelp/index.html',
		               self.gen_html,
		               ('build/doc/htmlhelp', 'build/doc/htmlhelp', 'htmlhelp.xsl'))

		self.mkpath('build/doc/htmlhelp')

		for file in ('manual.hhp', 'manual.hhc'):
			if os.path.exists(file):
				x = open(file).read()
##				x = string.replace(x, 'build/doc/htmlhelp_raw/', '')
				x = string.replace(x, 'build/doc/htmlhelp/', '')
				open(os.path.join('build', 'doc', 'htmlhelp', file), 'w').write(x)
				os.remove(file)
			
#		self.move_file('manual.hhp', 'build/doc/htmlhelp')
#		self.move_file('toc.hhc', 'build/doc/htmlhelp')
		
##		self.make_file(['build/doc/htmlhelp_raw/index.html'],
##		               'build/doc/htmlhelp/index.html',
##		               self.xform_html,
##		               ('build/doc/htmlhelp_raw', 'build/doc/htmlhelp'))

		self.copy_file('doc/misc/style.css', 'build/doc/htmlhelp')
		self.copy_file('doc/misc/greypinstripe.png', 'build/doc/htmlhelp')
	
		f = FileList()
		f.findall('build/doc/htmlhelp')
		f.process_template_line('global-include *')
		self.make_file(f.files,
		               'build/doc/htmlhelp/manual.chm',
		               self.hhc,
		               ())

		self.copy_file('build/doc/htmlhelp/manual.chm', 'OpenGL/doc')
Ejemplo n.º 4
0
def _parse_template_file(filename, path=None):
    template = TextFile(filename,
                        strip_comments=1,
                        skip_blanks=1,
                        join_lines=1,
                        lstrip_ws=1,
                        rstrip_ws=1,
                        collapse_join=1)
    lines = template.readlines()

    filelist = FileList()
    try:
        if path is not None and not path == os.getcwd():
            oldpath = os.getcwd()
            os.chdir(path)
        else:
            oldpath = None

        for line in lines:
            filelist.process_template_line(line)
    finally:
        if oldpath is not None:
            os.chdir(oldpath)
    return filelist.files
Ejemplo n.º 5
0
#!/usr/bin/env python
"""Distutils setup file, used to install or test 'setuptools'"""
import sys
import os

src_root = None
if sys.version_info >= (3, ):
    tmp_src = os.path.join("build", "src")
    from distutils.filelist import FileList
    from distutils import dir_util, file_util, util, log
    log.set_verbosity(1)
    fl = FileList()
    for line in open("MANIFEST.in"):
        fl.process_template_line(line)
    dir_util.create_tree(tmp_src, fl.files)
    outfiles_2to3 = []
    dist_script = os.path.join("build", "src", "distribute_setup.py")
    for f in fl.files:
        outf, copied = file_util.copy_file(f,
                                           os.path.join(tmp_src, f),
                                           update=1)
        if copied and outf.endswith(".py") and outf != dist_script:
            outfiles_2to3.append(outf)
        if copied and outf.endswith('api_tests.txt'):
            # XXX support this in distutils as well
            from lib2to3.main import main
            main(
                'lib2to3.fixes',
                ['-wd', os.path.join(tmp_src, 'tests', 'api_tests.txt')])

    util.run_2to3(outfiles_2to3)
Ejemplo n.º 6
0
    def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
        """
        Copy parts of a source tree to a destination tree with a
        different tree structure and/or names.

        The basic idea: given a set of source files, copy them to a
        destination directory, let's call this operation an
        install_spec. A sequence of install_spec's allows one to build
        up the destrination tree in any structure desired.

        Each install_spec consists of 3 components
        (manifest_template, dst_xforms, dst_dir):

        The manifest_template is a sequence where each item is identical
        to a line in the MANIFEST.in template described in distutils. This
        gives you ability to easily specify a set of source files in a
        compact abstract manner (with recursion, exclusion, etc.) The
        manifest_template yields a sequence of source paths.

        dst_xforms is a sequence of regular expression substitutions
        applied to the each source path to yield a rewritten destination
        path. Each transform is expressed as a two-valued sequence
        (pattern, replacement)

        dst_dir is a destination directory where the destinations paths
        are written to. dst_dir is always relative to the dst_root.

        All input may be parametrized via variable substitutions
        supplied by a substitution dict. Any use of $name will cause
        name to be looked up first in the substitution dict and then
        if its not found there in the enviorment. If found it will be
        replaced with it's value.

        The pseudo code algorithm for processing an install_spec is:

        substitute all variables in manifest template
        src_list = evaluate manifest template
        for each src_path in src_list:
            dst_path = src_path
            for each xform in dst_xform:
                apply xform to dst_path
            copy src_root+src_path to dst_root+dest_dir+dest_path

        This process is repeated for each install spec. The src_root and
        dst_root are also subject to variable substitution.


        Examples:

        Copy all text files in build/doc to doc:

            copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])

        Copy all html files found under build to doc/html and change the extension from
        .html to .htm

            copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])

    """

        if src_root is not None: src_root = subst_vars(src_root, substitutions)
        if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)

        filelist = FileList()
        if src_root is None:
            filelist.findall()
        else:
            filelist.findall(src_root)

        for manifest_template, dst_xforms, dst_dir in install_specs:
            if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)

            filelist.files = [] # reinitialize to empty

            for line in manifest_template:
                filelist.process_template_line(subst_vars(line, substitutions))

            for src_path in filelist.files:
                dst_path = src_path
                if dst_xforms:
                    for dst_xform in dst_xforms:
                        dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
                if dst_dir is not None:
                    dst_path = change_root(dst_dir, dst_path)
                if dst_root is None:
                    full_dst_path = dst_path
                else:
                    full_dst_path = change_root(dst_root, dst_path)
                full_dst_dir = os.path.dirname(full_dst_path)
                self.mkpath(full_dst_dir)
                self.copy_file(src_path, full_dst_path)
Ejemplo n.º 7
0
    def test_process_template(self):
        l = make_local_path
        # invalid lines
        file_list = FileList()
        for action in ('include', 'exclude', 'global-include',
                       'global-exclude', 'recursive-include',
                       'recursive-exclude', 'graft', 'prune', 'blarg'):
            self.assertRaises(DistutilsTemplateError,
                              file_list.process_template_line, action)

        # include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('include *.py')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertNoWarnings()

        file_list.process_template_line('include *.rb')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertWarnings()

        # exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('exclude *.py')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertWarnings()

        # global-include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('global-include *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('global-include *.rb')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertWarnings()

        # global-exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('global-exclude *.py')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertNoWarnings()

        file_list.process_template_line('global-exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertWarnings()

        # recursive-include
        file_list = FileList()
        file_list.set_allfiles(
            ['a.py', l('d/b.py'),
             l('d/c.txt'), l('d/d/e.py')])

        file_list.process_template_line('recursive-include d *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-include e *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # recursive-exclude
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/c.txt'), l('d/d/e.py')]

        file_list.process_template_line('recursive-exclude d *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-exclude e *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertWarnings()

        # graft
        file_list = FileList()
        file_list.set_allfiles(
            ['a.py', l('d/b.py'),
             l('d/d/e.py'), l('f/f.py')])

        file_list.process_template_line('graft d')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('graft e')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # prune
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/d/e.py'), l('f/f.py')]

        file_list.process_template_line('prune d')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertNoWarnings()

        file_list.process_template_line('prune e')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertWarnings()
Ejemplo n.º 8
0
 def test_set_allfiles(self):
     file_list = FileList()
     files = ['a', 'b', 'c']
     file_list.set_allfiles(files)
     self.assertEqual(file_list.allfiles, files)
Ejemplo n.º 9
0
	def finalize_options(self):
		distutils.dist.Distribution.finalize_options(self)

		cfg = ConfigParser()
		name = sys.platform
		config_name = os.path.join('config', name + '.cfg')
		while len(name) and not os.path.exists(config_name):
			name = name[:-1]
			config_name = os.path.join('config', name + '.cfg')

		if not os.path.exists(config_name):
			print "Can't find a config file for the \"%s\" platform.  Look in the config directory." % sys.platform
			sys.exit(1)

		try:
			self.announce( "Using cfg file: %s"%( config_name,))
			cfg.read(config_name)
		except ParsingError:
			print "parse error in config file."
			sys.exit(1)

		self.lib_aliases = {}

		for section in cfg.sections():
			if section != 'General':
				try:
					self.lib_aliases[section] = config_list(cfg.get(section, 'libs'))
				except:
					pass

		try:
			self.include_dirs = config_list(cfg.get('General', 'include_dirs'))
		except:
			self.include_dirs = []

		try:
			self.library_dirs = config_list(cfg.get('General', 'library_dirs'))
		except:
			self.library_dirs = []

		try:
			self.BUILD_TOGL = cfg.getint('General', 'build_togl')
		except:
			self.BUILD_TOGL = 0
			
		try:
			self.extra_link_args = config_list(cfg.get('General', 'extra_link_args'))
		except:
			self.extra_link_args = []

		try:
			self.define_macros = [(string.upper(string.strip(cfg.get('General', 'gl_platform'))) + '_PLATFORM', None)]
			self.gl_platform = cfg.get('General', 'gl_platform')
		except:
			self.define_macros = []
			print 'No gl_platform defined in the config file "%s"' % config_name

		self.togl_libs = self.transform_libs(['GL', 'GLU', 'Togl'])

##		build_togl = self.get_command_obj( 'build_togl' )
##		for field in ('tk-source','tcl-source'):
##			if not getattr(build_togl, field, None):
##				try:
##					setattr(build_togl, field.replace('-','_'), cfg.get('Togl', field))
##				except:
##					pass
		
		try:
			import Numeric
			include_dirs = find_file(get_python_inc(), 'arrayobject.h')
			if not len(include_dirs):
				self.announce("Successfully imported Numeric, but can't find the Numeric headers!")
				self.HAS_NUMERIC = 0
			else:
				self.include_dirs = self.include_dirs + include_dirs
				self.HAS_NUMERIC = 1
		except ImportError:
			self.HAS_NUMERIC = 0

		if self.HAS_NUMERIC:
			Numeric_version = 'yes'
			self.define_macros.append(('NUMERIC', None))
			try:
				import numeric_version
				Numeric_version = numeric_version.version
##				if int(string.split(Numeric_version, '.')[0]) == 20:
##					self.announce('Numeric %s is present...beware!  This is buggy!')
			except:
				pass
		else:
			Numeric_version = 'no'

		boolean = ['no', 'yes']

		self.announce('PyOpenGL %s setup' % self.get_version())
		self.announce('')
		self.announce('System configuration:')
		self.announce('    Platform    = %s' % sys.platform)
		self.announce('    GL Platform = %s' % self.gl_platform)
		self.announce('    Numeric     = %s' % Numeric_version)
		self.announce('    Build Togl  = %s' % boolean[self.BUILD_TOGL])
		self.announce('')

		# get the list of platforms
		self.announce('Getting the list of platforms...')
		self.metadata.platforms = []
		f = FileList()
		f.findall('config')
		f.process_template_line('global-include *.cfg')
		for file in f.files:
			self.metadata.platforms.append(os.path.splitext(os.path.split(file)[1])[0])

		# get the list of packages for this platform
		self.announce('Getting the list of packages...')
		if self.packages is None:
			self.packages = []
		f = FileList()
		# first the real packages
		if os.path.exists('OpenGL'):
			f.findall('OpenGL')
			f.process_template_line('global-include __init__.py')
			# second the Demo's
			Demo = os.path.join('OpenGL', 'Demo')
			if os.path.exists(Demo):
				f.findall(Demo)
				f.process_template_line('global-include *.py')
			# last the scripts
			scripts = os.path.join('OpenGL', 'scripts')
			if os.path.exists(scripts):
				f.findall(scripts)
				f.process_template_line('global-include *.py')
		for file in f.files:
			package = string.replace(os.path.dirname(file), os.sep, '.')
			if package not in self.packages:
				g = {'__name__':'__build__'}
				l = {}
				try:
					exec open(file) in g, l
				except:
					pass
				if not l.has_key('gl_platforms') or self.gl_platform in l['gl_platforms']:
					self.packages.append(package)

		# get the list of extension modules for this platform
		self.announce('Getting the list of extension modules...')
		if self.ext_modules is None:
			self.ext_modules = []

		f = FileList()
		f.findall('interface')
		f.process_template_line('global-include *.i')
		if not len(f.files):
			print "Whoa!  I can't find any interfaces...panic!"
			sys.exit()

		f.files.sort()
		for file in f.files:
			BUILD = get_build_info(file)
			actual_libs = []

			if not BUILD.has_key('gl_platforms') or self.gl_platform in BUILD['gl_platforms']:
				# everything requires GL and GLU
				libs = ['GL', 'GLU']
				if BUILD.has_key('libs'):
					libs.extend(BUILD['libs'])


				directory,name = os.path.split( os.path.splitext(file)[0] )
				module = ".".join(
					directory.split( os.sep)[1:] +
					[ '_'+ name ],
				)

				BUILD['sources'].append('src/interface/' + module + '.c')
				self.ext_modules.append(Extension(module,
												  BUILD['sources'],
												  include_dirs = BUILD['include_dirs'],
												  define_macros = self.define_macros,
												  libraries = self.transform_libs(libs),
												  library_dirs = self.library_dirs,
												  extra_link_args = self.extra_link_args))

#		print self.libraries
		l = []
		for i in range(len(self.libraries)):
			d = self.libraries[i][1]
			d['include_dirs'] = [get_python_inc()] + self.include_dirs
			d['macros'] = self.define_macros
			l.append((self.libraries[i][0], d))
		self.libraries = l
Ejemplo n.º 10
0
 def test_remove_duplicates(self):
     file_list = FileList()
     file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
     file_list.sort()
     file_list.remove_duplicates()
     self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
Ejemplo n.º 11
0
"""distutils.command.sdist
Ejemplo n.º 12
0
    def _make_spec_file(self):
        """Generate the text of an RPM spec file and return it as a
        list of strings (one per line).
        """
        sdist = self.reinitialize_command('sdist')
        sdist.finalize_options()
        sdist.filelist = FileList()
        sdist.get_file_list()
        manifest = sdist.filelist.files

        # definitions and headers
        name = self.distribution.get_name()
        version = self.distribution.get_version().replace('-', '_')
        release = self.release.replace('-', '_')
        summary = self.distribution.get_description().strip().strip('.')

        spec_file = [
            '%define\toname\t' + name,
        ]
        if name[:2] == "py":
            spec_file.append('%define\tmodule\t' + name[2:])
            module = '%{module}'
        else:
            module = '%{oname}'

        spec_file.extend([
            '',
            'Name:\t\tpython-' + module,
            'Version:\t' + version,
            'Release:\t' + release,
            'Summary:\t' + summary,
            'Source0:\thttp://pypi.python.org/packages/source/%c/%%{oname}/%%{oname}-%%{version}.tar'
            % name[0],
        ])
        # XXX yuck! this filename is available from the "sdist" command,
        # but only after it has run: and we create the spec file before
        # running "sdist", in case of --spec-only.
        if sdist.formats and 'xztar' in sdist.formats:
            spec_file[-1] += '.xz'
        elif sdist.formats and 'bztar' in sdist.formats:
            spec_file[-1] += '.bz2'
        else:
            spec_file[-1] += '.gz'

        license = self.distribution.get_license()
        if license == "UNKNOWN":
            classifiers = self.distribution.get_classifiers()
            for classifier in classifiers:
                values = classifier.split(" :: ")
                if values[0] == "License":
                    license = values[-1]
        license.replace("GPL ", "GPLv").strip()
        spec_file.extend([
            'License:\t' + license,
            'Group:\t\t' + self.group,
        ])
        if self.distribution.get_url() != 'UNKNOWN':
            spec_file.append('Url:\t\t' + self.distribution.get_url())

        doc_names = [
            'README', 'CHANGES', 'ChangeLog', 'NEWS', 'THANKS', 'HISTORY',
            'AUTHORS', 'BUGS', 'ReleaseNotes', 'DISCLAIMER', 'TODO',
            'TROUBLESHOOTING', 'IDEAS', 'HACKING', 'WISHLIST', 'CREDITS',
            'PROJECTS', 'LEGAL', 'KNOWN_BUGS', 'MISSING_FEATURES', 'FAQ',
            'ANNOUNCE', 'FEATURES', 'WHATSNEW'
        ]
        license_names = ['LICENSE', 'COPYRIGHT', 'COPYING']
        common_licenses = glob('/usr/share/common-licenses/*')
        for i in range(len(common_licenses)):
            common_licenses[i] = os.path.basename(common_licenses[i])
        doc_names.extend(license_names)
        doc_suffixes = ('.doc', '.htm', '.txt', '.pdf', '.odt')

        self.doc_files = []
        all_files = []
        if self.distribution.data_files:
            all_files.extend(self.distribution.data_files)
        if manifest:
            all_files.extend(manifest)
        if all_files:
            for data_file in all_files:
                done = False
                for doc_name in doc_names:
                    if doc_name.lower() in data_file.lower():
                        if doc_name in license_names and license in common_licenses:
                            done = True
                            break
                        self.doc_files.append(data_file)
                        done = True
                        break
                if done:
                    continue
                for doc_suffix in doc_suffixes:
                    ext = os.path.splitext(data_file.lower())[1]
                    if ext.lower().startswith(doc_suffix.lower()):
                        self.doc_files.append(data_file)
                        break
        if not self.force_arch:
            # noarch if no extension modules
            if not self.distribution.has_ext_modules():
                spec_file.append('BuildArch:\tnoarch')
        else:
            spec_file.append('BuildArch:\t%s' % self.force_arch)

        for field in (
                'Provides',
                'Requires',
                'Conflicts',
                'Obsoletes',
        ):
            val = getattr(self, string.lower(field))
            if type(val) is ListType:
                spec_file.append('%s: %s' % (field, string.join(val)))
            elif val is not None:
                spec_file.append('%s: %s' % (field, val))

        build_requires = []
        if self.distribution.has_ext_modules():
            build_requires.append('python-devel')
        # Ugly, but should mostly work... :p
        if 'setuptools' in str(
                self.distribution.__dict__) or 'setuptools' in str(
                    sdist.__dict__):
            build_requires.append('python-setuptools')
        if build_requires:
            spec_file.append('BuildRequires:\t' + string.join(build_requires))

        if self.build_requires:
            spec_file.append('BuildRequires:\t' +
                             string.join(self.build_requires))

        spec_file.extend([
            '', '%description',
            self.distribution.get_long_description().strip()
        ])

        # insert contents of files

        # XXX this is kind of misleading: user-supplied options are files
        # that we open and interpolate into the spec file, but the defaults
        # are just text that we drop in as-is.  Hmmm.

        if 'test_suite' in self.distribution.__dict__ and self.distribution.test_suite:
            verify_script = "python setup.py test"
        else:
            verify_script = None

        script_options = [
            ('prep', 'prep_script', "%setup -q -n %{oname}-%{version}"),
            ('build', 'build_script', "python setup.py build"),
            ('install', 'install_script', ("python setup.py install "
                                           "--root=%{buildroot}")),
            ('check', 'verify_script', verify_script),
            ('pre', 'pre_install', None),
            ('post', 'post_install', None),
            ('preun', 'pre_uninstall', None),
            ('postun', 'post_uninstall', None),
        ]

        for (rpm_opt, attr, default) in script_options:
            # Insert contents of file referred to, if no file is referred to
            # use 'default' as contents of script
            val = getattr(self, attr)
            if val or default:
                spec_file.extend([
                    '',
                    '%' + rpm_opt,
                ])
                if val:
                    spec_file.extend(string.split(open(val, 'r').read(), '\n'))
                else:
                    spec_file.append(default)

        # files section
        spec_file.extend([
            '',
            '%files',
        ])
        for doc_file in self.doc_files:
            spec_file.append('%doc ' + doc_file)

        if self.distribution.has_ext_modules():
            site_pkgs = '%{py_platsitedir}'
        else:
            site_pkgs = '%{py_puresitedir}'
        if self.distribution.has_scripts():
            for script in self.distribution.scripts:
                if type(script) == StringType:
                    spec_file.append(
                        os.path.join('%{_bindir}', os.path.basename(script)))
        site_pkgs_files = []
        if self.distribution.data_files:
            for data_file in self.distribution.data_files:
                site_pkgs_files.append(os.path.join(site_pkgs, data_file))
        if 'entry_points' in self.distribution.__dict__ and self.distribution.entry_points:
            if type(self.distribution.entry_points) is DictType:
                for entry_points in self.distribution.entry_points:
                    for entry_point in self.distribution.entry_points[
                            entry_points]:
                        site_pkgs_files.append(
                            os.path.join(
                                '%{_bindir}',
                                os.path.basename(entry_point.split('=')[0])))
        if 'py_modules' in self.distribution.__dict__ and self.distribution.py_modules:
            for py_module in self.distribution.py_modules:
                py_module = py_module.replace('.', os.path.sep)
                site_pkgs_files.append(
                    os.path.join(site_pkgs, py_module + '.py*'))
        if 'packages' in self.distribution.__dict__ and self.distribution.packages:
            for package in self.distribution.packages:
                package = package.replace('.', os.path.sep)
                #spec_file.append('%dir ' + os.path.join(site_pkgs, package))
                site_pkgs_files.append(
                    os.path.join(site_pkgs, package, '*.py*'))
        if self.distribution.has_ext_modules():
            for ext_module in self.distribution.ext_modules:
                ext_module = ext_module.name.replace('.', os.path.sep)
                site_pkgs_files.append(
                    os.path.join(
                        site_pkgs, ext_module +
                        get_config_var('SHLIB_EXT').replace('"', '')))

        site_pkgs_files.sort()
        for f in site_pkgs_files:
            spec_file.append(f)

        spec_file.append(
            os.path.join(site_pkgs,
                         name.replace('-', '_') + '*.egg-info'))

        packager = rpm.expandMacro('%packager')

        spec_file.extend([
            '',
            '%changelog',
            '* Thu Oct 21 2010 %s %s-%s' % (packager, version, release),
            '- Initial release',
        ])
        return spec_file
Ejemplo n.º 13
0
 def run(self):
     self.filelist = FileList()
     self.add_defaults()
     self.make_distribution()
Ejemplo n.º 14
0
sys.path.insert(0, os.path.abspath('./src'))
from tel import config

long_description = """\
tel is a little console-based phone book program. It allows adding,
modifing, editing and searching of phone book entries right on your
terminal. Pretty printing capabilites are also provided.
Entries are stored in simple csv file. This eases import and export with
common spread sheet applications like Microsoft Excel or OpenOffice.org
Calc."""

# gettext source file for i18n
optparse_source = optparse.__file__.rstrip('c')

# collect all python sources for i18n
tel_sources = FileList()
tel_sources.findall('./src')
tel_sources.include_pattern('*.py', anchor=False)

setup(
    name='tel',
    version=config.version,
    description='A little terminal phone book',
    long_description=long_description,
    author='Sebastian Wiesner',
    author_email='*****@*****.**',
    url='http://tel.lunaryorn.de',
    license='MIT/X11',
    # list packages
    packages=['tel'],
    package_dir={'': 'src'},