From 2e38c6a34c4b3571c15e6be5ec3d6ebd10a90483 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Fri, 17 Oct 2014 12:03:38 -0500 Subject: [PATCH] fix some cli bugs, update manifest, Fix #29 --- MANIFEST.in | 4 ++-- README => README.md | 0 VERSION | 2 +- realms/__init__.py | 12 ++++++++++-- realms/cli.py | 24 ++---------------------- realms/lib/util.py | 10 ++++++++++ setup.py | 2 +- 7 files changed, 26 insertions(+), 28 deletions(-) rename README => README.md (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 41985cd..d72fe63 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ -include requirements.txt VERSION LICENSE -recursive-include realms/static/css * +include requirements.txt VERSION LICENSE README.md recursive-include realms/static/fonts * +recursive-include realms/static/css * recursive-include realms/static/js * recursive-include realms/static/vendor * recursive-include realms/templates * \ No newline at end of file diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/VERSION b/VERSION index 0010ffe..719cd12 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.14 \ No newline at end of file +0.3.19 \ No newline at end of file diff --git a/realms/__init__.py b/realms/__init__.py index b6f81e4..6875fae 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -20,6 +20,7 @@ from werkzeug.exceptions import HTTPException from realms.lib.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict from realms.lib.hook import HookModelMeta +from realms.lib.util import is_su, in_virtualenv class Application(Flask): @@ -179,8 +180,15 @@ if app.config['RELATIVE_PATH']: @click.group() -def cli(): - pass +@click.pass_context +def cli(ctx): + # This could probably done better + if ctx.invoked_subcommand in ['setup', 'setup_upstart', 'pip']: + if not in_virtualenv() and not is_su(): + # This does not account for people the have user level python installs + # that aren't virtual environments! Should be rare I think + click.secho("This command requires root privileges, use sudo or run as root.", fg='red') + sys.exit() # Init plugins here if possible login_manager = LoginManager(app) diff --git a/realms/cli.py b/realms/cli.py index 8e6a4cb..a8a7e89 100644 --- a/realms/cli.py +++ b/realms/cli.py @@ -1,5 +1,5 @@ -from realms import config, app, cli, db -from realms.lib.util import random_string +from realms import config, app, db, cli +from realms.lib.util import random_string, in_virtualenv from subprocess import call, Popen from multiprocessing import cpu_count import click @@ -8,15 +8,6 @@ import sys import os -def check_su(f): - if not in_virtualenv() and not is_su(): - # This does not account for people the have user level python installs - # that aren't virtual environments! Should be rare I think - red("This command requires root privileges, use sudo or run as root.") - sys.exit() - return f - - def get_user(): for name in ('SUDO_USER', 'LOGNAME', 'USER', 'LNAME', 'USERNAME'): user = os.environ.get(name) @@ -24,14 +15,6 @@ def get_user(): return user -def in_virtualenv(): - return hasattr(sys, 'real_prefix') - - -def is_su(): - return os.geteuid() == 0 - - def get_pid(): try: with file(config.PIDFILE) as f: @@ -63,7 +46,6 @@ def red(s): @cli.command() -@check_su @click.option('--site-title', default=config.SITE_TITLE, prompt='Enter site title.') @@ -154,7 +136,6 @@ def get_pip(): @cli.command() -@check_su @click.argument('cmd', nargs=-1) def pip(cmd): """ Execute pip commands, useful for virtualenvs @@ -193,7 +174,6 @@ def setup_memcached(**kw): @cli.command() -@check_su @click.option('--user', default=get_user(), type=click.STRING, diff --git a/realms/lib/util.py b/realms/lib/util.py index 47e8b14..8166ffa 100644 --- a/realms/lib/util.py +++ b/realms/lib/util.py @@ -4,6 +4,7 @@ import hashlib import json import string import random +import sys from jinja2 import Template @@ -99,6 +100,15 @@ def to_canonical(s): def gravatar_url(email): return "//www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() + +def in_virtualenv(): + return hasattr(sys, 'real_prefix') + + +def is_su(): + return os.geteuid() == 0 + + def upstart_script(user='root', app_dir=None, port=5000, workers=2, path=None): script = """ limit nofile 65335 65335 diff --git a/setup.py b/setup.py index 30b39f6..55ad062 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ if os.environ.get('USER', '') == 'vagrant': DESCRIPTION = "Simple git based wiki" -with open('README') as f: +with open('README.md') as f: LONG_DESCRIPTION = f.read() with open('requirements.txt') as f: