Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pokeapi_ditto/commands/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pokeapi_ditto.common import from_dir


def do_analyze(api_dir: str, schema_dir: str):
def do_analyze(api_dir: str, schema_dir: str, log: bool):
if not Path(schema_dir).exists():
Path(schema_dir).mkdir(parents=True)

Expand Down Expand Up @@ -38,7 +38,8 @@ def gen_single_schema(path: Path) -> SchemaBuilder:
@from_dir(schema_dir)
def gen_schemas(paths: List[Path]):
for path in paths:
print(Path(schema_dir).joinpath(path))
if log:
print(Path(schema_dir).joinpath(path))
if not path.parent.exists():
os.makedirs(path.parent)
schema = gen_single_schema(path)
Expand Down
8 changes: 5 additions & 3 deletions pokeapi_ditto/commands/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pokeapi_ditto.common import BASE_URL_PLACEHOLDER


def do_clone(src_url, dest_dir):
def do_clone(src_url: str, dest_dir: str, log: bool):
if not src_url.endswith("/"):
src_url += "/"

Expand All @@ -29,7 +29,8 @@ def print_json(data, file_name):
endpoints = requests.get(url)

path = dest_dir + url.replace(src_url, "") + "index.json"
print(path)
if log:
print(path)
print_json(endpoints.json(), path)

# Endpoints
Expand All @@ -44,7 +45,8 @@ def print_json(data, file_name):
url = endpoint + "?limit=" + count
resource_list = requests.get(url)
path = dest_dir + endpoint.replace(src_url, "") + "index.json"
print(path)
if log:
print(path)
print_json(resource_list.json(), path)

# All resources
Expand Down
5 changes: 3 additions & 2 deletions pokeapi_ditto/commands/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pokeapi_ditto.common import apply_base_url


def do_transform(src_dir: str, dest_dir: str, base_url: str):
def do_transform(src_dir: str, dest_dir: str, base_url: str, log: bool):
src_dir: Path = Path(src_dir)
dest_dir: Path = Path(dest_dir)

Expand All @@ -18,7 +18,8 @@ def do_transform(src_dir: str, dest_dir: str, base_url: str):

for orig in orig_paths:
new = dest_dir.joinpath(orig.relative_to(src_dir))
print(new)
if log:
print(new)

if not new.parent.exists():
new.parent.mkdir(parents=True)
Expand Down
9 changes: 9 additions & 0 deletions pokeapi_ditto/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@

from gevent.pywsgi import WSGIServer

from pokeapi_ditto import __version__
from pokeapi_ditto.commands import analyze, clone, serve, transform


class Ditto(object):
def __init__(self):
parser = argparse.ArgumentParser()
parser.add_argument("--version", action="version", version=__version__)
parser.add_argument(
"--log",
action="store_const",
const=True,
default=False,
help="turn on logging of files saved",
)
subparsers = parser.add_subparsers(dest="command")

clone_args = subparsers.add_parser("clone")
Expand Down