def import_all(): db = declarative_base() set_db(db) fs = filesystem.Filesystem().fs for file in fs.listdir('data/Feeder/public/'): feeder_path = join("data/Feeder/public/", file) # without omf, due to HOME_DIR in filesystem class Converter.convert(feeder_path, the_config.POSTGIS_DB_URI, -92.3395017, 38.9589246, 1)
def saveFeederFromGeoData(feederId): user_name = current_user_name() logger.info("Saving feeder: {} to json".format(feederId)) feeder_data = Converter.deconvert(feederId, the_config.POSTGIS_DB_URI) logger.info("Saving feeder: {} to filesystem".format(feeder_data[0])) fs.save("data/Feeder/" + user_name + "/" + feeder_data[0], json.dumps(feeder_data[1])) return "Success"
def importBackground(owner, feederName, convertFunc, convertArgs): ''' Function to run in the background for Milsoft import. ''' file_name = "/" + feederName + ".json" user_conversion_folder = "data/Conversion/" + owner user_feeder_folder = "data/Feeder/" + owner newFeeder = dict(**feeder.newFeederWireframe) [newFeeder["tree"], xScale, yScale] = convertFunc(*convertArgs) newFeeder["layoutVars"]["xScale"] = xScale newFeeder["layoutVars"]["yScale"] = yScale logger.info('Attaching schedules.glm file') with open("./schedules.glm", "r") as schedFile: newFeeder["attachments"] = {"schedules.glm": schedFile.read()} logger.info('Save new feeder %s as new json file', feederName) fs.save(user_feeder_folder + file_name, json.dumps(newFeeder, indent=4)) fs.remove(user_conversion_folder + file_name) Converter.convert(user_feeder_folder + file_name, the_config.POSTGIS_DB_URI, _LON, _LAT, flask_login.current_user.id)