def test_call_auto_env(self): """Regression test: Passing the environment to the ManageAssets command is optional, it can be auto-detected.""" mgmt = Manager(self.app) mgmt.add_command('assets', ManageAssets()) try: # Used to raise an error due to the env not being properly set. sys.argv = ['./manage.py', 'assets', 'build'] mgmt.run() except SystemExit: # Always raised, regardless of success or failure of command pass
def test_parse_templates(self): """Test the --parse-templates option. """ # Create a file in the app's templates directory self.app.template_folder = self.path('templates') self.create_files({ 'templates/template.html': """ {% assets "in", output="output" %} {{ ASSET_URL }} {% endassets %} """, 'in': "foo" }) # Run the build command with --parse-templates, which should pick # up the bundle we defined in above template. mgmt = Manager(self.app) mgmt.add_command('assets', ManageAssets(log=stdout_log)) mgmt.handle('test', 'assets', ['--parse-templates', 'build']) assert self.exists('output')
def test_call(self): # Setup the webassets.script with a mock main() function, # so we can check whether our call via Flask-Script actually # goes through. test_inst = self class DummyArgparseImplementation(GenericArgparseImplementation): def run_with_argv(self, argv): test_inst.last_script_call = argv return 0 mgmt = Manager(self.app) mgmt.add_command( 'assets', ManageAssets(self.env, impl=DummyArgparseImplementation)) try: # -h is a great test as that is something Flask-Script might # want to claim for itself. sys.argv = ['./manage.py', 'assets', '-h'] mgmt.run() except SystemExit: # Always raised, regardless of success or failure of command pass assert self.last_script_call == ['-h']
from flaskext.script import Manager from web import db, app manager = Manager(app) @manager.command def createDbSchema(): db.create_all() if __name__ == "__main__": manager.run()
#!/usr/bin/env python # coding: utf-8 from jzsadmin import create_app from jzsadmin.models import User, Entry from jzsadmin.scripts.crawl_ganji import crawl_ganji from flaskext.script import Server, Shell, Manager, Command, prompt_bool manager = Manager(create_app('dev.cfg')) manager.add_command("runserver", Server('0.0.0.0', port=8080)) @manager.option('-u', '--username', dest='name', type=str) @manager.option('-p', '--password', dest='passwd', type=str) @manager.option('-r', '--role', dest='role', default=100, type=int) def adduser(name, passwd, role): user = User(name=name, password=passwd, role=role) user.save() print 'Created' @manager.option('-u', '--username', dest='name', type=str) def deluser(name): user = User.query.filter_by(name=name).first() user.remove() print 'Del.' @manager.option('-c', '--city', dest='city', type=str)
from flaskext.script import Manager import bf3 manager = Manager(bf3.app) @manager.command def initdb(): """Create the database tables""" print 'Using database %s' % bf3.db.engine.url bf3.db.create_all() print 'Created tables' @manager.command def sync(): """Download new messages from twitter and forums""" bf3.sync() print 'Done syncing' if __name__ == '__main__': manager.run()
import pprint import memcache import sys, os, signal import subprocess import time from subprocess import call, Popen, PIPE from flask import Flask, current_app as app from flask import Config from flaskext.script import Server, Shell, Manager, Command, prompt_bool from memcached_stats import MemcachedStats from boardhood import create_app from boardhood.helpers.os import children_pid manager = Manager(create_app('development')) manager.add_command("runserver", Server('127.0.0.1',port=5000)) sql_files_91 = [ '/usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql', '/usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql', '/usr/share/postgresql/9.1/contrib/postgis_comments.sql', 'db/schema.sql', 'db/extras.sql', 'db/functions.sql', 'db/sample.sql' ] sql_files_84 = [ '/usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql', '/usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql',
""" import sys import feedparser from flask import current_app from flaskext.script import Manager, prompt, prompt_pass, \ prompt_bool, prompt_choices from flaskext.mail import Message from newsmeme import create_app from newsmeme.extensions import db, mail from newsmeme.models import Post, User, Comment, Tag manager = Manager(create_app) @manager.option("-u", "--url", dest="url", help="Feed URL") @manager.option("-n", "--username", dest="username", help="Save to user") def importfeed(url, username): """ Bulk import news from a feed. For testing only ! """ user = User.query.filter_by(username=username).first() if not user: print "User %s does not exist" % username sys.exit(1) d = feedparser.parse(url) for entry in d['entries']:
#!/usr/bin/env python #coding=utf-8 import uuid from flask import Flask, current_app from flaskext.script import Server, Shell, Manager, Command, prompt_bool from pypress import create_app from pypress.extensions import db from pypress.models.users import User, UserCode manager = Manager(create_app('config.cfg')) manager.add_command("runserver", Server('0.0.0.0',port=8080)) def _make_context(): return dict(db=db) manager.add_command("shell", Shell(make_context=_make_context)) @manager.command def createall(): "Creates database tables" db.create_all() @manager.command def dropall(): "Drops all database tables" if prompt_bool("Are you sure ? You will lose all your data !"): db.drop_all()
#!/usr/bin/env python # -*- coding: utf-8 -*- """jmoiron.net script/commands""" from flaskext.script import Manager from glob import glob from misc import migrate from jmoiron.app import app, db script = Manager(app) @script.command def loadsql(dumpfile=None): """Reload the SQL database.""" if dumpfile is None: try: dumpfile = glob("*.sql")[-1] except: print "Could not find a dumpfile (*.sql) in CWD." return migrate.loaddb(dumpfile) @script.command def flushdb(): """Flush the database.""" db.drop_collection('blog_post') db.drop_collection('stream_entry') db.drop_collection('stream_plugin')
import subprocess from flaskext.script import Manager, Server from . import app from .freezer import freezer manager = Manager(app, with_default_commands=False) # I prefer shorter names manager.add_command('run', Server()) @manager.command def freeze(serve=False): """Freezes the static version of the website.""" if serve: freezer.run(debug=True) else: urls = freezer.freeze() print 'Built %i files.' % len(urls) @manager.command def up(destination='hako:http/exyr.org/htdocs/'): """Freezes and uploads the website.""" push = subprocess.Popen(['git', 'push'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print '### Freezing' freeze() print '### Uploading to', destination
#!/usr/bin/env python from flaskext.script import Manager from screenchop import urls from scripts.add_invite_code import generate_invite from scripts.tag_freq import tag_frequencies manager = Manager(urls.app) @manager.command def invite_code(): "Generates an invitation code" generate_invite() @manager.command def tag_freq(): "Updates tag_freq collection with updated tag cloud" tag_frequencies() if __name__ == '__main__': manager.run()
""" :copyright: (c) 2011 Local Projects, all rights reserved :license: Affero GNU GPL v3, see LEGAL/LICENSE for more details. """ import os os.environ.setdefault('FLAILS_ENV', 'script') import main from flaskext.script import Manager from flaskext.assets import ManageAssets from script.users import MakeAdmin manager = Manager(main.app) manager.add_command("assets", ManageAssets()) manager.add_command("make_admin", MakeAdmin()) if __name__ == "__main__": manager.run()