Skip to content

Commit

Permalink
[fet] Added new options Fixes #1
Browse files Browse the repository at this point in the history
- "-v" for create virtualenv by defult name "env"
if you need set custom name you can use "-n env_name"
- added help options
- fixes bugs
- refactor code
- remove version check function
- required add path to project
django-start <project_name> <app_name> <path>
now for install django-start just type "pip install django-start-automate"
  • Loading branch information
islam kamel committed Jul 16, 2022
1 parent 47fbfc0 commit 9a595b8
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 155 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
__pycache__/
*.py[cod]
*$py.class
test
test_*

# C extensions
*.so

Expand Down
103 changes: 57 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
<head>
<style>
.title {
text-align: center;
font-family: Serif;
font-size: 6vh;
}
.title .first {
color: darkgoldenrod;
letter-spacing: -6px;
margin-right: -2.2%;
}
.title .second {
color: darkgoldenrod;
z-index: 0;
letter-spacing: -3px;
}
.description {
text-align: center;
background: rgba(131,131,131,0.17);
padding: 10px;
border-radius: 5px;
width: 650px;
margin: 0 auto
}
</style>
</head>

<h1 class="title">
<span class="first">Django</span>
<span class="second">Start</span>
<h1 style="
text-align: center;
font-family: Serif;
font-size: 6vh;
">
<span style="
color: darkgoldenrod;
letter-spacing: -6px;
margin-right: -2.2%;"
>Django</span>
<span style="
color: darkgoldenrod;
letter-spacing: -3px;"
>Start</span>
Automate Script ✨
</h1>

<div class="description">
<div style="
text-align: center;
background: rgba(131,131,131,0.17);
padding: 10px;
border-radius: 5px;
width: 650px;
margin: 0 auto
">
Django automate start project and create app
This script saves time for you to start a new Django project.
It creates the project and creates the first app
Expand All @@ -50,23 +40,44 @@ Automate Script ✨
</div>

---
### open start manu and type Edit the system environment variables
![img.png](assest/img_1.png)
- #### click Environment Variables

### click Path variables
![img.png](assest/img_2.png)
### Installation

### insert script install path
![img.png](assest/img_3.png)
- #### click ok
---
## Success Install 🎊
![img.png](assest/img_4.png)
![img.png](assest/img_5.png)
````shell
pip install django-start-automate
````

## Welcome to contribute ❤
````shell
django-start --help

usage: django-start [-h] [-v] [-n ] project_name app_name path

django-start 1.0.4 (Beta) automate start project and create app

positional arguments:
project_name Write a project name
app_name Write an app name
path select path

options:
-h, --help show this help message and exit
-v, --virtualenv Create virtualenv
-n [], --name [] Set virtualenv name

````
**Success Install 🎊**

### Start First Project with virtualenv
```shell
django-start frist_project first_app -v -n my_virtualenv .
```
---
> You can run command without create virrualenv
```shell
pip install pyinstaller | pyinstaller --noconfirm --onefile --console --add-data <requests_package_path> --add-data <djstartlib> "django-start.py"
django-start frist_project first_app .
```

![img.png](assest/img.png)

## Welcome to contribute ❤
### [django-start](!https://github.com/islam-kamel/django-start) 🧑‍💻
Binary file modified assest/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 0 additions & 53 deletions django-start.py

This file was deleted.

2 changes: 1 addition & 1 deletion djstartlib/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def line_list(self):
@line_list.setter
def line_list(self, value):
self.__line_list = value
return self.__line_list
return self.line_list

def index(self, value):
return self.line_list.index(value)
Expand Down
6 changes: 3 additions & 3 deletions djstartlib/djstart_interface.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
import subprocess

from project_manager import ProjectManager


class DjangoStart(ProjectManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def upgrade_pip(self):
@staticmethod
def upgrade_pip():
print("📦 Upgrade Pip")
subprocess.call(
f"{sys.executable} -m pip install --upgrade pip",
Expand All @@ -21,7 +21,7 @@ def setup_project(self):
self.upgrade_pip()
self.install_dep()
self.create_project()
self.requirements()
self.requirements_extract()

def setup_app(self):
self.app_manager.create_app()
Expand Down
52 changes: 52 additions & 0 deletions djstartlib/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /usr/bin/python3
import sys
import argparse
import pathlib
import re
from djstart_interface import DjangoStart as djstart

version = """
django-start 1.0.4 (Beta) automate start project and create app
"""


def check_regx(arg_value, pat=re.compile(r"^[a-zA-Z]")):
if not pat.match(arg_value):
return argparse.ArgumentParser.exit(1, "Enter valid name")
else:
return arg_value


def main():
parser = argparse.ArgumentParser("django-start", description=version)
parser.add_argument(
"project_name", help="Write a project name", type=check_regx
)
parser.add_argument("app_name", help="Write an app name", type=check_regx)
parser.add_argument(
"-v", "--virtualenv", help="Create virtualenv", action="store_true"
)
parser.add_argument(
"-n",
"--name",
default="env",
const="env",
type=lambda p: pathlib.Path(p).absolute(),
nargs="?",
metavar="",
help="Set virtualenv name",
)
parser.add_argument(
"path", type=lambda p: pathlib.Path(p).absolute(), help="select path"
)
args = parser.parse_args()
if args.virtualenv:
djstart.create_env(djstart, args.name)
app = djstart(core_name=args.project_name, app_name=args.app_name)
app.setup_project()
app.setup_app()


if __name__ == "__main__":
sys.executable = "python"
main()
46 changes: 32 additions & 14 deletions djstartlib/project_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import platform
from app_manager import AppManager
from hellper import warn_stdout

Expand Down Expand Up @@ -51,50 +52,51 @@ def line_list(self):
@line_list.setter
def line_list(self, value):
self.__line_list = value
return self.__line_list
return self.line_list

def index(self, value):
return self.line_list.index(value)
return self.__line_list.index(value)

def read_file(self, file):
with open(file) as f:
self.line_list = f.readlines()
self.__line_list = f.readlines()
f.close()
return self.line_list
return self.__line_list

def update_lines_list(self, flag, value):
self.line_list.insert(self.index(flag), value)
self.__line_list.insert(self.index(flag), value)

def replace_line(self, index, value):
self.line_list[index] = value
self.__line_list[index] = value

def update_settings(self):
self.read_file(self.settings_path)
if f"\t'{self.app_name}',\n" not in self.line_list:
if f"\t'{self.app_name}',\n" not in self.__line_list:
print("⚙️ Update Settings")
self.update_lines_list("]\n", f"\t'{self.app_name}',\n")
with open(self.settings_path, "w") as f:
f.write("".join(self.line_list))
f.write("".join(self.__line_list))
f.close()
else:
warn_stdout(f'"{self.app_name}" is installed!')

def update_urls(self):
self.read_file(self.urls_path)
view_path = f"\tpath('', include('{self.app_name}.urls')),\n"
if view_path not in self.line_list:
if view_path not in self.__line_list:
self.replace_line(
self.index("from django.urls import path\n"),
"from django.urls import path, include\n",
)
self.update_lines_list("]\n", view_path)
with open(self.urls_path, "w") as f:
f.write("".join(self.line_list))
f.write("".join(self.__line_list))
f.close()
else:
warn_stdout("Urls Already Updated")

def install_dep(self):
@staticmethod
def install_dep():
print("⏳ Install Dependencies")
subprocess.call(
f"{sys.executable} -m pip install django",
Expand All @@ -103,6 +105,16 @@ def install_dep(self):
shell=True,
)

@staticmethod
def requirements_extract():
print("🧾 Create Requirements.txt")
subprocess.call(
f"{sys.executable} -m pip freeze > requirements.txt",
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
shell=True,
)

def create_project(self):
if self.core_name not in os.listdir(self.workdir):
print(f'✨ Create Project "{self.core_name}"')
Expand All @@ -112,11 +124,17 @@ def create_project(self):
else:
warn_stdout(f'"{self.core_name}" already exist!')

def requirements(self):
print("🧾 Create Requirements.txt")
def create_env(self, env_name_path):
print("⚗️ Create Virtualen")
subprocess.call(
"pip freeze > requirements.txt",
f"{sys.executable} -m venv {env_name_path}",
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
shell=True,
)
if platform.system() == "Windows":
sys.executable = (
f"{env_name_path}{os.sep}Scripts{os.sep}python.exe"
)
else:
sys.executable = f"{env_name_path}{os.sep}bin{os.sep}python3"
Loading

0 comments on commit 9a595b8

Please sign in to comment.