Example #1
0
def get_django_version():
    try:
        import django
        version = django.VERSION
        return str(version[0]) + "." + str(version[1]) + "." + str(version[2])
    except:
        log("Failed to import Django!", withError=True)
        return "FAILED TO IMPORT DJANGO!"
Example #2
0
 def _check_before(self):
     
     try:
         import django
     except ImportError:
         log("Failed to import Django!", withError = True,
                             errorDetail = "You have to install Django before creating a new Django project.")
         raise ImportError
Example #3
0
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()
Example #4
0
def _load_json(filename):

    if not os.path.exists(filename):
        return filename + " does not exist!"

    with open(filename, "r") as jsonfile:
        try: 
            return json.load(jsonfile)
        except:
            log("Failed to load Miragefile!", withError = True, errorDetail = raise_error_message(_load_json))
            return load_failed()
Example #5
0
def get_copyright(item):

    data = load_miragefile()

    if item == MiragefileDataCategory.copyright_start_year:
        return data["project"]["copyright"]["start_year"]
    elif item == MiragefileDataCategory.copyright_copyrigtors:
        return data["project"]["copyright"]["copyrightors"]
    else:
        log("The config information named " + item + " does not exist!", withError = True) 
        return load_failed()
Example #6
0
def get_reserved_addon_config(item):

    data = load_miragefile_addon()

    if item == "iyashi":
        try:
            return data["additional_options"]["iyashi"]
        except:
            return False
    else:
        log("The config information named " + item + " does not exist!", withError = True) 
        return load_failed()
Example #7
0
    def flow(self):
        try:
            self._check_all()
        except:
            log("Environmental compatability is invalid.", withError = True)
            return


        for app in self._must_creat_serializer:
            log("Creating a selia " + app + ".")
            self._create_app(app)
            self._create_url(app)
            self._install_app(app)
Example #8
0
    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))
Example #9
0
def get_django(item):

    data = load_miragefile()

    if item == MiragefileDataCategory.django_path:
        return data["project"]["django"]["path"]
    elif item == MiragefileDataCategory.django_module:
        return data["project"]["django"]["module"]
    elif item == MiragefileDataCategory.django_package_manager:
        return data["project"]["django"]["package"]
    elif item == MiragefileDataCategory.django_db_backend:
        return data["project"]["django"]["database"]
    else:
        log("The config information named " + item + " does not exist!", withError = True) 
        return load_failed()
Example #10
0
    def _check_all(self):

        reserved_names = [
            "test",
        ]

        for app in self._must_creat_serializer:
            for name in reserved_names:
                if app == name:
                    log("The app named " + app + " is reserved by Django!", withError = True)
                    raise ValueError

        for app in self._must_creat_serializer:
            if os.path.isdir(app):
                log("The app named " + app + " is already exists.", withError = True)
                raise FileExistsError
Example #11
0
    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

Currently, Django Console support SQLite database for debug.
            """)
Example #12
0
    def main(self):

        if self._project_name == None:
            log("Please type your new Django CMS application name.")
            self._project_name = log("Django CMS name", withInput=True)

        try:
            self._check(self._project_name)
        except:
            log("Project {0} is already exists.".format(self._project_name),
                withError=True)

        self._create_new_django_app(self._project_name)

        with proj.InDir("./" + self._project_name):
            self._create_template_git_project(self._project_name)
            self._create_docs(self._project_name)
Example #13
0
def get_project(item):
    
    data = load_miragefile()

    if item == MiragefileDataCategory.project_name:
        return data["project"]["name"]
    elif item == MiragefileDataCategory.project_version:
        return data["project"]["version"]
    elif item == MiragefileDataCategory.project_author:
        return data["project"]["author"]
    elif item == MiragefileDataCategory.project_git:
        return data["project"]["git"]
    elif item == MiragefileDataCategory.project_license:
        return data["project"]["license"]
    elif item == MiragefileDataCategory.project_description:
        return data["project"]["description"]
    else:
        log("The config information named " + item + " does not exist!", withError = True) 
        return load_failed()
Example #14
0
    def __insert_app_path(self, app_name):
        lines = []
        insert_line = 0

        try:
            with open("settings.py" , "r") as setting:
                try:
                    lines = setting.readlines()
                except:
                    log("Failed to load configuration file lines.", withError = True)
        except:
            pass

    
        for i in range(len(lines)):
            if "INSTALLED_APPS = [" in lines[i]:
                insert_line = i
    
        with open("settings.py", "w") as setting:
            app_config = app_name[0].upper() + app_name[1:] + "Config"
            lines.insert(insert_line + 1, "    \'" + app_name + ".apps." + app_config + "\',\n")
            setting.writelines(lines)
Example #15
0
    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
       
        return None
Example #16
0
    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)
Example #17
0
 def _create_new_django_app(self, name):
     log("Creating Django CMS application...")
     log("Please wait for a moment.")
     command("djangocms " + name)
Example #18
0
 def main(self):
     log("Not implemented!")
Example #19
0
def pip_install(package_name):
    log("Installing {0} ...".format(package_name))
    pip.main(['install', package_name])
Example #20
0
 def __init__(self, subcommand):
     log("Django Console Git is now unser development!", withError = True)
     self._subcommand = subcommand
Example #21
0
 def _remove_sqlite(self):
     log("Removing SQLite3 file...")
     if os.path.exists("db.sqlite3"):
         os.remove("db.sqlite3")
Example #22
0
 def main(self):
     log("Clearing all DB...")
     self._reset_db()
Example #23
0
 def __init__(self, subcommand):
     log("Django DataBase is now unser development!", withError=True)
     self._subcommand = subcommand
Example #24
0
    def _configure(self):

        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))
Example #25
0
 def setUp(self):
     log("Setup")
Example #26
0
 def test_first(self):
     log("test first")
Example #27
0
    def main(self):
        # Check

        try:
            self._check_before()
        except:
            return

        # Input information
        log("Please type your new Django application information.")

        # Check namespace
        try:
            self._project_name = log("Project name", withInput=True)
            self._check_namesapce(self._project_name)
        except:
            log("Project \"{0}\" is already exists.".format(
                self._project_name),
                withError=True,
                errorDetail=
                "Please remove duplication of Django project namespace.")
            return

        version = log("App version", withInput=True, default="0.0.1")
        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)

        self._create_new_django_app()

        with proj.InDir("./" + self._project_name):

            # Generate .gitignore
            log("Generating gitignore...")
            self._create_template_git_project()

            # Generate README.md
            log("Generating readme...")
            self._create_docs()

            # Generate Miragefile
            log("Generating Miragefile...")
            self._create_miragefile(version, author, email, git_url,
                                    license_name, description, copyrightor)

            # Add remote repo
            log("Adding remote repository...")
            command("git remote add origin " + git_url)

            # Make shell directory
            os.mkdir("shell")

        with proj.InDir("./shell"):

            # Generate package.json
            log("Generating package configuration...")
            self._create_package_json(version, description, git_url, author,
                                      email, license_name)

            # Install webpack
            log("Installing assets builder...")
            command("yarn add --dev webpack")

        # Completed
        log("Completed!")