Update app.py
Browse files
app.py
CHANGED
@@ -640,20 +640,21 @@ def saved_documentation_page():
|
|
640 |
|
641 |
|
642 |
|
643 |
-
|
644 |
-
|
|
|
645 |
try:
|
646 |
items = sorted(os.listdir(folder_path)) # Sort items for consistent display
|
647 |
-
|
648 |
-
|
649 |
-
for item in items:
|
650 |
item_path = os.path.join(folder_path, item)
|
|
|
|
|
|
|
|
|
651 |
if os.path.isdir(item_path):
|
652 |
-
# Recursively display sub-folders
|
653 |
-
|
654 |
-
|
655 |
-
# Display files with an indented structure
|
656 |
-
st.write(f"{prefix} {item}")
|
657 |
except Exception as e:
|
658 |
st.error(f"Error displaying folder contents: {e}")
|
659 |
|
@@ -679,16 +680,26 @@ def project_view_page():
|
|
679 |
user_folder = os.path.join("user_projects", st.session_state.username)
|
680 |
project_folder = os.path.join(user_folder, st.session_state.current_project)
|
681 |
|
682 |
-
#
|
683 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
684 |
|
685 |
-
# Count total lines of code in all text files
|
686 |
num_lines = 0
|
687 |
-
for root, _, files in os.walk(
|
688 |
for file in files:
|
689 |
file_path = os.path.join(root, file)
|
690 |
try:
|
691 |
-
with open(file_path,
|
692 |
num_lines += sum(1 for _ in f)
|
693 |
except (UnicodeDecodeError, IsADirectoryError):
|
694 |
continue
|
@@ -714,13 +725,14 @@ def project_view_page():
|
|
714 |
if st.button("Show File Structure"):
|
715 |
st.session_state.show_file_structure = not st.session_state.show_file_structure
|
716 |
|
717 |
-
# Display
|
718 |
if "show_file_structure" not in st.session_state:
|
719 |
st.session_state.show_file_structure = False
|
720 |
|
721 |
if st.session_state.show_file_structure:
|
722 |
st.write("File structure:")
|
723 |
-
|
|
|
724 |
|
725 |
|
726 |
|
|
|
640 |
|
641 |
|
642 |
|
643 |
+
|
644 |
+
def display_tree_structure(folder_path, prefix=""):
|
645 |
+
"""Recursively display the folder structure in a tree-like format."""
|
646 |
try:
|
647 |
items = sorted(os.listdir(folder_path)) # Sort items for consistent display
|
648 |
+
for i, item in enumerate(items):
|
|
|
|
|
649 |
item_path = os.path.join(folder_path, item)
|
650 |
+
is_last_item = i == len(items) - 1
|
651 |
+
connector = "βββ " if is_last_item else "βββ "
|
652 |
+
st.write(f"{prefix}{connector}{item}")
|
653 |
+
|
654 |
if os.path.isdir(item_path):
|
655 |
+
# Recursively display sub-folders with additional indentation
|
656 |
+
new_prefix = prefix + (" " if is_last_item else "β ")
|
657 |
+
display_tree_structure(item_path, new_prefix)
|
|
|
|
|
658 |
except Exception as e:
|
659 |
st.error(f"Error displaying folder contents: {e}")
|
660 |
|
|
|
680 |
user_folder = os.path.join("user_projects", st.session_state.username)
|
681 |
project_folder = os.path.join(user_folder, st.session_state.current_project)
|
682 |
|
683 |
+
# Check for `.git` directory and focus on `origin` folder
|
684 |
+
git_dir = os.path.join(project_folder, ".git")
|
685 |
+
origin_dir = os.path.join(git_dir, "refs", "remotes", "origin")
|
686 |
+
|
687 |
+
if not os.path.exists(origin_dir):
|
688 |
+
st.error("The 'origin' folder does not exist in this project.")
|
689 |
+
return
|
690 |
+
|
691 |
+
# Count number of files in `origin`
|
692 |
+
num_files = sum(
|
693 |
+
[len(files) for _, _, files in os.walk(origin_dir)]
|
694 |
+
)
|
695 |
|
696 |
+
# Count total lines of code in all text files in `origin`
|
697 |
num_lines = 0
|
698 |
+
for root, _, files in os.walk(origin_dir):
|
699 |
for file in files:
|
700 |
file_path = os.path.join(root, file)
|
701 |
try:
|
702 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
703 |
num_lines += sum(1 for _ in f)
|
704 |
except (UnicodeDecodeError, IsADirectoryError):
|
705 |
continue
|
|
|
725 |
if st.button("Show File Structure"):
|
726 |
st.session_state.show_file_structure = not st.session_state.show_file_structure
|
727 |
|
728 |
+
# Display tree structure for `origin`
|
729 |
if "show_file_structure" not in st.session_state:
|
730 |
st.session_state.show_file_structure = False
|
731 |
|
732 |
if st.session_state.show_file_structure:
|
733 |
st.write("File structure:")
|
734 |
+
st.write(".") # Root representation
|
735 |
+
display_tree_structure(origin_dir)
|
736 |
|
737 |
|
738 |
|