fix: throw if directory exsists
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
William Luke 2022-04-26 15:01:52 +03:00
parent 067f354905
commit 5f22220825
2 changed files with 11 additions and 21 deletions

View File

@ -2,7 +2,7 @@ from __future__ import annotations
# standard import
import logging
import os
from chainlib.cli.config import Config
@ -66,13 +66,17 @@ def execute(
if wallet_keystore:
config.add(wallet_keystore, "WALLET_KEY_FILE", exists_ok=True)
if not skip_gen:
if skip_gen:
contract = load_contract(directory)
else:
if os.path.exists(directory):
raise Exception(f"Directory {directory} already exists")
if csv_file:
print(f"Generating from csv:{csv_file} to {directory}")
contract = load_contract_from_csv(config, directory, csv_file)
else:
print("Using Interactive Mode")
contract = generate_contract(directory, [target], config, interactive=True)
else:
contract = load_contract(directory)
print(contract)

View File

@ -4,13 +4,8 @@ import logging
import os
from typing import List
# external imports
from cic_types.ext.metadata import MetadataRequestsHandler
from cic_types.ext.metadata.signer import Signer as MetadataSigner
from chainlib.chain import ChainSpec
from chainlib.cli.config import Config
# Local Modules
from cic.contract.components.attachment import Attachment
from cic.contract.components.meta import Meta
@ -20,8 +15,9 @@ from cic.contract.helpers import init_writers_from_config
from cic.contract.network import Network
from cic.contract.processor import ContractProcessor
from cic.writers import HTTPWriter, KeyedWriterFactory, MetadataWriter
# external imports
from cic_types.ext.metadata import MetadataRequestsHandler
from cic_types.ext.metadata.signer import Signer as MetadataSigner
log = logging.getLogger(__name__)
@ -74,16 +70,6 @@ def load_contract(directory) -> Contract:
def generate_contract(
directory: str, targets: List[str], config, interactive=True
) -> Contract:
if os.path.exists(directory):
contine = input(
f"Directory {directory} already exists, Would you like to delete it? (y/n): "
)
if contine.lower() != "y":
log.debug("Trying to load existing contract")
return load_contract(directory)
else:
print(f"Deleted {directory}")
os.system(f"rm -rf {directory}")
os.makedirs(directory)
log.info("Generating token")
token = Token(directory, interactive=interactive)