def run(opts, **kw): # parse paths if not '/' in opts.module_name: root_dir = here('.') _slug = slug(opts.module_name) else: parts = opts.module_name.split('/') root_dir = "/".join(parts[:1]) _slug = slug(parts[-1]) kw.update({ 'root_dir': root_dir, 'name': _slug.replace('-', '_'), 'slug': _slug, 'description': opts.description, 'github_user': opts.github_user, 'author': opts.author, 'update': opts.update }) if opts.template: kw['tmpl_dir'] = opts.template log.info( 'Creating Sous Chef Module: {}'.format(opts.module_name)) sc_module.create(**kw)
def run(opts, **kw): # parse paths if not '/' in opts.module_name: root_dir = here('.') _slug = slug(opts.module_name) else: parts = opts.module_name.split('/') root_dir = "/".join(parts[:1]) _slug = slug(parts[-1]) kw.update({ 'root_dir': root_dir, 'name': _slug.replace('-', '_'), 'slug': _slug, 'description': opts.description, 'github_user': opts.github_user, 'author': opts.author, 'update': opts.update }) if opts.template: kw['tmpl_dir'] = opts.template log.info('Creating Sous Chef Module: {}'.format(opts.module_name)) sc_module.create(**kw)
""" Utilities for initializing NewsLynx """ import os from newslynx.lib.serialize import yaml_to_obj from newslynx.exc import ConfigError from newslynx import settings from newslynx.models import sous_chef_schema from newslynx.util import recursive_listdir, here # directory of built-in sous chefs SOUS_CHEF_DIR = here(__file__, 'sc') # directory of built-in sql functions SQL_DIR = here(__file__, 'sql') def _load_config_file(fp): """ Attempt to load a file or raise a ConfigError """ try: return yaml_to_obj(open(fp).read()) except Exception as e: raise ConfigError( "There was an error loding config '{}'.\n" "Here is the error: \n{}" .format(fp, e.message))
""" Default configurations that can be overriden by ~/.newslynx/config.yaml or ENV variables. """ import os from newslynx.util import here _DEFAULT_CONFIG = here(__file__, "app/config.yaml") _CONFIG_REQUIRES = [ 'super_user', 'super_user_email', 'super_user_apikey', 'super_user_password', 'sqlalchemy_database_uri', 'secret_key' ] _DEFAULT_DEFAULTS = here(__file__, "app/defaults/") TESTING = False CONFIG_FILE = os.getenv('NEWSLYNX_CONFIG_FILE', os.path.expanduser('~/.newslynx/config.yaml')) DEFAULT_TAGS = os.path.expanduser('~/.newslynx/defaults/tags.yaml') DEFAULT_RECIPES = os.path.expanduser('~/.newslynx/defaults/recipes.yaml') # sous chefs SOUS_CHEFS_DIR = os.path.expanduser('~/.newslynx/sous-chefs/') # app configurations # API_URL = "http://localhost:5000" API_DNS = "http://changeme.com:5000" API_PORT = 5000 API_VERSION = "v1"
import re import importlib from jsonschema import Draft4Validator from newslynx.sc import SousChef as SC from newslynx.exc import SousChefSchemaError from newslynx.models import SousChef from newslynx.lib.serialize import yaml_to_obj from newslynx.lib.serialize import obj_to_json, json_to_obj from newslynx.constants import SOUS_CHEF_RESERVED_FIELDS from newslynx.util import here, update_nested_dict # load souschef schema + validator. SOUS_CHEF_JSON_SCHEMA = yaml_to_obj( open(here(__file__, 'sous_chef.yaml')).read()) # these are default options that all sous chefs have. SOUS_CHEF_DEFAULT_OPTIONS = yaml_to_obj( open(here(__file__, 'sous_chef_default_options.yaml')).read()) # a json-schema validator for a sous chef. SOUS_CHEF_VALIDATOR = Draft4Validator(SOUS_CHEF_JSON_SCHEMA) # a regex for validation option + metric names re_opt_name = re.compile(r'^[a-z][a-z_]+[a-z]$') def validate(sc): """ Validate a sous chef schema:
from newslynx.models import recipe_schema from newslynx.core import db from newslynx.lib import dates from newslynx.lib.serialize import obj_to_json from newslynx.constants import * from newslynx.exc import RecipeSchemaError from newslynx.util import here from newslynx.tasks import rollup_metric from newslynx.lib.text import slug log = logging.getLogger(__name__) # fake factory fake = Faker() fixtures_dir = here(__file__, 'fixtures') thumbnail = open('{}/thumbnail.txt'.format(fixtures_dir)).read() IMG_URL = 'https://www.propublica.org/images/ngen/gypsy_og_image/20150520-group-home-hearing-1200x630.jpg' IMPACT_TAG_NAMES = [ 'Media pickup', 'Media social share', 'Indv. social share', 'Comm. social share' ] SUBJECT_TAG_NAMES = ['Environment', 'Money & politics', 'Government', 'Health'] AUTHORS = ['Michael Keller', 'Brian Abelson', 'Merlynne Jones'] # a lookup of letters to their number letters_to_int = dict(zip(list(set(letters.lower())), range(1, 27)))
from newslynx.models import recipe_schema from newslynx.core import db from newslynx.lib import dates from newslynx.lib.serialize import obj_to_json from newslynx.constants import * from newslynx.exc import RecipeSchemaError from newslynx.util import here from newslynx.tasks import rollup_metric from newslynx.lib.text import slug log = logging.getLogger(__name__) # fake factory fake = Faker() fixtures_dir = here(__file__, 'fixtures') thumbnail = open('{}/thumbnail.txt'.format(fixtures_dir)).read() IMG_URL = 'https://www.propublica.org/images/ngen/gypsy_og_image/20150520-group-home-hearing-1200x630.jpg' IMPACT_TAG_NAMES = ['Media pickup', 'Media social share', 'Indv. social share', 'Comm. social share'] SUBJECT_TAG_NAMES = ['Environment', 'Money & politics', 'Government', 'Health'] AUTHORS = ['Michael Keller', 'Brian Abelson', 'Merlynne Jones'] # a lookup of letters to their number letters_to_int = dict(zip(list(set(letters.lower())), range(1, 27))) def random_date(n1, n2):
from googleanalytics.auth import Credentials from flask import (Blueprint, request, session, redirect, url_for, render_template) from newslynx.core import settings from newslynx.core import db from newslynx.models import Auth from newslynx.exc import AuthError, RequestError from newslynx.lib.serialize import jsonify from newslynx.views.decorators import load_user, load_org from newslynx.views.util import (obj_or_404, delete_response, request_data) from newslynx.lib import url from newslynx.util import here # blueprint tmpl_folder = here(__file__, 'templates/') bp = Blueprint('auth_google_analytics', __name__, template_folder=tmpl_folder) if settings.GA_ENABLED: # auth flow # ga_oauth = googleanalytics.auth.Flow( settings.GOOGLE_ANALYTICS_CLIENT_ID, settings.GOOGLE_ANALYTICS_CLIENT_SECRET, redirect_uri=urljoin(settings.API_DNS, '/api/v1/auths/google-analytics/callback')) # oauth utilities # def ga_revoke_access(tokens): """
""" Default configurations that can be overriden by ~/.newslynx/config.yaml or ENV variables. """ import os from newslynx.util import here _DEFAULT_CONFIG = here(__file__, "app/config.yaml") _CONFIG_REQUIRES = [ 'super_user', 'super_user_email', 'super_user_apikey', 'super_user_password', 'sqlalchemy_database_uri', 'secret_key' ] _DEFAULT_DEFAULTS = here(__file__, "app/defaults/") TESTING = False CONFIG_FILE = os.getenv('NEWSLYNX_CONFIG_FILE', os.path.expanduser('~/.newslynx/config.yaml')) DEFAULT_TAGS = os.path.expanduser('~/.newslynx/defaults/tags.yaml') DEFAULT_RECIPES = os.path.expanduser('~/.newslynx/defaults/recipes.yaml') # sous chefs SOUS_CHEFS_DIR = os.path.expanduser('~/.newslynx/sous-chefs/') # app configurations # API_URL = "http://localhost:5000"
render_template ) from newslynx.core import settings from newslynx.core import db from newslynx.models import Auth from newslynx.exc import AuthError, RequestError from newslynx.lib.serialize import jsonify from newslynx.views.decorators import load_user, load_org from newslynx.views.util import ( obj_or_404, delete_response, request_data) from newslynx.lib import url from newslynx.util import here # blueprint tmpl_folder = here(__file__, 'templates/') bp = Blueprint('auth_google_analytics', __name__, template_folder=tmpl_folder) if settings.GA_ENABLED: # auth flow # ga_oauth = googleanalytics.auth.Flow( settings.GOOGLE_ANALYTICS_CLIENT_ID, settings.GOOGLE_ANALYTICS_CLIENT_SECRET, redirect_uri=urljoin( settings.API_DNS, '/api/v1/auths/google-analytics/callback')) # oauth utilities #
""" Utilities for initializing NewsLynx """ import os import logging from newslynx.lib.serialize import yaml_to_obj from newslynx.exc import ConfigError from newslynx.core import settings from newslynx.models import sous_chef_schema from newslynx.util import recursive_listdir, here log = logging.getLogger(__name__) # directory of built-in sous chefs SOUS_CHEF_DIR = here(__file__, 'sc') # directory of built-in sql functions SQL_DIR = here(__file__, 'sql') def _load_config_file(fp): """ Attempt to load a file or raise a ConfigError """ try: return yaml_to_obj(open(fp).read()) except Exception as e: raise ConfigError( "There was an error loding config '{}'.\n" "Here is the error: \n{}"
import os import logging from traceback import format_exc import pip from jinja2 import Template from git import Repo from newslynx.util import here from newslynx.core import settings from newslynx.exc import SousChefInstallError log = logging.getLogger(__name__) DEFAULT_TMPL_DIR = here(__file__, 'template/') DUMMY_SOUS_CHEF_CLASS = """ import os from newslynx.sc import SousChef class SayMyName(SousChef): def run(self): msg = 'Hello {my_name}!'.format(**self.options) os.system("say '{}'".format(msg)) self.log.info(msg) return self.options """
import os.path from traceback import format_exc from jsonschema import Draft4Validator from newslynx.sc import SousChef as SC from newslynx.exc import SousChefSchemaError from newslynx.models import SousChef from newslynx.lib.serialize import yaml_stream_to_obj from newslynx.lib.serialize import obj_to_json, json_to_obj from newslynx.constants import SOUS_CHEF_RESERVED_FIELDS from newslynx.util import here, update_nested_dict # load souschef schema + validator. SOUS_CHEF_JSON_SCHEMA = yaml_stream_to_obj( open(here(__file__, 'sous_chef.yaml'))) # these are default options that all sous chefs have. SOUS_CHEF_DEFAULT_OPTIONS = yaml_stream_to_obj( open(here(__file__, 'sous_chef_default_options.yaml'))) # a json-schema validator for a sous chef. SOUS_CHEF_VALIDATOR = Draft4Validator(SOUS_CHEF_JSON_SCHEMA) # a regex for validation option + metric names re_opt_name = re.compile(r'^[a-z][a-z_]+[a-z]$') def load(fp): """ Load a sous chef allowing for include statements.