|
import streamlit as st |
|
import os |
|
import shutil |
|
from git import Repo |
|
|
|
|
|
SAVE_DIR = "saved_projects" |
|
|
|
if not os.path.exists(SAVE_DIR): |
|
os.makedirs(SAVE_DIR) |
|
|
|
def save_uploaded_files(uploaded_files): |
|
"""Save uploaded files to the SAVE_DIR.""" |
|
project_dir = os.path.join(SAVE_DIR, "uploaded_project") |
|
if os.path.exists(project_dir): |
|
shutil.rmtree(project_dir) |
|
os.makedirs(project_dir) |
|
|
|
for uploaded_file in uploaded_files: |
|
with open(os.path.join(project_dir, uploaded_file.name), "wb") as f: |
|
f.write(uploaded_file.getbuffer()) |
|
return project_dir |
|
|
|
def clone_repository(repo_url): |
|
"""Clone a GitHub repository into SAVE_DIR.""" |
|
repo_name = repo_url.split("/")[-1].replace(".git", "") |
|
repo_dir = os.path.join(SAVE_DIR, repo_name) |
|
if os.path.exists(repo_dir): |
|
shutil.rmtree(repo_dir) |
|
Repo.clone_from(repo_url, repo_dir) |
|
return repo_dir |
|
|
|
def main(): |
|
st.title("Project Manager App") |
|
st.write("Upload your project files or clone a GitHub repository.") |
|
|
|
|
|
option = st.sidebar.selectbox( |
|
"Choose an option:", |
|
("Upload Files", "Clone GitHub Repository") |
|
) |
|
|
|
if option == "Upload Files": |
|
st.header("Upload Files") |
|
uploaded_files = st.file_uploader( |
|
"Upload your coding project files (multiple files allowed):", |
|
accept_multiple_files=True |
|
) |
|
if uploaded_files: |
|
saved_path = save_uploaded_files(uploaded_files) |
|
st.success(f"Files saved to {saved_path}") |
|
|
|
elif option == "Clone GitHub Repository": |
|
st.header("Clone GitHub Repository") |
|
repo_url = st.text_input("Enter the GitHub repository URL:") |
|
if repo_url: |
|
if st.button("Clone Repository"): |
|
try: |
|
repo_path = clone_repository(repo_url) |
|
st.success(f"Repository cloned to {repo_path}") |
|
except Exception as e: |
|
st.error(f"Error cloning repository: {e}") |
|
|
|
|
|
st.header("Saved Projects") |
|
if os.listdir(SAVE_DIR): |
|
for project in os.listdir(SAVE_DIR): |
|
st.write(f"- {project}") |
|
else: |
|
st.write("No projects saved yet.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|