def create_db_user(self): # Setup the database user if self.creating: print("\nCreating database user") django_command_line(["", "createsuperuser"])
def execute_from_command_line(argv=None): opts = docopt(__doc__, argv=argv, version=iepy.__version__) folder_path = opts["<folder_path>"] if opts["--download-third-party-data"]: download_third_party_data() return abs_folder_path = os.path.abspath(folder_path) if os.path.exists(folder_path): print("Error: folder already exists") sys.exit(1) files_to_copy = [ os.path.join(THIS_FOLDER, "csv_to_iepy.py"), os.path.join(THIS_FOLDER, "preprocess.py"), os.path.join(THIS_FOLDER, "iepy_runner.py"), os.path.join(THIS_FOLDER, "iepy_rules_runner.py"), os.path.join(THIS_FOLDER, "manage.py"), ] # Create folders bin_folder = os.path.join(folder_path, "bin") os.mkdir(folder_path) os.mkdir(bin_folder) for filepath in files_to_copy: filename = os.path.basename(filepath) destination = os.path.join(bin_folder, filename) shutil.copyfile(filepath, destination) # Create empty rules file rules_filepath = os.path.join(folder_path, "rules.py") with open(rules_filepath, "w") as filehandler: filehandler.write("# Write here your rules\n") filehandler.write("# RELATION = 'your relation here'\n") # Create extractor config extractor_config_filepath = os.path.join(folder_path, "extractor_config.json") with open(extractor_config_filepath, "w") as filehandler: json.dump(defaults.extractor_config, filehandler, indent=4) # Create the settings file print("Initializing database") folder_name = folder_path.rsplit(os.sep, 1) folder_name = folder_name[1] if len(folder_name) > 1 else folder_name[0] database_name = input("Database name [{}]: ".format(folder_name)) if not database_name: database_name = folder_name database_path = os.path.join(abs_folder_path, database_name) new_settings_filepath = "{}_settings.py".format(folder_name) settings_filepath = os.path.join(folder_path, new_settings_filepath) settings_data = get_settings_string(database_path) with open(settings_filepath, "w") as filehandler: filehandler.write(settings_data) # Setup IEPY with the new instance os.chdir(abs_folder_path) iepy.setup(abs_folder_path) django_command_line(["", "migrate"]) # Setup the database user print("\nCreating database user") django_command_line(["", "createsuperuser"]) print("\n IEPY instance ready to use at '{}'".format(abs_folder_path))
def migrate_db(self): # Setup IEPY with the new instance os.chdir(self.abs_folder_path) iepy.setup(self.abs_folder_path) django_command_line(["", "migrate"])
def execute_from_command_line(argv=None): opts = docopt(__doc__, argv=argv, version=0.1) folder_path = opts["<folder_path>"] if opts["--download-third-party-data"]: download_third_party_data() return abs_folder_path = os.path.abspath(folder_path) if os.path.exists(folder_path): print("Error: folder already exists") sys.exit(1) files_to_copy = [ os.path.join(THIS_FOLDER, "csv_to_iepy.py"), os.path.join(THIS_FOLDER, "preprocess.py"), os.path.join(THIS_FOLDER, "iepy_runner.py"), os.path.join(THIS_FOLDER, "iepy_rules_runner.py"), os.path.join(THIS_FOLDER, "manage.py"), ] # Create folders bin_folder = os.path.join(folder_path, "bin") os.mkdir(folder_path) os.mkdir(bin_folder) for filepath in files_to_copy: filename = os.path.basename(filepath) destination = os.path.join(bin_folder, filename) shutil.copyfile(filepath, destination) # Create empty rules file rules_filepath = os.path.join(folder_path, "rules.py") with open(rules_filepath, "w") as filehandler: filehandler.write("# Write here your rules\n") filehandler.write("# RELATION = 'your relation here'\n") # Create extractor config extractor_config_filepath = os.path.join(folder_path, "extractor_config.json") with open(extractor_config_filepath, "w") as filehandler: json.dump(defaults.extractor_config, filehandler, indent=4) # Create the settings file print("Initializing database") folder_name = folder_path.rsplit(os.sep, 1) folder_name = folder_name[1] if len(folder_name) > 1 else folder_name[0] database_name = input("Database name [{}]: ".format(folder_name)) if not database_name: database_name = folder_name database_path = os.path.join(abs_folder_path, database_name) new_settings_filepath = "{}_settings.py".format(folder_name) settings_filepath = os.path.join(folder_path, new_settings_filepath) settings_data = get_settings_string(database_path) with open(settings_filepath, "w") as filehandler: filehandler.write(settings_data) # Setup IEPY with the new instance os.chdir(abs_folder_path) iepy.setup(abs_folder_path) django_command_line(["", "migrate"]) # Setup the database user print("\nCreating database user") django_command_line(["", "createsuperuser"]) print("\n IEPY instance ready to use at '{}'".format(abs_folder_path))