Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinkova committed Nov 8, 2024
1 parent f4d430a commit a04a8cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dsw_seed_maker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def list_resources(output, resource_type):
resources = list_logic(resource_type)
json_output = json.dumps(resources, indent=4)
output.write(json_output)


# just for testing the download
# @cli.command(help='List all available seed resources', name='download')
Expand Down
19 changes: 18 additions & 1 deletion src/dsw_seed_maker/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

load_dotenv()


def connect_to_db_logic() -> Database:
return Database(name=os.getenv("DSW_DB_CONN_NAME"), dsn=os.getenv("DSW_DB_CONN_STR"))


processed_resources = set()
db = connect_to_db_logic()
output_dir = "-"


def example_logic(req_dto: ExampleRequestDTO) -> ExampleResponseDTO:
return ExampleResponseDTO(
message=req_dto.message.replace('server', 'client'),
Expand All @@ -36,6 +39,7 @@ def connect_to_s3_logic() -> S3Storage:
multi_tenant=True
)


def generate_insert_query(data, table):
columns = ', '.join(data.keys())
values = ", ".join(format_for_sql(data))
Expand All @@ -51,7 +55,7 @@ def generate_select_all_query(resource_type):


def list_logic(resource_type: str) -> dict[str, list[dict[str, Any]]] | list[dict[str, Any]]:
if resource_type== "all":
if resource_type == "all":
resource = {}
for each in resource_attributes.keys():
resource[each] = list_resource(each, resource_attributes[each])
Expand Down Expand Up @@ -95,6 +99,7 @@ def create_recipe_file():
with open(os.path.join(output_dir, 'recipe.json'), 'w') as recipe:
recipe.write(data)


# Add a seed file (its name) to the recipe (the structure)
def add_seed_file_to_recipe(recipe_path, db_file_name):
with open(recipe_path, 'r') as recipe_file:
Expand All @@ -116,6 +121,7 @@ def create_seed_files_db(resource_type, output_dir):
file = open(file_path, 'w', encoding='utf-8')
return file


def process_input(data, output):
global output_dir
output_dir = output
Expand All @@ -125,12 +131,14 @@ def process_input(data, output):
for item in items:
handle_resource(resource_type, item[resource_identification[resource_type]])


def write_seed_files_db(output_dir, resource_type, query):
with open(os.path.join(output_dir, f"add_{resource_type}.sql"), 'a', encoding='utf-8') as file:
if file is None:
print("File not found")
file.write(query + "\n")


def has_placeholder_in_s3_objects(resource_s3_objects):
# Regular expression to match placeholders, e.g., "{some_placeholder}"
placeholder_pattern = re.compile(r"{placeholder}")
Expand Down Expand Up @@ -178,6 +186,7 @@ def return_fkey_dependency(resource_type, dependent_resource_type):
return str(dependency[dependent_resource_type])
return None


def handle_resource(resource_type, resource_id):
if resource_id in processed_resources:
return
Expand Down Expand Up @@ -221,6 +230,7 @@ def handle_resource(resource_type, resource_id):
handle_resource(dependent_resource_type, dependent_resource[resource_identification[dependent_resource_type]])
return


# Map resources to their dependencies
resources_part_of = {
"users": [],
Expand All @@ -234,6 +244,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": []
}


# Map resources to their dependencies
resource_dependencies = {
"users": [],
Expand All @@ -247,6 +258,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": ["document_templates"]
}


# Map resources to their dependencies
resource_dependencies_keys = {
"users": [],
Expand All @@ -272,6 +284,7 @@ def handle_resource(resource_type, resource_id):
]
}


# Map resources to their s3 objects
resource_s3_objects = {
"users": "",
Expand All @@ -285,6 +298,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": ""
}


# Map resources to their s3 objects' file names
resource_s3_objects_fileNames = {
"locales": "name",
Expand All @@ -293,6 +307,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": ["templates/"]
}


# Map resources to their identification attribute
resource_identification= {
"users": "uuid",
Expand All @@ -306,6 +321,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": "uuid"
}


# Map resources to their table names
resource_tables = {
"users": "user_entity",
Expand All @@ -319,6 +335,7 @@ def handle_resource(resource_type, resource_id):
"document_template_file": "document_template_file"
}


# Map resources to attributes visible to users
resource_attributes = {
"users": ['uuid', 'first_name', 'last_name', 'role', 'email'],
Expand Down

0 comments on commit a04a8cb

Please sign in to comment.