-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (54 loc) · 1.91 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import subprocess
import tkinter as tk
from tkinter import filedialog
from tkinter import simpledialog
import os
from tkinter import messagebox
# Create a Tkinter window
window = tk.Tk()
# Hide the main window
window.withdraw()
# Open a file dialog to select the directory
directory = filedialog.askdirectory(title="Select Directory")
# Create a new directory
res = simpledialog.askstring("Project Directory", "Enter: ")
if res == None or res == "":
exit()
new_directory = os.path.join(directory, res)
os.mkdir(new_directory)
print("Created Project Directory:", new_directory)
# Create a file inside the new directory
file_path = os.path.join(new_directory, "main.py")
with open(file_path, "w") as f:
f.write('print("Hello, world!")')
print("Created main.py:", file_path)
# Create Pipenv virtual environment in the project folder
try:
# Change to the new directory
os.chdir(new_directory)
# create .venv directory
os.mkdir(".venv")
# Initialize Pipenv environment
subprocess.run(["pipenv", "install"], check=True)
print("Created Pipenv Virtual Environment")
except subprocess.CalledProcessError:
print("Error: Ensure pipenv is installed (pip install pipenv)")
messagebox.showerror("Error", "Pipenv installation failed. Is pipenv installed?")
exit()
# Initialize Git repository
subprocess.run(["git", "init", new_directory])
print("Initialized git")
# Create a .gitignore file
gitignore_path = os.path.join(new_directory, ".gitignore")
with open(gitignore_path, "w") as f:
f.write(".venv\n.env\n__pycache__/\n*.pyc\n")
print("Created .gitignore and added .venv/ to it:", gitignore_path)
# Open in vs code
response = messagebox.askyesno("Confirmation", "Open in vs code?")
if response:
# st = 'code '+ new_directory + '\main.py'
# print(st)
os.system(rf'code "{new_directory}"')
os.system(rf'code "{file_path}"')
# Close the window"D:\python programs\aaaaa\main.py"
window.destroy()