2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-14 09:14:04 +00:00

Merge pull request #215 from vjFaLk/get-app

Removed get-app app-name argument
This commit is contained in:
Anand Doshi 2016-05-18 18:11:15 +05:30
commit a09cc4424a
5 changed files with 37 additions and 16 deletions

View File

@ -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)
@ -211,7 +221,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'):

View File

@ -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')

19
bench/tests/test_init.py Normal file → Executable file
View File

@ -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)
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")))

View File

@ -28,7 +28,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='.'):
@ -60,7 +60,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)

View File

@ -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']: