Skip to content

Commit

Permalink
Merge pull request #117 from ctripcorp/116-cli-create-support-mini-pr…
Browse files Browse the repository at this point in the history
…oject

116 cli create support mini project
  • Loading branch information
clgwlg authored Oct 23, 2022
2 parents b0ffc35 + 4670e31 commit 9a6ecde
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.5
current_version = 0.4.6
commit = True
tag = True

Expand Down
17 changes: 14 additions & 3 deletions flybirds/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typer

import flybirds.utils.flybirds_log as log
from flybirds.cli.create_project import create_demo
from flybirds.cli.create_project import create_demo, create_mini
from flybirds.cli.parse_args import parse_args, default_report_path
from flybirds.core.launch_cycle.run_manage import run_script

Expand Down Expand Up @@ -82,11 +82,22 @@ def runner(


@app.command("create")
def create_project():
def create_project(
mini: bool = typer.Option(
None,
"--mini",
"-M",
help="create mini project",
)

):
"""
Generate project example
"""
create_demo()
if mini is not None:
create_mini()
else:
create_demo()


if __name__ == "__main__":
Expand Down
72 changes: 61 additions & 11 deletions flybirds/cli/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_demo():
p_message = platform_start + platform_ending
test_platform = typer.prompt(p_message)
if test_platform is None or test_platform.strip().lower() not in [
'android', 'ios', 'web']:
'android', 'ios', 'web']:
test_platform = 'android'
test_platform = test_platform.strip().lower()
user_dict['test_platform'] = test_platform
Expand Down Expand Up @@ -128,22 +128,73 @@ def create_demo():
)


def copy_from_template(progress, user_dict):
def create_mini():
"""
Create mini project cli
"""
user_dict = {}

try:
typer.echo(f"Cloning into ...")
total = 900
with typer.progressbar(length=total, label="Processing") as progress:
demo_path = copy_from_template(progress, user_dict, os.path.normpath(os.getcwd()))
compare_path = os.path.join(demo_path, "compareData")
feat_files = get_files_from_dir(compare_path)

config_ele = os.path.join(demo_path, "config/ele_locator.json")
feat_files.append(config_ele)

config_schema = os.path.join(demo_path, "config/schema_url.json")
feat_files.append(config_schema)

config_flybirds = os.path.join(demo_path, "config/flybirds_config.json")
feat_files.append(config_flybirds)

interface_path = os.path.join(demo_path, "interfaceIgnoreConfig/test.json")
feat_files.append(interface_path)

mock_path = os.path.join(demo_path, "mockCaseData/mock_test.json")
feat_files.append(mock_path)

for file in feat_files:
os.remove(file)

feature_path = os.path.join(demo_path, "features/test")
shutil.rmtree(feature_path)

typer.secho(
f"Done it! Create Project has success!\n"
f"You can find it at: {demo_path}",
fg=typer.colors.MAGENTA,
)
except Exception as e:
typer.secho(
f"Error!! create project has error, errMsg: {e}",
fg=typer.colors.MAGENTA,
err=True,
)


def copy_from_template(progress, user_dict, target=None):
"""
Generate project files from template
"""
# Serialization path
src_file_path = template.__file__
src_path = os.path.normpath(src_file_path[0: src_file_path.rfind(os.sep)])
target_path = os.path.normpath(
os.path.join(os.path.normpath(os.getcwd()),
user_dict.get('project_name'))
)
if target is None:
target_path = os.path.normpath(
os.path.join(os.path.normpath(os.getcwd()),
user_dict.get('project_name'))
)
if os.path.isdir(target_path):
# target_path is existed
shutil.rmtree(target_path)
else:
target_path = target

if os.path.isdir(target_path):
# target_path is existed
shutil.rmtree(target_path)
shutil.copytree(src_path, target_path)
shutil.copytree(src_path, target_path, dirs_exist_ok=True)
progress.update(100)

try:
Expand Down Expand Up @@ -179,7 +230,6 @@ def copy_from_template(progress, user_dict):

# modify packageName
package_name = user_dict.get('package_name')
package_name = user_dict.get('package_name')
if package_name is not None:
replace_file_content(
os.path.join(target_path, "config/flybirds_config.json"),
Expand Down
2 changes: 1 addition & 1 deletion flybirds/core/plugin/plugins/default/step/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start_app(context, param):
g_Context.app.wake_app(param, 10)
gr.set_value("packageName", param)
# Modal box error detection
poco_ele.detect_error()
# poco_ele.detect_error()


def restart_app(context):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ airtest>=1.2.6
setuptools>=47.1.0
behave==1.2.6
jsonpath==0.82
typer>=0.4.0
typer>=0.6.0
tidevice==0.5.9
pyasn1==0.4.8
pyOpenSSL==19.1.0
Expand All @@ -17,3 +17,4 @@ paddlepaddle>=2.3.0
protobuf==3.20.1
baseImage>=2.1.1
ffmpeg-python>=0.2.0
rich<13.0.0,>=10.11.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse_requirements(filename):

setup(
name="flybirds",
version="0.4.5",
version="0.4.6",
author="trip_flight",
author_email="[email protected]",
description="BDD-driven natural language automated testing framework",
Expand Down

0 comments on commit 9a6ecde

Please sign in to comment.