fix some cli bugs, update manifest, Fix #29

This commit is contained in:
Matthew Scragg 2014-10-17 12:03:38 -05:00
parent 3be7ad1ab6
commit 2e38c6a34c
7 changed files with 26 additions and 28 deletions

View file

@ -1,6 +1,6 @@
include requirements.txt VERSION LICENSE include requirements.txt VERSION LICENSE README.md
recursive-include realms/static/css *
recursive-include realms/static/fonts * recursive-include realms/static/fonts *
recursive-include realms/static/css *
recursive-include realms/static/js * recursive-include realms/static/js *
recursive-include realms/static/vendor * recursive-include realms/static/vendor *
recursive-include realms/templates * recursive-include realms/templates *

View file

View file

@ -1 +1 @@
0.3.14 0.3.19

View file

@ -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.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict
from realms.lib.hook import HookModelMeta from realms.lib.hook import HookModelMeta
from realms.lib.util import is_su, in_virtualenv
class Application(Flask): class Application(Flask):
@ -179,8 +180,15 @@ if app.config['RELATIVE_PATH']:
@click.group() @click.group()
def cli(): @click.pass_context
pass 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 # Init plugins here if possible
login_manager = LoginManager(app) login_manager = LoginManager(app)

View file

@ -1,5 +1,5 @@
from realms import config, app, cli, db from realms import config, app, db, cli
from realms.lib.util import random_string from realms.lib.util import random_string, in_virtualenv
from subprocess import call, Popen from subprocess import call, Popen
from multiprocessing import cpu_count from multiprocessing import cpu_count
import click import click
@ -8,15 +8,6 @@ import sys
import os 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(): def get_user():
for name in ('SUDO_USER', 'LOGNAME', 'USER', 'LNAME', 'USERNAME'): for name in ('SUDO_USER', 'LOGNAME', 'USER', 'LNAME', 'USERNAME'):
user = os.environ.get(name) user = os.environ.get(name)
@ -24,14 +15,6 @@ def get_user():
return user return user
def in_virtualenv():
return hasattr(sys, 'real_prefix')
def is_su():
return os.geteuid() == 0
def get_pid(): def get_pid():
try: try:
with file(config.PIDFILE) as f: with file(config.PIDFILE) as f:
@ -63,7 +46,6 @@ def red(s):
@cli.command() @cli.command()
@check_su
@click.option('--site-title', @click.option('--site-title',
default=config.SITE_TITLE, default=config.SITE_TITLE,
prompt='Enter site title.') prompt='Enter site title.')
@ -154,7 +136,6 @@ def get_pip():
@cli.command() @cli.command()
@check_su
@click.argument('cmd', nargs=-1) @click.argument('cmd', nargs=-1)
def pip(cmd): def pip(cmd):
""" Execute pip commands, useful for virtualenvs """ Execute pip commands, useful for virtualenvs
@ -193,7 +174,6 @@ def setup_memcached(**kw):
@cli.command() @cli.command()
@check_su
@click.option('--user', @click.option('--user',
default=get_user(), default=get_user(),
type=click.STRING, type=click.STRING,

View file

@ -4,6 +4,7 @@ import hashlib
import json import json
import string import string
import random import random
import sys
from jinja2 import Template from jinja2 import Template
@ -99,6 +100,15 @@ def to_canonical(s):
def gravatar_url(email): def gravatar_url(email):
return "//www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() 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): def upstart_script(user='root', app_dir=None, port=5000, workers=2, path=None):
script = """ script = """
limit nofile 65335 65335 limit nofile 65335 65335

View file

@ -6,7 +6,7 @@ if os.environ.get('USER', '') == 'vagrant':
DESCRIPTION = "Simple git based wiki" DESCRIPTION = "Simple git based wiki"
with open('README') as f: with open('README.md') as f:
LONG_DESCRIPTION = f.read() LONG_DESCRIPTION = f.read()
with open('requirements.txt') as f: with open('requirements.txt') as f: