Example #1
0
    def _check_import(self):
        """Check if there are any POI in the old format
           and try to import them to the db (into the "other" category)
           then rename the old poi file to prevent multiple imports"""

        oldPOIPath = "data/poi/poi.txt"
        if os.path.exists(oldPOIPath):
            try:
                renamedOldPOIPath = "data/poi/imported_old_poi.txt"
                self.log.info("importing old POI from: %s", oldPOIPath)
                points = self._load_old_poi(oldPOIPath)
                if points:
                    for point in points:
                        # create a new POI object
                        name = point.name
                        description = point.description.replace('|', '\n')
                        lat = point.lat
                        lon = point.lon
                        catId = 11
                        newPOI = POI(name, description, lat, lon, catId)
                        newPOI.commit()
                    self.log.info("imported %d old POI", len(points))
                    os.rename(oldPOIPath, renamedOldPOIPath)
                    self.log.info("old POI file moved to: %s",
                                  renamedOldPOIPath)
                    self.sendMessage(
                        'ml:notification:m:%d old POI imported to category "Other";10'
                        % len(points))
            except Exception:
                self.log.exception("import of old POI failed")
Example #2
0
    def _check_import(self):
        """Check if there are any POI in the old format
           and try to import them to the db (into the "other" category)
           then rename the old poi file to prevent multiple imports"""

        oldPOIPath = "data/poi/poi.txt"
        if os.path.exists(oldPOIPath):
            try:
                renamedOldPOIPath = "data/poi/imported_old_poi.txt"
                self.log.info("importing old POI from: %s", oldPOIPath)
                points = self._load_old_poi(oldPOIPath)
                if points:
                    for point in points:
                        # create a new POI object
                        name = point.name
                        description = point.description.replace('|', '\n')
                        lat = point.lat
                        lon = point.lon
                        catId = 11
                        newPOI = POI(name, description, lat, lon, catId)
                        newPOI.commit()
                    self.log.info("imported %d old POI", len(points))
                    os.rename(oldPOIPath, renamedOldPOIPath)
                    self.log.info("old POI file moved to: %s", renamedOldPOIPath)
                    self.sendMessage('ml:notification:m:%d old POI imported to category "Other";10' % len(points))
            except Exception:
                self.log.exception("import of old POI failed")
Example #3
0
 def __init__(self, poi):
     POI.__init__(self,
                  name=poi.name,
                  description=poi.description,
                  lat=poi.lat,
                  lon=poi.lon,
                  db_cat_id=poi.db_category_index,
                  db_poi_id=poi.db_index)
Example #4
0
    def storeLocalSearchResult(self, result):
        """Store a local search result to the database"""

        (lat, lon) = result.getLL()
        newPOI = POI(name=result.name,
                     description=result.description,
                     lat=lat,
                     lon=lon,
                     db_cat_id=None)

        self.tempOnlinePOI = newPOI

        # start the name and description entry chain
        entry = self.m.get('textEntry', None)
        if entry:
            entry.entryBox(self, 'onlineResultName', 'POI Name', result.name)
Example #5
0
    def get_poi(self, poi_db_index):
        """Return a complete POI row from db fow a given POI id

        :param int poi_db_index: database index of the POI to retrieve from the database
        :returns: POI object or None
        :rtype: POI or None
        """
        if self.connected:
            result = self._db.execute(
                'select poi_id, lat, lon, label, desc, cat_id from poi where poi_id=?',
                [poi_db_index]).fetchone()
            if result:
                (poi_id, lat, lon, name, desc, cat_id) = result
                # make it more usable
                poiObject = POI(name, desc, lat, lon, cat_id, poi_id)
                return poiObject
            else:
                return None
        else:
            return None
Example #6
0
    def _addPOI(self):
        """Add a poi to the database"""
        self._disableStdout()
        from core import geo
        coords = geo.parse_geo_coords(self.args.poi_add_coords)
        if coords is None:
            self._enableStdout()
            print(
                "coordinate format parsing failed, should be: geo:latitude,longitude"
            )
            self._exit(COORDINATE_PARSING_ERROR)
        else:
            from core.point import POI
            lat, lon = coords
            store_poi = self.modrana._load_module("mod_storePOI", "storePOI")
            cat_id, cat_name = self._find_category(store_poi,
                                                   self.args.poi_category)
            if cat_id is None:
                self._enableStdout()
                print(
                    "invalid category specification (%s), falling back to default (%s)"
                    % (self.args.poi_category, "Other"))
                self._disableStdout()
                cat_id = 11
                cat_name = "Other"

            poi = POI(lat=lat,
                      lon=lon,
                      name=self.args.poi_name,
                      description=self.args.poi_description,
                      db_cat_id=cat_id)
            store_poi.db.store_poi(poi)
            self._enableStdout()
            print("point added to the modRana POI database (category: %d/%s)" %
                  (cat_id, cat_name))
            self._exit(0)
Example #7
0
    def storePoint(self, point, returnToMenu=False):
        """Store a given point to the POI database"""
        # TODO: automatic saving without asking
        # * skip name entry
        # * and/or skip category entry
        (lat, lon) = point.getLL()
        newPOI = POI(name=point.name,
                     description=point.description,
                     lat=lat,
                     lon=lon,
                     db_cat_id=None)

        # temporarily store the new POI to make it
        # available during filling its name, description, etc.
        self.tempOnlinePOI = newPOI
        self.menuNameAfterStorageComplete = returnToMenu

        # start the name and description entry chain
        entry = self.m.get('textEntry', None)
        if entry:
            entry.entryBox(self,
                           'onlineResultName',
                           'POI Name',
                           initialText=point.name)
Example #8
0
 def getEmptyPOI(self):
     """Get a POI with all variables set to None"""
     poiObject = POI(None, None, None, None, None, None)
     return poiObject
Example #9
0
 def __init__(self, poi):
     POI.__init__(self, name=poi.name, description=poi.description, lat=poi.lat, lon=poi.lon,
                  db_cat_id=poi.db_category_index, db_poi_id=poi.db_index)