Simon Strandgaard commited on
Commit
0f07150
·
1 Parent(s): ec06ad9

create_zip_archive() extracted

Browse files
src/plan/app_text2plan.py CHANGED
@@ -8,12 +8,9 @@ import time
8
  import sys
9
  import threading
10
  from math import ceil
11
- import shutil
12
- import zipfile
13
- import copy
14
-
15
  from src.llm_factory import get_available_llms
16
  from src.plan.generate_run_id import generate_run_id
 
17
  from src.plan.filenames import FilenameEnum
18
  from src.plan.plan_file import PlanFile
19
  from src.plan.speedvsdetail import SpeedVsDetailEnum
@@ -111,26 +108,6 @@ class SessionState:
111
  """
112
  return self
113
 
114
- def create_zip_archive(directory_to_zip: str) -> str:
115
- """
116
- Creates a zip archive of the given directory, excluding 'log.txt'.
117
- Returns the path to the zip file, or None if an error occurred.
118
- """
119
- zip_file_path = os.path.join(os.path.dirname(directory_to_zip), os.path.basename(directory_to_zip) + ".zip")
120
- try:
121
- with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
122
- for root, _, files in os.walk(directory_to_zip):
123
- for file in files:
124
- if file == "log.txt":
125
- continue # Skip the log file
126
-
127
- file_path = os.path.join(root, file)
128
- zipf.write(file_path, os.path.relpath(file_path, directory_to_zip))
129
- return zip_file_path
130
- except Exception as e:
131
- print(f"Error creating zip archive: {e}")
132
- return None
133
-
134
  def run_planner(submit_or_retry_button, plan_prompt, llm_model, speedvsdetail, session_state: SessionState):
135
  """
136
  Generator function for launching the pipeline process and streaming updates.
 
8
  import sys
9
  import threading
10
  from math import ceil
 
 
 
 
11
  from src.llm_factory import get_available_llms
12
  from src.plan.generate_run_id import generate_run_id
13
+ from src.plan.create_zip_archive import create_zip_archive
14
  from src.plan.filenames import FilenameEnum
15
  from src.plan.plan_file import PlanFile
16
  from src.plan.speedvsdetail import SpeedVsDetailEnum
 
108
  """
109
  return self
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  def run_planner(submit_or_retry_button, plan_prompt, llm_model, speedvsdetail, session_state: SessionState):
112
  """
113
  Generator function for launching the pipeline process and streaming updates.
src/plan/create_zip_archive.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import zipfile
2
+ import os
3
+
4
+ def create_zip_archive(directory_to_zip: str) -> str:
5
+ """
6
+ Creates a zip archive of the given directory, excluding 'log.txt'.
7
+ Returns the path to the zip file, or None if an error occurred.
8
+ """
9
+ zip_file_path = os.path.join(os.path.dirname(directory_to_zip), os.path.basename(directory_to_zip) + ".zip")
10
+ try:
11
+ with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
12
+ for root, _, files in os.walk(directory_to_zip):
13
+ for file in files:
14
+ if file == "log.txt":
15
+ continue # Skip the log file
16
+
17
+ file_path = os.path.join(root, file)
18
+ zipf.write(file_path, os.path.relpath(file_path, directory_to_zip))
19
+ return zip_file_path
20
+ except Exception as e:
21
+ print(f"Error creating zip archive: {e}")
22
+ return None
23
+
24
+ if __name__ == "__main__":
25
+ dir_path = os.path.join(os.path.dirname(__file__), '..', 'expert', 'test_data')
26
+ zip_path = create_zip_archive(dir_path)
27
+ print(f"Zip archive created at: {zip_path}")