Added option to identify the fleets by id raher than names in command line
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 7 Nov 2010 11:37:13 +0000 (11:37 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 7 Nov 2010 11:37:13 +0000 (11:37 +0000)
parameters.

bin/common.py
bin/show_targets_ships.py

index f97420b8e5291002c2854fa794228287e99e5bef..e7fba43e1cf34370b42dd5d4e246e7c7349f6267 100755 (executable)
@@ -32,6 +32,7 @@ __all__ = [
     'NmeaFeeder',
     'all_mmsi_generator',
     'load_fleet_to_uset',
+    'fleetname_to_fleetid',
     'filter_area',
     'filter_knownposition',
     'filter_speedcheck',
@@ -1712,13 +1713,13 @@ def all_mmsi_generator():
                 yield fname[:-6]
 
 
-def load_fleet_to_uset(fleetname):
+def load_fleet_to_uset(fleetid):
     """
-    Loads a fleet by name-id.
+    Loads a fleet by id.
     Returns an array of strmmsi.
     """
     result = []
-    sqlexec(u"SELECT mmsi FROM fleet_vessel JOIN fleet ON (fleet_vessel.fleet_id = fleet.id) WHERE fleet.name=%(fleetname)s", {'fleetname': fleetname})
+    sqlexec(u"SELECT mmsi FROM fleet_vessel WHERE fleet_id=" + unicode(fleetid))
     cursor = get_common_cursor()
     while True:
         row = cursor.fetchone()
@@ -1730,6 +1731,13 @@ def load_fleet_to_uset(fleetname):
     return result
 
 
+def fleetname_to_fleetid(fleetname):
+    sqlexec(u"SELECT id FROM fleet WHERE name=%(fleetname)s", {'fleetname': fleetname})
+    cursor = get_common_cursor()
+    row = cursor.fetchone()
+    return row[0]
+
+
 def filter_area(nmea, area):
     """
     Returns false if position is out of area.
@@ -1792,7 +1800,7 @@ def main():
     from optparse import OptionParser, OptionGroup
     global DBPATH
 
-    parser = OptionParser(usage='%prog [options] { mmsi | @fleet }+ | all')
+    parser = OptionParser(usage='%prog [options] { mmsi | @fleetname | ^fleetid }+ | all')
 
     parser.add_option('-d', '--debug',
         action='store_true', dest='debug', default=False,
@@ -1906,7 +1914,9 @@ def main():
         if arg == 'all':
             all_targets = True
         elif arg.startswith('@'):
-            target_mmsi_iterator += load_fleet_to_uset(arg[1:])
+            target_mmsi_iterator += load_fleet_to_uset(fleetname_to_fleetid(arg[1:]))
+        elif arg.startswith('^'):
+            target_mmsi_iterator += load_fleet_to_uset(int(arg[1:]))
         else:
             target_mmsi_iterator.append(arg)
     if all_targets:
index d41730359867f6990c36f16fce289a21141edc89..8662eb75a774f18b1c3ef7636c65afd3dfe5b0fc 100755 (executable)
@@ -443,7 +443,7 @@ def main():
     global DBPATH, STYLE
     from optparse import OptionParser, OptionGroup
 
-    parser = OptionParser(usage='%prog [options] { mmsi | @fleetfile }+ | all')
+    parser = OptionParser(usage='%prog [options] { mmsi | @fleetname | #fleetid }+ | all')
 
     parser.add_option('-d', '--debug',
         action='store_true', dest='debug', default=False,
@@ -567,7 +567,9 @@ def main():
         if arg == 'all':
             all_targets = True
         elif arg.startswith('@'):
-            target_mmsi_iterator += load_fleet_to_uset(arg[1:])
+            target_mmsi_iterator += load_fleet_to_uset(fleetname_to_fleetid(arg[1:]))
+        elif arg.startswith('^'):
+            target_mmsi_iterator += load_fleet_to_uset(int(arg[1:]))
         else:
             target_mmsi_iterator.append(arg)
     if all_targets: