示例#1
0
def joinchunks():
    msg = request.form
    outfile = msg['filename']
    filesize = msg['filesize']
    tofile = os.path.join(config.get('fileload', 'UPLOAD_FOLDER'),outfile)
    fromdir = os.path.join(config.get('fileload', 'UPLOAD_FOLDER'),'temp')
    output = open(tofile, 'wb')
    parts  = os.listdir(fromdir)
    parts.sort(  )
    for filename in parts:
        filepath = os.path.join(fromdir, filename)
        fileobj  = open(filepath, 'rb')
        while 1:
            filebytes = fileobj.read(readsize)
            if not filebytes: break
            output.write(filebytes)
        fileobj.close()
    output.close()
    data = {'filename': outfile}
    if os.path.isfile(tofile) and os.stat(tofile).st_size == int(filesize):
        data['status'] = 'Success'
        for filename in parts:
            filepath = os.path.join(fromdir, filename)
            os.remove(filepath)
    else:
        data['status'] = 'Failed'
    resp = jsonify(data)
    resp.status_code = 200
    return resp
示例#2
0
 def default(self, obj):
     if isinstance(obj, (datetime, date)):
         return obj.strftime(config.get('api', 'dtformat'))
     elif isinstance(obj, Decimal):
         return float(str(obj))
     else:
         super(JSONLawDEncoder, self).default(obj)
示例#3
0
    def test_client_api(self):
        app=self.create_app()
        headers = {
                    'Authorization': 'Basic ' + b64encode("{0}:{1}".format(config.get( 'adb', 'userid' ), config.get( 'adb', 'passcode' )))
                   }
        response =   app.get('/apiv1/clientinfo/sfdcapi/facebook', headers=headers)

        self.assertEqual(response.status_code, 200)
        respdata = json.loads(response.data)
        self.assertEqual(respdata['acct_id'], 1001)
        self.assertEqual(respdata['rulescount'], 2)
        self.assertEqual(respdata['groupcount'], 5)
        self.assertEqual(respdata['usercount'], 7)

        response =   app.get('/apiv1/clientinfo/sfdcapi/heroku', headers=headers)

        self.assertEqual(response.status_code, 200)
        respdata = json.loads(response.data)
        self.assertEqual(respdata['acct_id'], 1000)
        self.assertEqual(respdata['rulescount'], 9)
        self.assertEqual(respdata['groupcount'], 7)
        self.assertEqual(respdata['usercount'], 5)

        response =   app.get('/apiv1/clientinfo/sfdcapi/google', headers=headers)

        self.assertEqual(response.status_code, 200)
        respdata = json.loads(response.data)
        self.assertEqual(respdata['acct_id'], 1002)
        self.assertEqual(respdata['rulescount'], 1)
        self.assertEqual(respdata['groupcount'], 2)
        self.assertEqual(respdata['usercount'], 3)
示例#4
0
def initial_touchbiz_entry():
    epoch_start = datetime(1970, 1, 1)
    with tb_loader() as l:
        company = l.query( SalesReps )\
                   .filter( SalesReps.email == config.get( 'touchbiz', 'company_user' ) )\
                   .one()

        initial = Touchbiz(
            created=epoch_start,
            modified=epoch_start,
        )
        initial.owner = company

    return initial
示例#5
0
def upload():


# Get the name of the uploaded file
     file = request.files['filename']
     print 'file upload request received ', file    
#     # Check if the file is one of the allowed types/extensions
     if file :
#         # Make the filename safe, remove unsupported chars
         filename = secure_filename(file.filename)
#         # Move the file form the temporal folder to
#         # the upload folder we setup
         file.save(os.path.join(config.get('fileload', 'UPLOAD_FOLDER'),'temp',filename))
         file_status = [{'upldstatus':'complete','name':filename}]
         data = {'filename': filename, 'status':'complete' }
         resp = jsonify(data)
         resp.status_code = 200
         return resp
     else:
         data = {'filename': 'Bad files', 'status':'failure' }
         resp = jsonify(data)
         resp.status_code = 400
         return resp
示例#6
0
                                        Integer, DateTime, Date,
                                        Boolean, String,Text,
                                        Numeric, ForeignKey,
                                        Index)
from sqlalchemy.dialects.mysql  import BIGINT, SMALLINT, MEDIUMINT
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm             import sessionmaker, relationship, backref
from sqlalchemy.ext.hybrid import hybrid_method

