Skip to content

Commit

Permalink
Moved single use functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvanstraten committed Sep 14, 2023
1 parent f7aa8b5 commit a60bb80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
21 changes: 14 additions & 7 deletions Sources/CodeGen/generate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import click
import os
import glob

from os.path import abspath
from datetime import date
from typing import List

from parse import process_json_files
from parsing_types.command import Command
from utils import (
make_sure_remote_repo_is_downloaded,
clean_out_directory,
get_todays_date,
THIS_DIR,
)
from swift_format import format_files
from templates import render

SRC_DIR = abspath(THIS_DIR + "/redis/src")
OUT_DIR = abspath(THIS_DIR + "/../SwiftyRedis/CodeGen/Commands")
SRC_DIR = os.path.abspath(THIS_DIR + "/redis/src")
OUT_DIR = os.path.abspath(THIS_DIR + "/../SwiftyRedis/CodeGen/Commands")


def clean_out_directory():
click.echo("Cleaning out directory...")
os.makedirs(OUT_DIR, exist_ok=True)
for file_path in glob.glob(os.path.join(OUT_DIR, "*")):
os.remove(file_path)


def write_extensions_file(commands: List[Command], file_name: str):
Expand All @@ -24,7 +31,7 @@ def write_extensions_file(commands: List[Command], file_name: str):
render(
"extension.swift",
filename=file_name,
creation_date=get_todays_date(),
creation_date=date.today().strftime("%d.%m.%y"),
commands=commands,
)
)
Expand All @@ -44,7 +51,7 @@ def commands():
commands, subcommands = process_json_files(SRC_DIR)
commands.sort(key=lambda command: command.fullname())

clean_out_directory(OUT_DIR)
clean_out_directory()

to_format_files = []

Expand Down
14 changes: 0 additions & 14 deletions Sources/CodeGen/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import os
import glob
import re
from datetime import date
import click
from git.repo import Repo
from git import RemoteProgress
from tqdm import tqdm
Expand Down Expand Up @@ -66,14 +63,3 @@ def kebab_case(s):

def sanitize(s):
return s.replace("-", "_").replace(":", "")


def clean_out_directory(out_dir):
click.echo("Cleaning out directory...")
os.makedirs(out_dir, exist_ok=True)
for file_path in glob.glob(os.path.join(out_dir, "*")):
os.remove(file_path)


def get_todays_date():
return date.today().strftime("%d.%m.%y")

0 comments on commit a60bb80

Please sign in to comment.