Example #1
0
def cmdline():
    parser = VeliberatorOptionParser(
        usage=_('%prog [station_id] [address] [options]'),
        version='%s %s' % ('%prog', veliberator.__version__))
    parser.add_option('-d', '--database', dest='database',
                      help=_('The SQLURI of the database'),
                      default=DATABASE_URI)
    parser.add_option('-p', '--places', dest='places', type='int',
                      help=_('The number of places you want'), default=1)
    parser.add_option('-m', '--max-stations', dest='max_stations', type='int',
                      help=_('The maximun stations around proposed'),
                      default=5)
    parser.add_option('--synchronize', dest='synchronize', action='store_true',
                      help=_('Only do a synchronization of the cartography'))
    (options, args) = parser.parse_args()

    print '-==* Veliberator v%s *==-' % veliberator.__version__

    try:
        db_connection(options.database)
    except sqlalchemy.exc.OperationalError:
        if options.synchronize:
            sys.exit(_('-> The database %s is unreachable.') %
                     options.database)
        else:
            print _('-> The database is unreachable, switch on RAM.')
            print _('-> Edit the configuration file, '
                    'for removing this message.')
            db_connection('sqlite://')

    if options.synchronize:
        synchronization()
        sys.exit(0)

    if not StationInformation.query.count():
        synchronization()

    if args:
        user_input = args[0]
    else:
        user_input = raw_input(_('Station ID or complete address:\n'))

    if user_input.isdigit():
        try:
            station = Station(user_input)
        except UnknowStation:
            sys.exit(_('The Station ID does not exist.'))
        show_status(station)
        if not station.is_free(options.places):
            print _('Searching on the closest stations...')
            display_free_stations(station.stations_around,
                                  options.places, options.max_stations)
    else:
        try:
            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)
Example #2
0
 def acquire_informations(self):
     """Default method for acquiring informations
     of a stations, by connecting to the database"""
     try:
         return StationInformation.get(self.id)
     except AttributeError:
         db_connection()
         return StationInformation.get(self.id)
Example #3
0
"""Global suite of tests"""
import unittest

from veliberator.models import db_connection
from veliberator.tests.test_models import suite as models_suite
from veliberator.tests.test_xml_wrappers import suite as xml_suite
from veliberator.tests.test_station import suite as station_suite
from veliberator.tests.test_cartography import suite as cartography_suite
from veliberator.tests.test_status import suite as status_suite
from veliberator.tests.test_geofinder import suite as geofinder_suite
from veliberator.tests.test_grabber import suite as grabber_suite

db_connection("sqlite:///:memory:")

global_test_suite = unittest.TestSuite(
    [models_suite, xml_suite, station_suite, cartography_suite, status_suite, geofinder_suite, grabber_suite]
)