def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) # initialize locale locale = QSettings().value("locale/userLocale")[0:2] localePath = os.path.join(self.plugin_dir, 'i18n', 'postgisquerybuilder_{}.qm'.format(locale)) if os.path.exists(localePath): self.translator = QTranslator() self.translator.load(localePath) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) #self.dlg = uic.loadUi( os.path.join( os.path.dirname( os.path.abspath( __file__ ) ), "ui_postgisquerybuilder.ui" ) ) self.querySet = querySet() self.PSQL = PSQL(self.iface)
def main(): parser = argparse.ArgumentParser( description='Initialize or update a Postgres database with OSM data') parser.add_argument( '-i', '--init', dest='initialize', action='store_const', const=True, default=False, help='Initialize the database and supply a planet file') parser.add_argument( '-u', '--update', dest='update', action='store_const', const=True, default=False, help='Update and initialized database by downloading updates') parser.add_argument('-f', '--filter', dest='filter_path', default='./config/filter.json', help='Filter file') parser.add_argument('-b', '--base_url', dest='base_url', default='https://planet.osm.ch/replication', help='Planet website. Used both in init and update') parser.add_argument( '-m', '--mode', dest='mode', default='hour', help='replication mode (hour, minute...). Used both in init and update' ) parser.add_argument('-ph', '--psqlhost', dest='psqlhost', required=True, help='Postgres host') parser.add_argument('-ppo', '--psqlport', dest='psqlport', default=5432, help='Postgres port') parser.add_argument('-pd', '--psqldb', dest='psqldb', required=True, help='Postgres database') parser.add_argument('-pu', '--psqluser', dest='psqluser', required=True, help='Postgres user') parser.add_argument('-pp', '--psqlpassword', dest='psqlpassword', required=True, help='Postgres password') parser.add_argument( '-p', '--planet', dest='planet_path', default=None, help='Planet file in pbf format. Option valid only if --init is used') parser.add_argument('-d', '--debug', dest='debug', action='store_const', const=True, default=False, help='Debug mode') args = parser.parse_args() if args.initialize and args.update: return print('Select either --init or --update, not both') if not args.initialize and not args.update: return print('Select one of --init or --update') if args.initialize and args.planet_path is None: return print('To initialize, we need a planet file (-p)') if args.update and args.planet_path: print('Ignoring planet file during updatess') setup_logging(args.debug) logging.debug('Options parsed') logging.info(f'base url: {args.base_url}, mode: {args.mode}') filt = Filter(args.filter_path) if filt is None: return psql = PSQL(args.psqlhost, args.psqlport, args.psqldb, args.psqluser, args.psqlpassword) if args.initialize: try: initializer = Initializer(args, psql, filt) initializer.start() except: logging.critical('Something came up.', exc_info=True) return psql.stop() logging.info('Stopping PSQL. It might take some seconds')