Exemple #1
0
def confirm_permission():
    """Raises an exception if the user does not have permission to execute a statement"""
    user = users.get_current_user()
    nologin = NotLoggedInError('Hello! Please $login_link to use this console')
    noadmin = NotAdminError('Please $logout_link, then log in as an administrator')

    if util.is_production():
        if not user:
            raise nologin
        else:
            if config.allow_any_user or util.is_my_website():
                pass                    # Do what the man says.
            else:
                if users.is_current_user_admin():
                    pass                # Grant access to the admin.
                else:
                    raise noadmin       # Administrator access required in production mode
    else:
        if not config.require_login_during_development:
            pass                        # Unrestricted access during development mode
        else:
            if user:
                pass                    # Logged-in user allowed, even in development mode.
            else:
                raise nologin           # Unlogged-in user not allowed in development mode
Exemple #2
0
def confirm_permission():
    """Raises an exception if the user does not have permission to execute a statement"""
    user = users.get_current_user()
    nologin = NotLoggedInError('Hello! Please $login_link to use this console')
    noadmin = NotAdminError(
        'Please $logout_link, then log in as an administrator')

    if util.is_production():
        if not user:
            raise nologin
        else:
            if config.allow_any_user or util.is_my_website():
                pass  # Do what the man says.
            else:
                if users.is_current_user_admin():
                    pass  # Grant access to the admin.
                else:
                    raise noadmin  # Administrator access required in production mode
    else:
        if not config.require_login_during_development:
            pass  # Unrestricted access during development mode
        else:
            if user:
                pass  # Logged-in user allowed, even in development mode.
            else:
                raise nologin  # Unlogged-in user not allowed in development mode
Exemple #3
0
def update_venues():
    refresh_date = datetime.date.today() - datetime.timedelta(venue_refresh_days)
    venues = Venue.select(
        AND(Venue.q.approved != None, OR(Venue.q.batch_updated == None, Venue.q.batch_updated < refresh_date))
    )
    count = venues.count()
    if not util.is_production():
        count = min(count, 10)

    for venue in venues[:count]:
        if venue.zip_code:
            area = ", " + venue.zip_code
        else:
            area = ", Portland, OR"
        if venue.address:
            try:
                lat, lon, zip_code = geo.get_geocode(venue.address + area)
                venue.geocode_lat = lat
                venue.geocode_lon = lon
                if not venue.zip_code:
                    venue.zip_code = zip_code
            except IOError:
                pass
        venue.batch_updated = datetime.datetime.now()

    return count
Exemple #4
0
def br_startup():
    scheduler.add_interval_task(batch.hourly_task, 60 * 60)
    if util.is_production():
        scheduler.add_weekday_task(batch.nightly_task, range(1, 8), (3, 0))
    else:
        scheduler.add_interval_task(batch.nightly_task, 60 * 5)
    saved_visit.start_extension()
    root_variable_providers.append(add_root_vars)
Exemple #5
0
def build_parser(lb_interactive_available=True):
    """
        Create and return a command line parser. The parser is initialized
        with all commands that are found in the command directory.
    """

    # lookup commands
    commands = []
    command_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'command')
    for dirpath, dirnames, filenames in os.walk(command_dir):
        for filename in filenames:
            if filename.endswith('.py') and not filename.startswith('.') and filename != '__init__.py':
                commands.append(filename[:-3])

    # create the main parser with our own help formatter
    if lb_interactive_available:
        parser = lbparser.LBArgumentParser(prog='lb', formatter_class=lbparser.LBHelpFormatter)
        subparsers = parser.add_subparsers(title='db commands')
    else:
        parser = argparse.ArgumentParser(prog='lb', formatter_class=lbparser.CLICommandHelpFormatter)
        subparsers = parser.add_subparsers(title='commands')

    # add global --version option if file exists
    with open(os.environ.get('LOGICBLOX_HOME') + "/libexec/logicblox/version") as file:
        version = file.read().rstrip()
    parser.add_argument('--version', '-v', action='version', help='print lb version', version=version)

    # ask commands to register themselves to the parser
    for command in commands:
        try:
            module = importlib.import_module('cli.command.' + command)

            if not util.is_production() or not hasattr(module, 'is_production') or module.is_production is not False:
                #print 'loading ' + str(module)
                module.add_commands(parser, subparsers)

        except ImportError, e:
            import traceback
            traceback.print_exc()
            print e
            raise lb_exception.LBCommandAPIException('Could not import module for command: ' + command)
        except AttributeError, e:
            import traceback
            traceback.print_exc()
            print e
            raise lb_exception.LBCommandAPIException('Command does not implement add_commands(parser, subparsers) function: ' + command)
Exemple #6
0
    Artist,
    SimilarArtist,
    AND,
    OR,
    SQLObjectNotFound,
)
from sqlobject.main import SQLObjectIntegrityError
import datetime
from imports import cdbaby, amazon, lastfm, mbz
import time
import geo
import util

log = logging.getLogger("bandradar.batch")

if util.is_production():
    queries_per_run = 1000
else:
    queries_per_run = 10

artist_refresh_days = 30
venue_refresh_days = 30


def hourly_task():
    hub.threadingLocal = threading_local()
    hub.begin()
    # notify admins of pending events added by users
    events_pending = Event.select(Event.q.approved == None)
    pending_count = events_pending.count()
    unnotified = events_pending.filter(Event.q.admin_notified == False)