-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
169 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from jinja2 import Environment, PackageLoader | ||
|
||
__version__ = "2.1.0" | ||
__version__ = "3.0.0" | ||
|
||
env = Environment(loader=PackageLoader('bench.config'), trim_blocks=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import bench, os | ||
import bench, os, click | ||
from bench.utils import find_executable | ||
|
||
def setup_procfile(bench_path): | ||
def setup_procfile(bench_path, force=False): | ||
procfile_path = os.path.join(bench_path, 'Procfile') | ||
if not force and os.path.exists(procfile_path): | ||
click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?', | ||
abort=True) | ||
|
||
procfile = bench.env.get_template('Procfile').render(node=find_executable("node") \ | ||
or find_executable("nodejs")) | ||
with open(os.path.join(bench_path, 'Procfile'), 'w') as f: | ||
|
||
with open(procfile_path, 'w') as f: | ||
f.write(procfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os, importlib | ||
|
||
def run(bench_path): | ||
source_patch_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'patches.txt') | ||
target_patch_file = os.path.join(os.path.abspath(bench_path), 'patches.txt') | ||
|
||
with open(source_patch_file, 'r') as f: | ||
patches = [p.strip() for p in f.read().splitlines() | ||
if p.strip() and not p.strip().startswith("#")] | ||
|
||
executed_patches = [] | ||
if os.path.exists(target_patch_file): | ||
with open(target_patch_file, 'r') as f: | ||
executed_patches = f.read().splitlines() | ||
|
||
try: | ||
for patch in patches: | ||
if patch not in executed_patches: | ||
module = importlib.import_module(patch.split()[0]) | ||
execute = getattr(module, 'execute') | ||
execute(bench_path) | ||
executed_patches.append(patch) | ||
|
||
finally: | ||
with open(target_patch_file, 'w') as f: | ||
f.write('\n'.join(executed_patches)) | ||
|
||
# end with an empty line | ||
f.write('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bench.patches.v3.deprecate_old_config | ||
bench.patches.v3.celery_to_rq |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import click, os | ||
from bench.config.procfile import setup_procfile | ||
from bench.config.supervisor import generate_supervisor_config | ||
|
||
def execute(bench_path): | ||
click.confirm('\nThis update will remove Celery config and prepare the bench to use Python RQ.\n' | ||
'And it will overwrite Procfile and supervisor.conf.\n' | ||
'If you don\'t know what this means, type Y ;)\n\n' | ||
'Do you want to continue?', | ||
abort=True) | ||
|
||
setup_procfile(bench_path, force=True) | ||
|
||
# if production setup | ||
if os.path.exists(os.path.join(bench_path, 'config', 'supervisor.conf')): | ||
generate_supervisor_config(bench_path, force=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os, json | ||
from bench.config.common_site_config import get_config, put_config, get_common_site_config | ||
|
||
def execute(bench_path): | ||
# deprecate bench config | ||
bench_config_path = os.path.join(bench_path, 'config.json') | ||
if not os.path.exists(bench_config_path): | ||
return | ||
|
||
with open(bench_config_path, "r") as f: | ||
bench_config = json.loads(f.read()) | ||
|
||
common_site_config = get_common_site_config(bench_path) | ||
common_site_config.update(bench_config) | ||
put_config(common_site_config, bench_path) | ||
|
||
# remove bench/config.json | ||
os.remove(bench_config_path) | ||
|
||
# change keys | ||
config = get_config(bench_path) | ||
changed = False | ||
for from_key, to_key, default in ( | ||
("celery_broker", "redis_queue", "redis://localhost:6379"), | ||
("async_redis_server", "redis_socketio", "redis://localhost:12311"), | ||
("cache_redis_server", "redis_cache", "redis://localhost:11311") | ||
): | ||
if from_key in config: | ||
config[to_key] = config[from_key] | ||
del config[from_key] | ||
changed = True | ||
|
||
elif to_key not in config: | ||
config[to_key] = default | ||
changed = True | ||
|
||
if changed: | ||
put_config(config, bench_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters