cleaning up, pep8 fix and changing tabs to spaces

This commit is contained in:
volpino 2012-03-27 18:58:19 +02:00
parent ac6c57cb57
commit 06bef562e8
2 changed files with 58 additions and 59 deletions

View File

@ -16,7 +16,6 @@ __version__ = "git"
""" Imports """ """ Imports """
import os
import sys import sys
import getopt import getopt
import errno import errno
@ -208,7 +207,7 @@ def main():
try: try:
ret = scan_upstream(package) ret = scan_upstream(package)
except AmbiguousPackageName as e: except AmbiguousPackageName as e:
pkgs = e.args[0] pkgs = e.args[0]
for candidate in pkgs: for candidate in pkgs:
print(candidate) print(candidate)
@ -219,7 +218,7 @@ def main():
print(pp.error("The short ebuild name '%s' is ambiguous. Please specify" % basename(pkgs[0])), print(pp.error("The short ebuild name '%s' is ambiguous. Please specify" % basename(pkgs[0])),
file=sys.stderr, end="") file=sys.stderr, end="")
pp.die(1, "one of the above fully-qualified ebuild names instead.") pp.die(1, "one of the above fully-qualified ebuild names instead.")
except GentoolkitException as err: except GentoolkitException as err:
pp.die(1, '%s: %s' % (package, str(err))) pp.die(1, '%s: %s' % (package, str(err)))
except Exception as err: except Exception as err:
pp.die(1, '%s: %s' % (package, str(err))) pp.die(1, '%s: %s' % (package, str(err)))

112
setup.py
View File

@ -6,9 +6,9 @@ import re
import sys import sys
from distutils import log from distutils import log
try: try:
from setuptools import setup, Command from setuptools import setup, Command
except ImportError: except ImportError:
from distutils.core import setup, Command from distutils.core import setup, Command
from glob import glob from glob import glob
import os import os
@ -22,75 +22,75 @@ cwd = os.getcwd()
# Load EPREFIX from Portage, fall back to the empty string if it fails # Load EPREFIX from Portage, fall back to the empty string if it fails
try: try:
from portage.const import EPREFIX from portage.const import EPREFIX
except ImportError: except ImportError:
EPREFIX = '' EPREFIX = ''
# Python files that need `__version__ = ""` subbed, relative to this dir: # Python files that need `__version__ = ""` subbed, relative to this dir:
python_scripts = [os.path.join(cwd, path) for path in ( python_scripts = [os.path.join(cwd, path) for path in (
'bin/euscan', 'bin/euscan',
)] )]
class set_version(Command): class set_version(Command):
"""Set python __version__ to our __version__.""" """Set python __version__ to our __version__."""
description = "hardcode scripts' version using VERSION from environment" description = "hardcode scripts' version using VERSION from environment"
user_options = [] # [(long_name, short_name, desc),] user_options = [] # [(long_name, short_name, desc),]
def initialize_options(self): def initialize_options(self):
pass pass
def finalize_options(self): def finalize_options(self):
pass pass
def run(self): def run(self):
ver = 'git' if __version__ == '9999' else __version__ ver = 'git' if __version__ == '9999' else __version__
print("Settings version to %s" % ver) print("Settings version to %s" % ver)
def sub(files, pattern): def sub(files, pattern):
for f in files: for f in files:
updated_file = [] updated_file = []
with io.open(f, 'r', 1, 'utf_8') as s: with io.open(f, 'r', 1, 'utf_8') as s:
for line in s: for line in s:
newline = re.sub(pattern, '"%s"' % ver, line, 1) newline = re.sub(pattern, '"%s"' % ver, line, 1)
if newline != line: if newline != line:
log.info("%s: %s" % (f, newline)) log.info("%s: %s" % (f, newline))
updated_file.append(newline) updated_file.append(newline)
with io.open(f, 'w', 1, 'utf_8') as s: with io.open(f, 'w', 1, 'utf_8') as s:
s.writelines(updated_file) s.writelines(updated_file)
quote = r'[\'"]{1}' quote = r'[\'"]{1}'
python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote
sub(python_scripts, python_re) sub(python_scripts, python_re)
packages = [ packages = [
str('.'.join(root.split(os.sep)[1:])) str('.'.join(root.split(os.sep)[1:]))
for root, dirs, files in os.walk('pym/euscan') for root, dirs, files in os.walk('pym/euscan')
if '__init__.py' in files if '__init__.py' in files
] ]
setup( setup(
name='euscan', name='euscan',
version=__version__, version=__version__,
description='Ebuild upstream scan utility.', description='Ebuild upstream scan utility.',
author='Corentin Chary', author='Corentin Chary',
author_email='corentin.chary@gmail.com', author_email='corentin.chary@gmail.com',
maintainer='Corentin Chary', maintainer='Corentin Chary',
maintainer_email='corentin.chary@gmail.com', maintainer_email='corentin.chary@gmail.com',
url='http://euscan.iksaif.net', url='http://euscan.iksaif.net',
download_url=( download_url=(
'https://github.com/iksaif/euscan/tarball/' + 'https://github.com/iksaif/euscan/tarball/' +
('master' if __version__ == '9999' else ('euscan-%s' % __version__)) ('master' if __version__ == '9999' else ('euscan-%s' % __version__))
), ),
install_requires=['django-annoying'], install_requires=['django-annoying'],
package_dir={'': 'pym'}, package_dir={'': 'pym'},
packages=packages, packages=packages,
package_data={}, package_data={},
scripts=python_scripts, scripts=python_scripts,
data_files=( data_files=(
(os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'usr/share/man/man1'), (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'usr/share/man/man1'),
glob('man/*')), glob('man/*')),
), ),
cmdclass={ cmdclass={
'set_version': set_version, 'set_version': set_version,
}, },
) )