Update deployer/revenue_tracker.py
Browse files- deployer/revenue_tracker.py +14 -13
deployer/revenue_tracker.py
CHANGED
|
@@ -24,35 +24,36 @@ def get_revenue_stats():
|
|
| 24 |
|
| 25 |
def package_artifacts(assets):
|
| 26 |
"""
|
| 27 |
-
Packages generated app assets (blueprint and code files) into a zip archive
|
|
|
|
| 28 |
Returns the path to the zip file.
|
| 29 |
"""
|
| 30 |
-
#
|
| 31 |
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
| 32 |
-
|
| 33 |
-
os.makedirs(
|
| 34 |
|
| 35 |
# Save blueprint as JSON
|
| 36 |
blueprint = assets.get("blueprint", {})
|
| 37 |
-
bp_path = os.path.join(
|
| 38 |
with open(bp_path, "w") as f:
|
| 39 |
json.dump(blueprint, f, indent=2)
|
| 40 |
|
| 41 |
-
# Save each code file
|
| 42 |
code_files = assets.get("code", {})
|
| 43 |
for fname, content in code_files.items():
|
| 44 |
-
file_path = os.path.join(
|
| 45 |
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 46 |
with open(file_path, "w") as f:
|
| 47 |
f.write(content)
|
| 48 |
|
| 49 |
-
# Create zip archive
|
| 50 |
-
zip_path = f"{
|
| 51 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 52 |
-
for root, _, files in os.walk(
|
| 53 |
for file in files:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
zipf.write(
|
| 57 |
|
| 58 |
return zip_path
|
|
|
|
| 24 |
|
| 25 |
def package_artifacts(assets):
|
| 26 |
"""
|
| 27 |
+
Packages generated app assets (blueprint and code files) into a zip archive
|
| 28 |
+
stored under the persistent /data directory so artifacts appear in the Space UI.
|
| 29 |
Returns the path to the zip file.
|
| 30 |
"""
|
| 31 |
+
# Timestamped directory under persistent storage (/data)
|
| 32 |
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
| 33 |
+
base_dir = f"/data/artifacts_{timestamp}"
|
| 34 |
+
os.makedirs(base_dir, exist_ok=True)
|
| 35 |
|
| 36 |
# Save blueprint as JSON
|
| 37 |
blueprint = assets.get("blueprint", {})
|
| 38 |
+
bp_path = os.path.join(base_dir, "blueprint.json")
|
| 39 |
with open(bp_path, "w") as f:
|
| 40 |
json.dump(blueprint, f, indent=2)
|
| 41 |
|
| 42 |
+
# Save each generated code file
|
| 43 |
code_files = assets.get("code", {})
|
| 44 |
for fname, content in code_files.items():
|
| 45 |
+
file_path = os.path.join(base_dir, fname)
|
| 46 |
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 47 |
with open(file_path, "w") as f:
|
| 48 |
f.write(content)
|
| 49 |
|
| 50 |
+
# Create zip archive alongside the directory
|
| 51 |
+
zip_path = f"{base_dir}.zip"
|
| 52 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 53 |
+
for root, _, files in os.walk(base_dir):
|
| 54 |
for file in files:
|
| 55 |
+
full_path = os.path.join(root, file)
|
| 56 |
+
rel_path = os.path.relpath(full_path, base_dir)
|
| 57 |
+
zipf.write(full_path, arcname=rel_path)
|
| 58 |
|
| 59 |
return zip_path
|