Skip to content

Commit

Permalink
change license and readme building
Browse files Browse the repository at this point in the history
  • Loading branch information
grokhi committed Nov 18, 2023
1 parent 3d231f5 commit c642f99
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import os, json
import tarfile
import tqdm
import supervisely as sly
Expand All @@ -14,6 +15,7 @@

from dataset_tools import ProjectRepo

from typing import Optional
if sly.is_development():
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/ninja.env"))
Expand Down Expand Up @@ -172,6 +174,15 @@ def download_json_plus_images(api, project, dataset_ids):
download_dir = os.path.join(my_app.data_dir, f"{project.id}_{project.name}")
if os.path.exists(download_dir):
sly.fs.clean_dir(download_dir)

tf_urls_path = "/cache/released_datasets.json"
local_save_path = sly.app.get_data_dir() + '/tmp/'
if api.file.exists(TEAM_ID, tf_urls_path):
api.file.download(TEAM_ID, tf_urls_path, local_save_path)
with open(local_save_path, "r") as f:
urls = json.load(f)
else:
raise FileNotFoundError(f"File not found: '{tf_urls_path}'")
sly.download_project(
api,
project.id,
Expand All @@ -185,14 +196,12 @@ def download_json_plus_images(api, project, dataset_ids):
)

sly.logger.info("Start building files...")
sly.logger.info(
f"LICENSE: {project.custom_data.get('LICENSE', 'Please add license')}"
)
sly.logger.info(f"README: {project.custom_data.get('README', 'Please add readme')}")
build_license(
project.custom_data.get("LICENSE", "Please add license"), download_dir
)
build_readme(project.custom_data.get("README", "Please add readme"), download_dir)
# sly.logger.info(
# f"LICENSE: {urls[project.name].get('LICENSE', 'Please add license')}"
# )
# sly.logger.info(f"README: {urls[project.name].get('README', 'Please add readme')}")
build_license(urls[project.name]['LICENSE'], download_dir)
build_readme(urls[project.name]['README'], download_dir)
sly.logger.info("'LICENSE.md' and 'README.md' were successfully built.")


Expand Down Expand Up @@ -246,8 +255,8 @@ def build_license(license_content: str, download_dir: str):
license_file.write(license_content)


def build_readme(readme_content, download_dir):
readme_path = os.path.join(download_dir, "README.md")
def build_readme(readme_content:str, download_dir:str):
readme_path = os.path.join(download_dir, "README.md")
with open(readme_path, "w") as license_file:
license_file.write(readme_content)

Expand Down

0 comments on commit c642f99

Please sign in to comment.