diff --git a/bench/app.py b/bench/app.py old mode 100644 new mode 100755 index cc5177a1..3f32ff58 --- a/bench/app.py +++ b/bench/app.py @@ -42,19 +42,29 @@ def write_appstxt(apps, bench='.'): with open(os.path.join(bench, 'sites', 'apps.txt'), 'w') as f: return f.write('\n'.join(apps)) -def get_app(app, git_url, branch=None, bench='.', build_asset_files=True, verbose=False): - logger.info('getting app {}'.format(app)) +def get_app(git_url, branch=None, bench='.', build_asset_files=True, verbose=False): + #Gets repo name from URL + repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0] + logger.info('getting app {}'.format(repo_name)) shallow_clone = '--depth 1' if check_git_for_shallow_clone() else '' branch = '--branch {branch}'.format(branch=branch) if branch else '' - exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream {app}".format( + exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format( git_url=git_url, - app=app, shallow_clone=shallow_clone, branch=branch), cwd=os.path.join(bench, 'apps')) - print 'installing', app - install_app(app, bench=bench, verbose=verbose) + + #Retrieves app name from setup.py + app_path = os.path.join(bench, 'apps', repo_name, 'setup.py') + with open(app_path, 'rb') as f: + app_name = re.search(r'name\s*=\s*[\'"](.*)[\'"]', f.read().decode('utf-8')).group(1) + if repo_name != app_name: + apps_path = os.path.join(os.path.abspath(bench), 'apps') + os.rename(os.path.join(apps_path, repo_name), os.path.join(apps_path, app_name)) + + print 'installing', app_name + install_app(app=app_name, bench=bench, verbose=verbose) if build_asset_files: build_assets(bench=bench) conf = get_config(bench=bench) @@ -201,7 +211,7 @@ def get_major_version(version): def install_apps_from_path(path, bench='.'): apps = get_apps_json(path) for app in apps: - get_app(app['name'], app['url'], branch=app.get('branch'), bench=bench, build_asset_files=False) + get_app(app['url'], branch=app.get('branch'), bench=bench, build_asset_files=False) def get_apps_json(path): if path.startswith('http'): diff --git a/bench/commands/make.py b/bench/commands/make.py index a7c9c712..3efc8da3 100644 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -19,13 +19,13 @@ def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, @click.command('get-app') -@click.argument('name') +@click.argument('name', nargs=-1) # Dummy argument for backward compatibility @click.argument('git-url') @click.option('--branch', default=None, help="branch to checkout") -def get_app(name, git_url, branch): +def get_app(git_url, branch, name=None): "clone an app from the internet and set it up in your bench" from bench.app import get_app - get_app(name, git_url, branch=branch) + get_app(git_url, branch=branch) @click.command('new-app') diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py old mode 100644 new mode 100755 index 867fd39a..ebeb5e2f --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -20,6 +20,8 @@ class TestBenchInit(unittest.TestCase): if os.path.exists(bench_path): shutil.rmtree(bench_path, ignore_errors=True) + + def test_init(self, bench_name="test-bench", **kwargs): self.init_bench(bench_name, **kwargs) @@ -85,16 +87,25 @@ class TestBenchInit(unittest.TestCase): self.assertTrue(key in site_config) self.assertTrue(site_config[key]) - def test_install_app(self): + def test_get_app(self): site_name = "test-site-2.dev" - self.init_bench('test-bench') + self.new_site(site_name) + bench_path = os.path.join(self.benches_path, "test-bench") + + bench.app.get_app("https://github.com/frappe/frappe-client", bench=bench_path) + self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", "frappeclient"))) + def test_install_app(self): + site_name = "test-site-3.dev" + self.init_bench('test-bench') + + self.new_site(site_name) bench_path = os.path.join(self.benches_path, "test-bench") # get app - bench.app.get_app("erpnext", "https://github.com/frappe/erpnext", "develop", bench=bench_path) + bench.app.get_app("https://github.com/frappe/erpnext", "develop", bench=bench_path) self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", "erpnext"))) diff --git a/bench/utils.py b/bench/utils.py index 8a0b981e..854faa64 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -27,7 +27,7 @@ def get_frappe(bench='.'): frappe = get_env_cmd('frappe', bench=bench) if not os.path.exists(frappe): print 'frappe app is not installed. Run the following command to install frappe' - print 'bench get-app frappe https://github.com/frappe/frappe.git' + print 'bench get-app https://github.com/frappe/frappe.git' return frappe def get_env_cmd(cmd, bench='.'): @@ -59,7 +59,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' - get_app('frappe', frappe_path, branch=frappe_branch, bench=path, build_asset_files=False, verbose=verbose) + get_app(frappe_path, branch=frappe_branch, bench=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench=path) diff --git a/vm/ansible/library/bench.py b/vm/ansible/library/bench.py index 4e9d5a5f..cb3aa9e1 100644 --- a/vm/ansible/library/bench.py +++ b/vm/ansible/library/bench.py @@ -60,7 +60,7 @@ def main(): if module.check_mode: module.exit_json(changed=True) - get_app(app['name'], app['url'], app.get('branch', 'master'), bench_path) + get_app(app['url'], app.get('branch', 'master'), bench_path) changed = True for site in module.params['sites']: