Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
os.chdir(django_path)
except:
log("Failed to move Django project directory.", withError = True,
errorDetail = "Config directory: " + str(os.getcwd()) + "/" + mfile.get_django(Category.django_path))
return
try:
try:
devnull = open('/dev/null', 'w')
server = subprocess.Popen(shlex.split("mi internal_server_launch"), stdout=devnull, stderr=devnull)
except:
log("Failed to launch server!", withError = True)
log("Launching shell...")
log("Server listening started on http://127.0.0.1:5050")
log("Ctl + C to exit scaffold.")
time.sleep(1)
webbrowser.open("http://127.0.0.1:5050")
server.wait()
except KeyboardInterrupt:
server.kill()
if fileable.exists("Miragefile"):
if log("Miragefile is exists. Are you sure to overwrite Miragefile?", withConfirm = True):
os.remove("Miragefile")
else:
log("Miragefile is already exists!", withError = True)
raise FileExistsError
return
app_name = log("App name", withInput = True)
version = log("App version", withInput = True)
author = log("Author name", withInput = True)
email = log("Email", withInput = True)
git_url = log("Git URL", withInput = True)
license_name = log("License", withInput = True)
description = log("Description", withInput = True)
copyrightor = log("Copyrightor", withInput = True, default = author)
with open("Miragefile", "w") as f:
f.write(source.create(app_name, version, author, email, git_url, license_name, description, copyrightor))
def __detect_master_app(self):
try:
dirs = os.listdir(os.getcwd())
except:
log("Failed to detect Django apps.", withError = True)
current = os.getcwd()
for app in dirs:
try:
os.chdir("./" + app)
if os.path.isfile("settings.py"):
log("Master app " + app + " detected.")
os.chdir(current)
return app
else:
os.chdir(current)
except:
pass
def flow(self):
model_classies = self._third_args[0]
model_contents = self._third_args[1:len(self._third_args)]
model_body = self.__make_model_body(model_contents)
modelpy = create_model_class(model_classies, model_body)
if os.path.isfile("manage.py"):
log("Please generate model inside the Django app directory.", withError = True)
try:
with open("models.py", "a") as writing:
writing.write(modelpy)
except:
log("Failed to open models.py", withError = True)
def _configure_addition(self):
if fileable.exists("Miragefile.addon"):
if log("Miragefile (Additional) is exists. Are you sure to overwrite?", withConfirm = True):
os.remove("Miragefile.addon")
else:
log("Miragefile is already exists!", withError = True)
raise FileExistsError
return
option_string = log("Additional option string", withInput = True)
with open("Miragefile.addon", "w") as f:
f.write(create_additional(option_string))
def _reset_db(self):
msg = "This action will remove ALL stored data in database and data can't be restored!\nDo you confirm to continue this action?"
if project.in_project():
if log(msg, withConfirm = True):
self._remove_sqlite()
else:
log("Canceled.")
else:
log("Failed to reset database.", withError = True, errorDetail = """
Django Console Database Manager Error!s
def _install_app(self, name):
try:
current = os.getcwd()
except:
log("Failed to get current.", withError = True)
try:
master_app = self.__detect_master_app()
except:
log("Failed to detect master app.", withError = True)
log("Installing created app...")
os.chdir(master_app)
if os.path.isfile("settings.py"):
self.__insert_app_path(name)
else:
log("Failed to install Django app due to missing configuration file.", withError = True)
os.chdir(current)
def get_private_profile(item):
data = load_miragefile_secret()
if item == "name":
return data["private_profile"]["name"]
elif item == "license":
return data["private_license"]["url"]
else:
log("The config information named " + item + " does not exist!", withError = True)
return load_failed()
def main(self):
log("Runnng server...")
if project.in_project():
try:
os.system("python manage.py runserver")
# time.sleep(1)
# webbrowser.open("http://127.0.0.1:8000/")
except KeyboardInterrupt:
log("Good bye!")
else:
log("Failed to launch server!", withError = True, errorDetail = "You are now out of Django project.")
def _install_app(self, name):
try:
current = os.getcwd()
except:
log("Failed to get current.", withError = True)
try:
master_app = self.__detect_master_app()
except:
log("Failed to detect master app.", withError = True)
log("Installing created app...")
os.chdir(master_app)
if os.path.isfile("settings.py"):
self.__insert_app_path(name)
else:
log("Failed to install Django app due to missing configuration file.", withError = True)
os.chdir(current)