Base = declarative_base()
# Duplicate models of the same table need another base declaration
# so that they have a separate MetaData instance
OwnersBase = declarative_base()

db_url = '{dialect}://{user}:{passwd}@{host}:{port}/{dbname}'.format(
    dialect = config.get( 'a2', 'dialect' ),
    user    = config.get( 'a2', 'username' ),
    passwd  = config.get( 'a2', 'password' ),
    host    = config.get( 'a2', 'host' ),
    port    = config.get( 'a2', 'port' ),
    dbname  = config.get( 'a2', 'dbname' ),
)

engine = create_engine( 
            db_url, 
            echo=config.getboolean( 'a2', 'debug' ),
            pool_recycle=config.getint( 'a2', 'pool_recycle' ),
         )

Session = sessionmaker( bind=engine )
示例#7
0
"""
" Copyright:    Loggly, Inc.
" Author:       Scott Griffin
" Email:        [email protected]
"
" LAW specific loggers.
"
"""
import os
import logging, logging.handlers

from law import config

LOG_PREFIX = 'LAW'
LOG_FORMAT = config.get('logging', 'format', raw=True)
LOG_PATH = config.get('logging', 'logdir')
LOG_LEVEL = getattr(logging, config.get('logging', 'level'))
LOG_MAX_BYTES = config.getint('logging', 'maxbytes')
LOG_BACKUPS = config.getint('logging', 'numbackups')


def make_logger(name, level=LOG_LEVEL, path=LOG_PATH):
    if not os.path.exists(LOG_PATH):
        os.makedirs(LOG_PATH, 0775)
    logger = logging.getLogger('{}.{}'.format(LOG_PREFIX, name))
    logger.setLevel(level)

    rfh = logging.handlers.RotatingFileHandler(os.path.join(LOG_PATH, name),
                                               maxBytes=LOG_MAX_BYTES,
                                               backupCount=LOG_BACKUPS)
    formatter = logging.Formatter(LOG_FORMAT)
示例#8
0
def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    return username == config.get('adb', 'userid') and password == config.get(
        'adb', 'passcode')
示例#9
0
                                        Index)
from sqlalchemy.dialects.mysql  import BIGINT, SMALLINT, MEDIUMINT
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm             import sessionmaker, relationship, backref
import logging

logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

Base = declarative_base()
# Duplicate models of the same table need another base declaration
# so that they have a separate MetaData instance
OwnersBase = declarative_base()

db_url = '{dialect}://{user}:{passwd}@{host}:{port}/{dbname}'.format(
    dialect = config.get( 'salesorder', 'dialect' ),
    user    = config.get( 'salesorder', 'username' ),
    passwd  = config.get( 'salesorder', 'password' ),
    host    = config.get( 'salesorder', 'host' ),
    port    = config.get( 'salesorder', 'port' ),
    dbname  = config.get( 'salesorder', 'dbname' ),
)

engine = create_engine(
            db_url,
            echo=config.getboolean( 'salesorder', 'debug' ),
            pool_recycle=config.getint( 'salesorder', 'pool_recycle' ),
         )

Session = sessionmaker( bind=engine )
示例#10
0
" Flask interface for the web module
"
"""
from datetime import datetime, date
from decimal import Decimal

from flask import Flask, url_for
from flask.json import JSONEncoder
from law import config
from law.web             import views, subscription, volumes, salesdash, touchbiz, salesorder, userinfo, tracer, \
                         cluster
from law.util.adb import Session, AccountState, Tier
from law.util.lawdb import db_url, db, security
from flask.ext.login import current_user, current_app, login_user

app = Flask(config.get('webapp', 'name'))
app.debug = config.getboolean('webapp', 'debug')

# Blueprints and top-level routes
app.register_blueprint(views.blueprint)

app.register_blueprint(subscription.views.blueprint,
                       url_prefix='/subscription')
app.register_blueprint(volumes.views.blueprint, url_prefix='/volumes')
app.register_blueprint(salesdash.views.blueprint, url_prefix='/sales')
app.register_blueprint(userinfo.views.blueprint, url_prefix='/user')
app.register_blueprint(touchbiz.views.blueprint, url_prefix='/touchbiz')
app.register_blueprint(salesorder.views.blueprint, url_prefix='/salesorder')
app.register_blueprint(tracer.views.blueprint, url_prefix='/tracer')
app.register_blueprint(cluster.views.blueprint, url_prefix='/cluster')