Skip to content

Commit

Permalink
Merge branch 'feature/cmd-line' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Mar 16, 2015
2 parents 62b9a83 + 0bbc1ba commit f1f9b07
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
7 changes: 5 additions & 2 deletions setup.py
Expand Up @@ -21,15 +21,18 @@
keywords='velib, api, service',

classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'License :: OSI Approved :: BSD License',
'Topic :: Software Development :: Libraries :: Python Modules'
],

scripts=['./veliberator/scripts/veliberator'],
entry_points={
'console_scripts': [
'veliberator=veliberator.scripts.command_line:cmdline',
]
},
test_suite='veliberator.tests.global_test_suite',
packages=find_packages(exclude=['tests']),

Expand Down
3 changes: 3 additions & 0 deletions veliberator/scripts/__init__.py
@@ -0,0 +1,3 @@
"""
Scripts for veliberator
"""
33 changes: 19 additions & 14 deletions veliberator/scripts/veliberator → veliberator/scripts/command_line.py 100755 → 100644
@@ -1,4 +1,6 @@
#!/usr/bin/python
"""
Veliberator script
"""
import os
import sys
import gettext
Expand All @@ -18,9 +20,11 @@
from veliberator.models import StationInformation


gettext.install('veliberator', os.path.join(
os.path.dirname(veliberator.__file__), 'locale'),
names='ngettext')
translation = gettext.translation(
'veliberator',
os.path.join(os.path.dirname(veliberator.__file__), 'locale'))
_ = translation.gettext
__ = translation.ngettext


def synchronization():
Expand All @@ -38,13 +42,13 @@ def show_status(station, distance=None):
else:
print station.informations.full_address

print ngettext('%(available)s/%(total)s bike available',
'%(available)s/%(total)s bikes available',
station.status.available) % {
print __('%(available)s/%(total)s bike available',
'%(available)s/%(total)s bikes available',
station.status.available) % {
'available': station.status.available,
'total': station.status.total}
print ngettext('%s parking place', '%s parking places',
station.status.free) % station.status.free
print __('%s parking place', '%s parking places',
station.status.free) % station.status.free


def display_free_stations(stations, places, max_display):
Expand All @@ -59,6 +63,7 @@ def display_free_stations(stations, places, max_display):
show_status(station, station_information.distance)
displayed += 1


class VeliberatorOptionParser(OptionParser):
"""Customized OptionParser with
correct gettext handling"""
Expand All @@ -74,11 +79,10 @@ def _add_version_option(self):
def print_help(self, file=None):
if file is None:
file = sys.stdout
encoding = self._get_encoding(file)
file.write(self.format_help())


if __name__ == '__main__':
def cmdline():
parser = VeliberatorOptionParser(
usage=_('%prog [station_id] [address] [options]'),
version='%s %s' % ('%prog', veliberator.__version__))
Expand All @@ -104,7 +108,7 @@ def print_help(self, file=None):
options.database)
else:
print _('-> The database is unreachable, switch on RAM.')
print _('-> Edit the configuration file, '\
print _('-> Edit the configuration file, '
'for removing this message.')
db_connection('sqlite://')

Expand Down Expand Up @@ -135,5 +139,6 @@ def print_help(self, file=None):
finder = AddressGeoFinder(user_input)
except GeoFinderError:
sys.exit(_('The provided address is not valid or imprecise.'))
display_free_stations(finder.get_stations_around(STATION_AROUND_RADIUS),
options.places, options.max_stations)
display_free_stations(
finder.get_stations_around(STATION_AROUND_RADIUS),
options.places, options.max_stations)

0 comments on commit f1f9b07

Please sign in to comment.