<commit_before># -*- coding: utf-8 -*-
'''
Return salt data via slack

.. versionadded:: 2015.5.0

The following fields can be set in the minion conf file::

    slack.channel (required)
    slack.api_key (required)
    slack.username (required)
    slack.as_user (required to see the profile picture of your bot)
    slack.profile (optional)

Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location::

    slack.channel
    slack.api_key
    slack.username
    slack.as_user

Slack settings may also be configured as::

    slack:
        channel: RoomName
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        username: user
        as_user: true

    alternative.slack:
        room_id: RoomName
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        from_name: user@email.com

    slack_profile:
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        from_name: user@email.com

    slack:
        profile: slack_profile
        channel: RoomName

    alternative.slack:
        profile: slack_profile
        channel: RoomName

To use the Slack returner, append '--return slack' to the salt command.

.. code-block:: bash

    salt '*' test.ping --return slack

To use the alternative configuration, append '--return_config alternative' to the salt command.

.. code-block:: bash

    salt '*' test.ping --return slack --return_config alternative
'''
from __future__ import absolute_import

# Import Python libs
import pprint
import logging

# Import 3rd-party libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin  # pylint: disable=import-error,no-name-in-module
import salt.ext.six.moves.http_client
# pylint: enable=import-error,no-name-in-module,redefined-builtin

# Import Salt Libs
import salt.returners

log = logging.getLogger(__name__)

__virtualname__ = 'slack'

def _get_options(ret=None):
    '''
    Get the slack options from salt.
    '''

    defaults = {'channel': '#general'}

    attrs = {'slack_profile': 'profile',
             'channel': 'channel',
             'username': 'username',
             'as_user': 'as_user',
             'api_key': 'api_key',
             }

    profile_attr = 'slack_profile'

    profile_attrs = {'from_jid': 'from_jid',
                     'api_key': 'api_key',
                     'api_version': 'api_key'
                     }

    _options = salt.returners.get_returner_options(__virtualname__,
                                                   ret,
                                                   attrs,
                                                   profile_attr=profile_attr,
                                                   profile_attrs=profile_attrs,
                                                   __salt__=__salt__,
                                                   __opts__=__opts__,
                                                   defaults=defaults)
    return _options

def __virtual__():
    '''
    Return virtual name of the module.

    :return: The virtual name of the module.
    '''
    return __virtualname__

def _query(function, api_key=None, method='GET', data=None):
    '''
    Slack object method function to construct and execute on the API URL.

    :param api_key:     The Slack api key.
    :param function:    The Slack api function to perform.
    :param method:      The HTTP method, e.g. GET or POST.
    :param data:        The data to be sent for POST method.
    :return:            The json response from the API call or False.
    '''
    headers = {}
    query_params = {}

    if data is None:
        data = {}

    ret = {'message': '',
           'res': True}

    slack_functions = {
        'rooms': {
            'request': 'channels.list',
            'response': 'channels',
        },
        'users': {
            'request': 'users.list',
            'response': 'members',
        },
        'message': {
            'request': 'chat.postMessage',
            'response': 'channel',
        },
    }

    if not api_key:
        try:
            options = __salt__['config.option']('slack')
            if not api_key:
                api_key = options.get('api_key')
        except (NameError, KeyError, AttributeError):
            log.error('No Slack api key found.')
            ret['message'] = 'No Slack api key found.'
            ret['res'] = False
            return ret

    api_url = 'https://slack.com'
    base_url = _urljoin(api_url, '/api/')
    path = slack_functions.get(function).get('request')
    url = _urljoin(base_url, path, False)
    query_params['token'] = api_key

    try:
        result = requests.request(
            method=method,
            url=url,
            headers=headers,
            params=query_params,
            data=data,
            verify=True,
        )
    except ConnectionError as e:
        ret['message'] = e
        ret['res'] = False
        return ret

    if result.status_code == salt.ext.six.moves.http_client.OK:
        result = result.json()
        response = slack_functions.get(function).get('response')
        if 'error' in result:
            ret['message'] = result['error']
            ret['res'] = False
            return ret
        ret['message'] = result.get(response)
        return ret
    elif result.status_code == salt.ext.six.moves.http_client.NO_CONTENT:
        return True
    else:
        log.debug(url)
        log.debug(query_params)
        log.debug(data)
        log.debug(result)
        if 'error' in result:
            ret['message'] = result['error']
            ret['res'] = False
            return ret
        ret['message'] = result
        return ret

def _post_message(channel,
                  message,
                  username,
                  as_user,
                  api_key=None):
    '''
    Send a message to a Slack room.
    :param channel:     The room name.
    :param message:     The message to send to the Slack room.
    :param username:    Specify who the message is from.
    :param as_user:     Sets the profile picture which have been added through Slack itself.
    :param api_key:     The Slack api key, if not specified in the configuration.
    :param api_version: The Slack api version, if not specified in the configuration.
    :return:            Boolean if message was sent successfully.
    '''

    parameters = dict()
    parameters['channel'] = channel
    parameters['username'] = username
    parameters['as_user'] = as_user
    parameters['text'] = message

    result = _query(function='message',
                    api_key=api_key,
                    method='POST',
                    data=parameters)

    log.debug('result {0}'.format(result))
    if result:
        return True
    else:
        return False

def returner(ret):
    '''
    Send an slack message with the data
    '''

    _options = _get_options(ret)

    channel = _options.get('channel')
    username = _options.get('username')
    as_user = _options.get('as_user')
    api_key = _options.get('api_key')

    if not channel:
        log.error('slack.channel not defined in salt config')
        return

    if not username:
        log.error('slack.username not defined in salt config')
        return

    if as_user is None:
       log.error('slack.as_user not defined in salt config')
       return

    if not api_key:
        log.error('slack.api_key not defined in salt config')
        return

    message = ('id: {0}\r\n'
               'function: {1}\r\n'
               'function args: {2}\r\n'
               'jid: {3}\r\n'
               'return: {4}\r\n').format(
                    ret.get('id'),
                    ret.get('fun'),
                    ret.get('fun_args'),
                    ret.get('jid'),
                    pprint.pformat(ret.get('return')))

    slack = _post_message(channel,
                          message,
                          username,
                          as_user,
                          api_key)
    return slack
<commit_msg>fix indentation<commit_after># -*- coding: utf-8 -*-
'''
Return salt data via slack

.. versionadded:: 2015.5.0

The following fields can be set in the minion conf file::

    slack.channel (required)
    slack.api_key (required)
    slack.username (required)
    slack.as_user (required to see the profile picture of your bot)
    slack.profile (optional)

Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location::

    slack.channel
    slack.api_key
    slack.username
    slack.as_user

Slack settings may also be configured as::

    slack:
        channel: RoomName
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        username: user
        as_user: true

    alternative.slack:
        room_id: RoomName
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        from_name: user@email.com

    slack_profile:
        api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        from_name: user@email.com

    slack:
        profile: slack_profile
        channel: RoomName

    alternative.slack:
        profile: slack_profile
        channel: RoomName

To use the Slack returner, append '--return slack' to the salt command.

.. code-block:: bash

    salt '*' test.ping --return slack

To use the alternative configuration, append '--return_config alternative' to the salt command.

.. code-block:: bash

    salt '*' test.ping --return slack --return_config alternative
'''
from __future__ import absolute_import

# Import Python libs
import pprint
import logging

# Import 3rd-party libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin  # pylint: disable=import-error,no-name-in-module
import salt.ext.six.moves.http_client
# pylint: enable=import-error,no-name-in-module,redefined-builtin

# Import Salt Libs
import salt.returners

log = logging.getLogger(__name__)

__virtualname__ = 'slack'

def _get_options(ret=None):
    '''
    Get the slack options from salt.
    '''

    defaults = {'channel': '#general'}

    attrs = {'slack_profile': 'profile',
             'channel': 'channel',
             'username': 'username',
             'as_user': 'as_user',
             'api_key': 'api_key',
             }

    profile_attr = 'slack_profile'

    profile_attrs = {'from_jid': 'from_jid',
                     'api_key': 'api_key',
                     'api_version': 'api_key'
                     }

    _options = salt.returners.get_returner_options(__virtualname__,
                                                   ret,
                                                   attrs,
                                                   profile_attr=profile_attr,
                                                   profile_attrs=profile_attrs,
                                                   __salt__=__salt__,
                                                   __opts__=__opts__,
                                                   defaults=defaults)
    return _options

def __virtual__():
    '''
    Return virtual name of the module.

    :return: The virtual name of the module.
    '''
    return __virtualname__

def _query(function, api_key=None, method='GET', data=None):
    '''
    Slack object method function to construct and execute on the API URL.

    :param api_key:     The Slack api key.
    :param function:    The Slack api function to perform.
    :param method:      The HTTP method, e.g. GET or POST.
    :param data:        The data to be sent for POST method.
    :return:            The json response from the API call or False.
    '''
    headers = {}
    query_params = {}

    if data is None:
        data = {}

    ret = {'message': '',
           'res': True}

    slack_functions = {
        'rooms': {
            'request': 'channels.list',
            'response': 'channels',
        },
        'users': {
            'request': 'users.list',
            'response': 'members',
        },
        'message': {
            'request': 'chat.postMessage',
            'response': 'channel',
        },
    }

    if not api_key:
        try:
            options = __salt__['config.option']('slack')
            if not api_key:
                api_key = options.get('api_key')
        except (NameError, KeyError, AttributeError):
            log.error('No Slack api key found.')
            ret['message'] = 'No Slack api key found.'
            ret['res'] = False
            return ret

    api_url = 'https://slack.com'
    base_url = _urljoin(api_url, '/api/')
    path = slack_functions.get(function).get('request')
    url = _urljoin(base_url, path, False)
    query_params['token'] = api_key

    try:
        result = requests.request(
            method=method,
            url=url,
            headers=headers,
            params=query_params,
            data=data,
            verify=True,
        )
    except ConnectionError as e:
        ret['message'] = e
        ret['res'] = False
        return ret

    if result.status_code == salt.ext.six.moves.http_client.OK:
        result = result.json()
        response = slack_functions.get(function).get('response')
        if 'error' in result:
            ret['message'] = result['error']
            ret['res'] = False
            return ret
        ret['message'] = result.get(response)
        return ret
    elif result.status_code == salt.ext.six.moves.http_client.NO_CONTENT:
        return True
    else:
        log.debug(url)
        log.debug(query_params)
        log.debug(data)
        log.debug(result)
        if 'error' in result:
            ret['message'] = result['error']
            ret['res'] = False
            return ret
        ret['message'] = result
        return ret

def _post_message(channel,
                  message,
                  username,
                  as_user,
                  api_key=None):
    '''
    Send a message to a Slack room.
    :param channel:     The room name.
    :param message:     The message to send to the Slack room.
    :param username:    Specify who the message is from.
    :param as_user:     Sets the profile picture which have been added through Slack itself.
    :param api_key:     The Slack api key, if not specified in the configuration.
    :param api_version: The Slack api version, if not specified in the configuration.
    :return:            Boolean if message was sent successfully.
    '''

    parameters = dict()
    parameters['channel'] = channel
    parameters['username'] = username
    parameters['as_user'] = as_user
    parameters['text'] = message

    result = _query(function='message',
                    api_key=api_key,
                    method='POST',
                    data=parameters)

    log.debug('result {0}'.format(result))
    if result:
        return True
    else:
        return False

def returner(ret):
    '''
    Send an slack message with the data
    '''

    _options = _get_options(ret)

    channel = _options.get('channel')
    username = _options.get('username')
    as_user = _options.get('as_user')
    api_key = _options.get('api_key')

    if not channel:
        log.error('slack.channel not defined in salt config')
        return

    if not username:
        log.error('slack.username not defined in salt config')
        return

    if as_user is None:
        log.error('slack.as_user not defined in salt config')
        return

    if not api_key:
        log.error('slack.api_key not defined in salt config')
        return

    message = ('id: {0}\r\n'
               'function: {1}\r\n'
               'function args: {2}\r\n'
               'jid: {3}\r\n'
               'return: {4}\r\n').format(
                    ret.get('id'),
                    ret.get('fun'),
                    ret.get('fun_args'),
                    ret.get('jid'),
                    pprint.pformat(ret.get('return')))

    slack = _post_message(channel,
                          message,
                          username,
                          as_user,
                          api_key)
    return slack
<|endoftext|>


<commit_before>from qpage import *
import sys
def error_handler():
    close_files()
    vector_2 = error_finder()
    error_vector = vector_2[0]
    pass_vector = vector_2[1]
    print(str(len(error_vector)) + " Error")
    print("Please Check Following :\n")
    for i in range(len(error_vector)):
        print(str(i + 1) + "-" + error_vector[i])
    for i in range(len(pass_vector)):
        print(str(i + len(error_vector) + 1) + "-" + pass_vector[i])
    enter_to_exit()
def run_2():
    for i in actual_name:
        html_init(i)  # create pages html files
    menu_writer()  # write menu for each html file
    for i in actual_name:
        contain(i)  # write contains of each page
        html_end(i)  # end tags of each page
    css_creator()  # create css file
    icon_creator()
    robot_maker()
    close_files()
    print("Homepage is ready")
    print("Upload output folder contains directly to your host")
    print("Please Don't Change HTML Files Name")
    address_print()
    print_warning()
    if internet():
        server()
    browse = int(input("Preview Homepage?[1] or Not[2]"))
    if browse == 1:
        preview()
        close_files()
def run(control_flag=True):
    try:
        response = create_folder()
        print("QPAGE By S.Haghighi & M.M.Rahimi")
        print("Version : " + version)
        address_print()
        if control_flag==True:
            version_control()
        if response:
            print(
                "At least one of the folders create for the first time ,\n"
                " please put your data in proper order and run program again\n Program Reboot Automaticly in 3 Sec")
            wait_func(3)
            run(False)
            sys.exit()
        clear_folder(out_dir)  # clear all of files in output directory
        page_name_update()  # update page names
        run_2()
    except FileNotFoundError:  # error exception in FileNotFound ( When Something Missed)
        error_handler()
    except ValueError:
        print("Bad Input")
        enter_to_exit()

if __name__ == "__main__":
    run()

<commit_msg>fix : new response handler function added<commit_after>from qpage import *
import sys
def error_handler():
    close_files()
    vector_2 = error_finder()
    error_vector = vector_2[0]
    pass_vector = vector_2[1]
    print(str(len(error_vector)) + " Error")
    print("Please Check Following :\n")
    for i in range(len(error_vector)):
        print(str(i + 1) + "-" + error_vector[i])
    for i in range(len(pass_vector)):
        print(str(i + len(error_vector) + 1) + "-" + pass_vector[i])
    enter_to_exit()
def run_2():
    for i in actual_name:
        html_init(i)  # create pages html files
    menu_writer()  # write menu for each html file
    for i in actual_name:
        contain(i)  # write contains of each page
        html_end(i)  # end tags of each page
    css_creator()  # create css file
    icon_creator()
    robot_maker()
    close_files()
    print("Homepage is ready")
    print("Upload output folder contains directly to your host")
    print("Please Don't Change HTML Files Name")
    address_print()
    print_warning()
    if internet():
        server()
    browse = int(input("Preview Homepage?[1] or Not[2]"))
    if browse == 1:
        preview()
        close_files()
def response_handler(response):
    if response:
        print(
            "At least one of the folders create for the first time ,\n"
            " please put your data in proper order and run program again\n Program Reboot Automaticly in 3 Sec")
        wait_func(3)
        run(False)
        sys.exit()
def run(control_flag=True):
    try:
        response = create_folder()
        print("QPAGE By S.Haghighi & M.M.Rahimi")
        print("Version : " + version)
        address_print()
        if control_flag==True:
            version_control()
        response_handler(response)
        clear_folder(out_dir)  # clear all of files in output directory
        page_name_update()  # update page names
        run_2()
    except FileNotFoundError:  # error exception in FileNotFound ( When Something Missed)
        error_handler()
    except ValueError:
        print("Bad Input")
        enter_to_exit()

if __name__ == "__main__":
    run()

<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
'''
Insert minion return data into a sqlite3 database

:maintainer:    Mickey Malone <mickey.malone@gmail.com>
:maturity:      New
:depends:       None
:platform:      All

Sqlite3 is a serverless database that lives in a single file.
In order to use this returner the database file must exist,
have the appropriate schema defined, and be accessible to the
user whom the minion process is running as. This returner
requires the following values configured in the master or
minion config::

    returner.sqlite3.database: /usr/lib/salt/salt.db
    returner.sqlite3.timeout: 5.0

Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location::

    alternative.returner.sqlite3.database: /usr/lib/salt/salt.db
    alternative.returner.sqlite3.timeout: 5.0

Use the commands to create the sqlite3 database and tables::

    sqlite3 /usr/lib/salt/salt.db << EOF
    --
    -- Table structure for table 'jids'
    --

    CREATE TABLE jids (
      jid TEXT PRIMARY KEY,
      load TEXT NOT NULL
      );

    --
    -- Table structure for table 'salt_returns'
    --

    CREATE TABLE salt_returns (
      fun TEXT KEY,
      jid TEXT KEY,
      id TEXT KEY,
      fun_args TEXT,
      date TEXT NOT NULL,
      full_ret TEXT NOT NULL,
      success TEXT NOT NULL
      );
    EOF

  To use the sqlite returner, append '--return sqlite3' to the salt command. ex:

    salt '*' test.ping --return sqlite3

  To use the alternative configuration, append '--return_config alternative' to the salt command. ex:

    salt '*' test.ping --return sqlite3 --return_config alternative

'''

# Import python libs
import logging
import json
import datetime

# Import Salt libs
import salt.utils
import salt.returners

# Better safe than sorry here. Even though sqlite3 is included in python
try:
    import sqlite3
    HAS_SQLITE3 = True
except ImportError:
    HAS_SQLITE3 = False

log = logging.getLogger(__name__)

# Define the module's virtual name
__virtualname__ = 'sqlite3'

def __virtual__():
    if not HAS_SQLITE3:
        return False
    return __virtualname__

def _get_options(ret=None):
    '''
    Get the SQLite3 options from salt.
    '''
    attrs = {'database': 'database',
             'timeout': 'timeout'}

    _options = salt.returners.get_returner_options(__virtualname__,
                                                   ret,
                                                   attrs,
                                                   __salt__=__salt__,
                                                   __opts__=__opts__)
    return _options

def _get_conn(ret=None):
    '''
    Return a sqlite3 database connection
    '''
    # Possible todo: support detect_types, isolation_level, check_same_thread,
    # factory, cached_statements. Do we really need to though?
    _options = _get_options(ret)
    database = _options.get('database')
    timeout = _options.get('timeout')

    if not database:
        raise Exception(
                'sqlite3 config option "returner.sqlite3.database" is missing')
    if not timeout:
        raise Exception(
                'sqlite3 config option "returner.sqlite3.timeout" is missing')
    log.debug('Connecting the sqlite3 database: {0} timeout: {1}'.format(
              database,
              timeout))
    conn = sqlite3.connect(database, timeout=float(timeout))
    return conn

def _close_conn(conn):
    '''
    Close the sqlite3 database connection
    '''
    log.debug('Closing the sqlite3 database connection')
    conn.commit()
    conn.close()

def returner(ret):
    '''
    Insert minion return data into the sqlite3 database
    '''
    log.debug('sqlite3 returner <returner> called with data: {0}'.format(ret))
    conn = _get_conn(ret)
    cur = conn.cursor()
    sql = '''INSERT INTO salt_returns
             (fun, jid, id, fun_args, date, full_ret, success)
             VALUES (:fun, :jid, :id, :fun_args, :date, :full_ret, :success)'''
    cur.execute(sql,
                {'fun': ret['fun'],
                 'jid': ret['jid'],
                 'id': ret['id'],
                 'fun_args': str(ret['fun_args']) if ret['fun_args'] else None,
                 'date': str(datetime.datetime.now()),
                 'full_ret': json.dumps(ret['return']),
                 'success': ret['success']})
    _close_conn(conn)

def save_load(jid, load):
    '''
    Save the load to the specified jid
    '''
    log.debug('sqlite3 returner <save_load> called jid:{0} load:{1}'
              .format(jid, load))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''INSERT INTO jids (jid, load) VALUES (:jid, :load)'''
    cur.execute(sql,
                {'jid': jid,
                 'load': json.dumps(load)})
    _close_conn(conn)

def get_load(jid):
    '''
    Return the load from a specified jid
    '''
    log.debug('sqlite3 returner <get_load> called jid: {0}'.format(jid))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT load FROM jids WHERE jid = :jid'''
    cur.execute(sql,
                {'jid': jid})
    data = cur.fetchone()
    if data:
        return json.loads(data)
    _close_conn(conn)
    return {}

def get_jid(jid):
    '''
    Return the information returned from a specified jid
    '''
    log.debug('sqlite3 returner <get_jid> called jid: {0}'.format(jid))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT id, full_ret FROM salt_returns WHERE jid = :jid'''
    cur.execute(sql,
                {'jid': jid})
    data = cur.fetchone()
    log.debug('query result: {0}'.format(data))
    ret = {}
    if data and len(data) > 1:
        ret = {str(data[0]): {u'return': json.loads(data[1])}}
        log.debug("ret: {0}".format(ret))
    _close_conn(conn)
    return ret

def get_fun(fun):
    '''
    Return a dict of the last function called for all minions
    '''
    log.debug('sqlite3 returner <get_fun> called fun: {0}'.format(fun))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT s.id, s.full_ret, s.jid
            FROM salt_returns s
            JOIN ( SELECT MAX(jid) AS jid FROM salt_returns GROUP BY fun, id) max
            ON s.jid = max.jid
            WHERE s.fun = :fun
            '''
    cur.execute(sql,
                {'fun': fun})
    data = cur.fetchall()
    ret = {}
    if data:
        # Pop the jid off the list since it is not
        # needed and I am trying to get a perfect
        # pylint score :-)
        data.pop()
        for minion, ret in data:
            ret[minion] = json.loads(ret)
    _close_conn(conn)
    return ret

def get_jids():
    '''
    Return a list of all job ids
    '''
    log.debug('sqlite3 returner <get_fun> called')
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT jid FROM jids'''
    cur.execute(sql)
    data = cur.fetchall()
    ret = []
    for jid in data:
        ret.append(jid[0])
    _close_conn(conn)
    return ret

def get_minions():
    '''
    Return a list of minions
    '''
    log.debug('sqlite3 returner <get_minions> called')
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT DISTINCT id FROM salt_returns'''
    cur.execute(sql)
    data = cur.fetchall()
    ret = []
    for minion in data:
        ret.append(minion[0])
    _close_conn(conn)
    return ret

def prep_jid(nocache, passed_jid=None):  # pylint: disable=unused-argument
    '''
    Do any work necessary to prepare a JID, including sending a custom id
    '''
    return passed_jid if passed_jid is not None else salt.utils.gen_jid()
<commit_msg>Making salt.returners.sqlite3_return python3 compatible<commit_after># -*- coding: utf-8 -*-
'''
Insert minion return data into a sqlite3 database

:maintainer:    Mickey Malone <mickey.malone@gmail.com>
:maturity:      New
:depends:       None
:platform:      All

Sqlite3 is a serverless database that lives in a single file.
In order to use this returner the database file must exist,
have the appropriate schema defined, and be accessible to the
user whom the minion process is running as. This returner
requires the following values configured in the master or
minion config::

    returner.sqlite3.database: /usr/lib/salt/salt.db
    returner.sqlite3.timeout: 5.0

Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location::

    alternative.returner.sqlite3.database: /usr/lib/salt/salt.db
    alternative.returner.sqlite3.timeout: 5.0

Use the commands to create the sqlite3 database and tables::

    sqlite3 /usr/lib/salt/salt.db << EOF
    --
    -- Table structure for table 'jids'
    --

    CREATE TABLE jids (
      jid TEXT PRIMARY KEY,
      load TEXT NOT NULL
      );

    --
    -- Table structure for table 'salt_returns'
    --

    CREATE TABLE salt_returns (
      fun TEXT KEY,
      jid TEXT KEY,
      id TEXT KEY,
      fun_args TEXT,
      date TEXT NOT NULL,
      full_ret TEXT NOT NULL,
      success TEXT NOT NULL
      );
    EOF

  To use the sqlite returner, append '--return sqlite3' to the salt command. ex:

    salt '*' test.ping --return sqlite3

  To use the alternative configuration, append '--return_config alternative' to the salt command. ex:

    salt '*' test.ping --return sqlite3 --return_config alternative

'''
from __future__ import absolute_import

# Import python libs
import logging
import json
import datetime

# Import Salt libs
import salt.utils
import salt.returners

# Better safe than sorry here. Even though sqlite3 is included in python
try:
    import sqlite3
    HAS_SQLITE3 = True
except ImportError:
    HAS_SQLITE3 = False

log = logging.getLogger(__name__)

# Define the module's virtual name
__virtualname__ = 'sqlite3'

def __virtual__():
    if not HAS_SQLITE3:
        return False
    return __virtualname__

def _get_options(ret=None):
    '''
    Get the SQLite3 options from salt.
    '''
    attrs = {'database': 'database',
             'timeout': 'timeout'}

    _options = salt.returners.get_returner_options(__virtualname__,
                                                   ret,
                                                   attrs,
                                                   __salt__=__salt__,
                                                   __opts__=__opts__)
    return _options

def _get_conn(ret=None):
    '''
    Return a sqlite3 database connection
    '''
    # Possible todo: support detect_types, isolation_level, check_same_thread,
    # factory, cached_statements. Do we really need to though?
    _options = _get_options(ret)
    database = _options.get('database')
    timeout = _options.get('timeout')

    if not database:
        raise Exception(
                'sqlite3 config option "returner.sqlite3.database" is missing')
    if not timeout:
        raise Exception(
                'sqlite3 config option "returner.sqlite3.timeout" is missing')
    log.debug('Connecting the sqlite3 database: {0} timeout: {1}'.format(
              database,
              timeout))
    conn = sqlite3.connect(database, timeout=float(timeout))
    return conn

def _close_conn(conn):
    '''
    Close the sqlite3 database connection
    '''
    log.debug('Closing the sqlite3 database connection')
    conn.commit()
    conn.close()

def returner(ret):
    '''
    Insert minion return data into the sqlite3 database
    '''
    log.debug('sqlite3 returner <returner> called with data: {0}'.format(ret))
    conn = _get_conn(ret)
    cur = conn.cursor()
    sql = '''INSERT INTO salt_returns
             (fun, jid, id, fun_args, date, full_ret, success)
             VALUES (:fun, :jid, :id, :fun_args, :date, :full_ret, :success)'''
    cur.execute(sql,
                {'fun': ret['fun'],
                 'jid': ret['jid'],
                 'id': ret['id'],
                 'fun_args': str(ret['fun_args']) if ret['fun_args'] else None,
                 'date': str(datetime.datetime.now()),
                 'full_ret': json.dumps(ret['return']),
                 'success': ret['success']})
    _close_conn(conn)

def save_load(jid, load):
    '''
    Save the load to the specified jid
    '''
    log.debug('sqlite3 returner <save_load> called jid:{0} load:{1}'
              .format(jid, load))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''INSERT INTO jids (jid, load) VALUES (:jid, :load)'''
    cur.execute(sql,
                {'jid': jid,
                 'load': json.dumps(load)})
    _close_conn(conn)

def get_load(jid):
    '''
    Return the load from a specified jid
    '''
    log.debug('sqlite3 returner <get_load> called jid: {0}'.format(jid))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT load FROM jids WHERE jid = :jid'''
    cur.execute(sql,
                {'jid': jid})
    data = cur.fetchone()
    if data:
        return json.loads(data)
    _close_conn(conn)
    return {}

def get_jid(jid):
    '''
    Return the information returned from a specified jid
    '''
    log.debug('sqlite3 returner <get_jid> called jid: {0}'.format(jid))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT id, full_ret FROM salt_returns WHERE jid = :jid'''
    cur.execute(sql,
                {'jid': jid})
    data = cur.fetchone()
    log.debug('query result: {0}'.format(data))
    ret = {}
    if data and len(data) > 1:
        ret = {str(data[0]): {u'return': json.loads(data[1])}}
        log.debug("ret: {0}".format(ret))
    _close_conn(conn)
    return ret

def get_fun(fun):
    '''
    Return a dict of the last function called for all minions
    '''
    log.debug('sqlite3 returner <get_fun> called fun: {0}'.format(fun))
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT s.id, s.full_ret, s.jid
            FROM salt_returns s
            JOIN ( SELECT MAX(jid) AS jid FROM salt_returns GROUP BY fun, id) max
            ON s.jid = max.jid
            WHERE s.fun = :fun
            '''
    cur.execute(sql,
                {'fun': fun})
    data = cur.fetchall()
    ret = {}
    if data:
        # Pop the jid off the list since it is not
        # needed and I am trying to get a perfect
        # pylint score :-)
        data.pop()
        for minion, ret in data:
            ret[minion] = json.loads(ret)
    _close_conn(conn)
    return ret

def get_jids():
    '''
    Return a list of all job ids
    '''
    log.debug('sqlite3 returner <get_fun> called')
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT jid FROM jids'''
    cur.execute(sql)
    data = cur.fetchall()
    ret = []
    for jid in data:
        ret.append(jid[0])
    _close_conn(conn)
    return ret

def get_minions():
    '''
    Return a list of minions
    '''
    log.debug('sqlite3 returner <get_minions> called')
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT DISTINCT id FROM salt_returns'''
    cur.execute(sql)
    data = cur.fetchall()
    ret = []
    for minion in data:
        ret.append(minion[0])
    _close_conn(conn)
    return ret

def prep_jid(nocache, passed_jid=None):  # pylint: disable=unused-argument
    '''
    Do any work necessary to prepare a JID, including sending a custom id
    '''
    return passed_jid if passed_jid is not None else salt.utils.gen_jid()
<|endoftext|>


<commit_before>import os
import json

from twython import Twython
from util import credentials

class Twitter:

    FILE ='tweets.json'

    def authenticate(self, cred_fn):
        creds = credentials(cred_fn=cred_fn)
        self.twitter = Twython(*creds)

    def capture(self, fn=FILE, output=False):
        tweets = self.twitter.search(q='@OKFNAu')
        outfile = open(fn, 'w')

        if output:
            print(json.dumps(tweets, sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            json.dump(tweets, outfile)

    def tweet_text(self, fn=FILE):

        with open(fn) as infile:
            jsono = json.load(infile)

        text = (st['text'] for st in jsono['statuses'] if ['text'] in st)

        outfn = os.path.splitext(fn)[0] + '.txt'
        with open(outfn, 'w') as outfile:
            for t in text:
                print(t, file=outfile)

tw = Twitter()
jsono = tw.tweet_text()

    <commit_msg>minor edits<commit_after>import os
import json

from twython import Twython
from util import credentials

class Twitter:

    FILE ='tweets.json'

    def authenticate(self, cred_fn):
        creds = credentials(cred_fn=cred_fn)
        self.twitter = Twython(*creds)

    def capture(self, outfn=FILE, output=False):
        tweets = self.twitter.search(q='@GreenYes2014')
        outfile = open(outfn, 'w')

        if output:
            print(json.dumps(tweets, sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            json.dump(tweets, outfile)
            print('Capturing tweets in %s' % outfn)

    def tweet_text(self, fn=FILE, dumptofile=True):

        with open(fn) as infile:
            jsono = json.load(infile)

        text = (st['text'] for st in jsono['statuses'])

        if not dumptofile:
            for t in text:
                print(t)
        else:
            outfn = os.path.splitext(fn)[0] + '.txt'
            print('Writing to %s' % outfn)
            with open(outfn, 'w') as outfile:
                for t in text:
                    print(t, file=outfile)

tw = Twitter()
tw.authenticate('creds.json')
tw.capture()
tw.tweet_text(dumptofile=False)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
"""
Rent-A-Bot
----------

Rent-A-Bot, your automation resource provider!

Rent-A-Bot is designed to help you lock your resources in your automation infrastructure.

Setup
`````
.. code:: bash
    $ pip install rent-a-bot
    $ export FLASK_APP=rentabot
    $ export RENTABOT_RESOURCE_DESCRIPTOR=path/to/your/descriptor
    $ flask run

Links
`````
* `website <https://github.com/cpoisson/rent-a-bot>`_

"""

from setuptools import setup, find_packages

from os import path

here = path.abspath(path.dirname(__file__))

setup(

    # Rent-A-Bot Package General Information

    name='rent-a-bot',

    version='0.0.5',

    description='Rent-A-Bot, your automation resource provider.',
    long_description=__doc__,

    url='https://github.com/cpoisson/rent-a-bot',

    author='Charles Poisson',
    author_email='charles.poisson@gmail.com',

    license='MIT',

    # Classifiers => https://pypi.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[
        'Framework :: Flask',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Topic :: Utilities',
        'Operating System :: POSIX :: Linux',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6'
    ],

    keywords='Resource allocation application for automation',

    packages=find_packages(exclude=['tests']),

    # Run time Requirements
    install_requires=['flask',
                      'flask-sqlalchemy',
                      'pyyaml'],

    setup_requires=['pytest-runner'],

    tests_require=['pytest', 'pytest-cov'],

    extras_require={
        'dev': ['pytest', 'pytest-cov'],
        'test': ['pytest', 'pytest-cov'],
    },

    # Include files listed in the MANIFEST.in file of the repository
    include_package_data=True,

)
<commit_msg>Add daiquiri dependency and bump version<commit_after># -*- coding: utf-8 -*-
"""
Rent-A-Bot
----------

Rent-A-Bot, your automation resource provider!

Rent-A-Bot is designed to help you lock your resources in your automation infrastructure.

Setup
`````
.. code:: bash
    $ pip install rent-a-bot
    $ export FLASK_APP=rentabot
    $ export RENTABOT_RESOURCE_DESCRIPTOR=path/to/your/descriptor
    $ flask run

Links
`````
* `website <https://github.com/cpoisson/rent-a-bot>`_

"""

from setuptools import setup, find_packages

from os import path

here = path.abspath(path.dirname(__file__))

setup(

    # Rent-A-Bot Package General Information

    name='rent-a-bot',

    version='0.0.6',

    description='Rent-A-Bot, your automation resource provider.',
    long_description=__doc__,

    url='https://github.com/cpoisson/rent-a-bot',

    author='Charles Poisson',
    author_email='charles.poisson@gmail.com',

    license='MIT',

    # Classifiers => https://pypi.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[
        'Framework :: Flask',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Topic :: Utilities',
        'Operating System :: POSIX :: Linux',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6'
    ],

    keywords='Resource allocation application for automation',

    packages=find_packages(exclude=['tests']),

    # Run time Requirements
    install_requires=['flask',
                      'flask-sqlalchemy',
                      'pyyaml',
                      'daiquiri'],

    setup_requires=['pytest-runner'],

    tests_require=['pytest', 'pytest-cov'],

    extras_require={
        'dev': ['pytest', 'pytest-cov'],
        'test': ['pytest', 'pytest-cov'],
    },

    # Include files listed in the MANIFEST.in file of the repository
    include_package_data=True,

)
<|endoftext|>


<commit_before>import databox
import setuptools

install_requires = []
install_requires.append('requests >= 2.7')

setuptools.setup(
    name=databox.__package_name__,
    version=databox.__version__,
    author=databox.__author__,
    author_email=databox.__author_email__,
    description=databox.__description__,
    url=databox.__url__,
    license='MIT',
    packages=setuptools.find_packages(exclude=('tests',)),
    install_requires=install_requires
)
<commit_msg>Small changes to setup.py<commit_after>import databox
from setuptools import setup, find_packages

install_requires = []
install_requires.append('requests >= 2.7')

setup(
    name=databox.__package_name__,
    version=databox.__version__,
    author=databox.__author__,
    author_email=databox.__author_email__,
    description=databox.__description__,
    url=databox.__url__,
    license='MIT',
    packages=find_packages(exclude=('tests',)),
    install_requires=install_requires
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import os

from setuptools import setup

setup(
    name = 'TracMasterTickets',
    version = '3.0',
    packages = ['mastertickets'],
    package_data = { 'mastertickets': ['templates/*.html', 'htdocs/*.js', 'htdocs/*.css' ] },

    author = 'Noah Kantrowitz',
    author_email = 'noah@coderanger.net',
    description = 'Provides support for ticket dependencies and master tickets.',
    long_description = open(os.path.join(os.path.dirname(__file__), 'README')).read(),
    license = 'BSD',
    keywords = 'trac plugin ticket dependencies master',
    url = 'http://github.com/coderanger/trac-mastertickets',
    classifiers = [
        'Framework :: Trac',
        #'Development Status :: 1 - Planning',
        # 'Development Status :: 2 - Pre-Alpha',
        # 'Development Status :: 3 - Alpha',
        # 'Development Status :: 4 - Beta',
        'Development Status :: 5 - Production/Stable',
        # 'Development Status :: 6 - Mature',
        # 'Development Status :: 7 - Inactive',
        'Environment :: Web Environment',
        'License :: OSI Approved :: BSD License',
        'Natural Language :: English',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],

    install_requires = ['Trac>=0.12'],

    entry_points = {
        'trac.plugins': [
            'mastertickets.web_ui = mastertickets.web_ui',
            'mastertickets.api = mastertickets.api',
        ]
    }
)
<commit_msg>Bump version number for new release.<commit_after>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import os

from setuptools import setup

setup(
    name = 'TracMasterTickets',
    version = '3.0.1',
    packages = ['mastertickets'],
    package_data = { 'mastertickets': ['templates/*.html', 'htdocs/*.js', 'htdocs/*.css' ] },

    author = 'Noah Kantrowitz',
    author_email = 'noah@coderanger.net',
    description = 'Provides support for ticket dependencies and master tickets.',
    long_description = open(os.path.join(os.path.dirname(__file__), 'README')).read(),
    license = 'BSD',
    keywords = 'trac plugin ticket dependencies master',
    url = 'http://github.com/coderanger/trac-mastertickets',
    classifiers = [
        'Framework :: Trac',
        #'Development Status :: 1 - Planning',
        # 'Development Status :: 2 - Pre-Alpha',
        # 'Development Status :: 3 - Alpha',
        # 'Development Status :: 4 - Beta',
        'Development Status :: 5 - Production/Stable',
        # 'Development Status :: 6 - Mature',
        # 'Development Status :: 7 - Inactive',
        'Environment :: Web Environment',
        'License :: OSI Approved :: BSD License',
        'Natural Language :: English',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],

    install_requires = ['Trac>=0.12'],

    entry_points = {
        'trac.plugins': [
            'mastertickets.web_ui = mastertickets.web_ui',
            'mastertickets.api = mastertickets.api',
        ]
    }
)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
from setuptools import setup, find_packages
import io
import os

about = {}
about_filename = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'themis', 'attack', '__about__.py')
with io.open(about_filename, 'rb') as fp:
    exec(fp.read(), about)

setup(
    name='themis.attack',
    version=about['__version__'],
    description='Themis Finals attack helper library',
    author='Alexander Pyatkin',
    author_email='asp@thexyz.net',
    url='https://github.com/aspyatkin/themis-attack-py',
    license='MIT',
    packages=find_packages('.'),
    install_requires=[
        'setuptools',
        'enum34>=1.0'
    ],
    namespace_packages=['themis'],
    entry_points={
        'console_scripts': [
            'themis-attack = themis.attack.main:run',
        ]
    }
)
<commit_msg>Add requirements<commit_after># -*- coding: utf-8 -*-
from setuptools import setup, find_packages
import io
import os

about = {}
about_filename = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'themis', 'attack', '__about__.py')
with io.open(about_filename, 'rb') as fp:
    exec(fp.read(), about)

setup(
    name='themis.attack',
    version=about['__version__'],
    description='Themis Finals attack helper library',
    author='Alexander Pyatkin',
    author_email='asp@thexyz.net',
    url='https://github.com/aspyatkin/themis-attack-py',
    license='MIT',
    packages=find_packages('.'),
    install_requires=[
        'setuptools',
        'enum34>=1.0',
        'requests>=2.7'
    ],
    namespace_packages=['themis'],
    entry_points={
        'console_scripts': [
            'themis-attack = themis.attack.main:run',
        ]
    }
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
from distutils.core import setup

version = "0.2"
author = "Alex Dzul"
author_email = "alexexc2@gmail.com"
mainteiner = "Alex Dzul"
mainteiner_email = "alexexc2@gmail.com"
licence = "MIT License"

setup(name='pyql-weather',
      version=version,
      description='Yahoo Weather in Python',
      long_description=open('README.md').read(),
      license="MIT License",
      author=author,
      author_email=author_email,
      url='http://www.github.com/alexdzul/pyql-weather/',
      packages=['pyql', 'pyql.weather', 'pyql.geo'],
      classifiers=["Development Status :: 4 - Beta",
                   "Environment :: Console",
                   "Intended Audience :: Developers",
                   "License :: OSI Approved :: MIT License",
                   "Natural Language :: English",
                   "Operating System :: OS Independent",
                   "Programming Language :: Python :: 2.7",
                   "Topic :: Software Development",
                   "Topic :: Software Development :: Libraries :: Python Modules",
                   ]
      )<commit_msg>Cambio de versión<commit_after>#!/usr/bin/env python
from distutils.core import setup

version = "0.2"
author = "Alex Dzul"
author_email = "alexexc2@gmail.com"
mainteiner = "Alex Dzul"
mainteiner_email = "alexexc2@gmail.com"
licence = "MIT License"

setup(name='pyql-weather',
      version=version,
      description='Yahoo Weather in Python v.%s' % version,
      long_description=open('README.md').read(),
      license="MIT License",
      author=author,
      author_email=author_email,
      url='http://www.github.com/alexdzul/pyql-weather/',
      packages=['pyql', 'pyql.weather', 'pyql.geo'],
      classifiers=["Development Status :: 4 - Beta",
                   "Environment :: Console",
                   "Intended Audience :: Developers",
                   "License :: OSI Approved :: MIT License",
                   "Natural Language :: English",
                   "Operating System :: OS Independent",
                   "Programming Language :: Python :: 2.7",
                   "Topic :: Software Development",
                   "Topic :: Software Development :: Libraries :: Python Modules",
                   ]
      )<|endoftext|>


<commit_before>import os

from setuptools import setup, find_packages

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name="openbaton-cli",
    version="1.0.2b",
    author="Open Baton",
    author_email="dev@openbaton.org",
    description="The Open Baton CLI",
    license="Apache 2",
    keywords="python vnfm nfvo open baton openbaton sdk cli rest",
    url="http://openbaton.github.io/",
    packages=find_packages(),
    scripts=["openbaton"],
    install_requires=['requests', 'texttable', 'tabulate'],
    long_description=read('README.rst'),
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        'Topic :: Software Development :: Build Tools',
        "Topic :: Utilities",
        "License :: OSI Approved :: Apache Software License",
    ],
    entry_points={
        'console_scripts': [
            'openbaton = org.openbaton.cli.openbaton:start',
        ]
    }
)
<commit_msg>update version<commit_after>import os

from setuptools import setup, find_packages

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name="openbaton-cli",
    version="3.2.1b",
    author="Open Baton",
    author_email="dev@openbaton.org",
    description="The Open Baton CLI",
    license="Apache 2",
    keywords="python vnfm nfvo open baton openbaton sdk cli rest",
    url="http://openbaton.github.io/",
    packages=find_packages(),
    scripts=["openbaton"],
    install_requires=['requests', 'texttable', 'tabulate'],
    long_description=read('README.rst'),
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        'Topic :: Software Development :: Build Tools',
        "Topic :: Utilities",
        "License :: OSI Approved :: Apache Software License",
    ],
    entry_points={
        'console_scripts': [
            'openbaton = org.openbaton.cli.openbaton:start',
        ]
    }
)
<|endoftext|>


<commit_before># Copyright 2014 Baidu, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.

"""
The setup script to install BCE SDK for python
"""
from __future__ import absolute_import
from builtins import str
import sys
try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup
from baidubce import SDK_VERSION

PY3 = sys.version_info[0]==3
if PY3 and isinstance(SDK_VERSION, bytes):
    SDK_VERSION = SDK_VERSION.decode("utf-8")

setup(
    name='bce-python-sdk',
    version=SDK_VERSION,
    install_requires=['pycrypto>=2.4',
                      'future>=0.6.0',
                      'six>=1.4.0'],
    requires=['pycrypto',
              'future',
              'six'],
    packages=['baidubce',
              'baidubce.auth',
              'baidubce.http',
              'baidubce.retry',
              'baidubce.services',
              'baidubce.services.bos',
              'baidubce.services.sts',
              'baidubce.services.bmr',
              'baidubce.services.dumap',
              'baidubce.services.media',
              'baidubce.services.vcr',
              'baidubce.services.vca',
#              'baidubce.services.sms',
              'baidubce.services.cdn',
              'baidubce.services.blb',
              'baidubce.services.eip',
              'baidubce.services.route',
              'baidubce.services.subnet',
              'baidubce.services.vpc'
#              'baidubce.services.cfc',
#              'baidubce.services.infinite',
#              'baidubce.services.tsdb'],
    ],
    url='http://bce.baidu.com',
    license='Apache License 2.0',
    author='',
    author_email='',
    description='BCE SDK for python'
)
<commit_msg>fix conflict<commit_after># Copyright 2014 Baidu, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.

"""
The setup script to install BCE SDK for python
"""
from __future__ import absolute_import
from builtins import str
import sys
try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup
from baidubce import SDK_VERSION

PY3 = sys.version_info[0]==3
if PY3 and isinstance(SDK_VERSION, bytes):
    SDK_VERSION = SDK_VERSION.decode("utf-8")

setup(
    name='bce-python-sdk',
    version=SDK_VERSION,
    install_requires=['pycrypto>=2.4',
                      'future>=0.6.0',
                      'six>=1.4.0'],
    requires=['pycrypto',
              'future',
              'six'],
    packages=['baidubce',
              'baidubce.auth',
              'baidubce.http',
              'baidubce.retry',
              'baidubce.services',
              'baidubce.services.bos',
              'baidubce.services.sts',
              'baidubce.services.bmr',
              'baidubce.services.dumap',
              'baidubce.services.media',
              'baidubce.services.vcr',
              'baidubce.services.vca',
              'baidubce.services.sms',
              'baidubce.services.cdn',
              'baidubce.services.blb',
              'baidubce.services.eip',
              'baidubce.services.route',
              'baidubce.services.subnet',
              'baidubce.services.vpc'
#              'baidubce.services.cfc',
#              'baidubce.services.infinite',
#              'baidubce.services.tsdb'],
    ],
    url='http://bce.baidu.com',
    license='Apache License 2.0',
    author='',
    author_email='',
    description='BCE SDK for python'
)
<|endoftext|>


<commit_before>#!/usr/bin/env python

import os.path
import re
import sys

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist bdist_wheel')
    sys.exit()

def read(filename):
    return open(os.path.join(os.path.dirname(__file__), filename)).read()

description = 'Google Spreadsheets Python API'

long_description = """
{index}

License
-------
MIT

Download
========
"""

long_description = long_description.lstrip("\n").format(index=read('docs/index.txt'))

version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
                    read('gspread/__init__.py'), re.MULTILINE).group(1)

setup(
    name='gspread',
    packages=['gspread', 'gspread.v4'],
    description=description,
    long_description=long_description,
    version=version,
    author='Anton Burnashev',
    author_email='fuss.here@gmail.com',
    url='https://github.com/burnash/gspread',
    keywords=['spreadsheets', 'google-spreadsheets'],
    install_requires=['requests>=2.2.1'],
    classifiers=[
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "Intended Audience :: End Users/Desktop",
        "Intended Audience :: Science/Research",
        "Topic :: Office/Business :: Financial :: Spreadsheet",
        "Topic :: Software Development :: Libraries :: Python Modules"
        ],
    license='MIT'
    )
<commit_msg>Exclude `v4` from setup<commit_after>#!/usr/bin/env python

import os.path
import re
import sys

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist bdist_wheel')
    sys.exit()

def read(filename):
    return open(os.path.join(os.path.dirname(__file__), filename)).read()

description = 'Google Spreadsheets Python API'

long_description = """
{index}

License
-------
MIT

Download
========
"""

long_description = long_description.lstrip("\n").format(index=read('docs/index.txt'))

version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
                    read('gspread/__init__.py'), re.MULTILINE).group(1)

setup(
    name='gspread',
    packages=['gspread'],
    description=description,
    long_description=long_description,
    version=version,
    author='Anton Burnashev',
    author_email='fuss.here@gmail.com',
    url='https://github.com/burnash/gspread',
    keywords=['spreadsheets', 'google-spreadsheets'],
    install_requires=['requests>=2.2.1'],
    classifiers=[
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "Intended Audience :: End Users/Desktop",
        "Intended Audience :: Science/Research",
        "Topic :: Office/Business :: Financial :: Spreadsheet",
        "Topic :: Software Development :: Libraries :: Python Modules"
        ],
    license='MIT'
    )
<|endoftext|>


<commit_before>#!/usr/bin/env python

import setuptools

setuptools.setup(
    name ="basebot",
    version = "1.0.3",
    license = "MIT",

    description = "a base IRC bot extensible with plugins",
    long_description = open("README.rst").read(),

    author = "Anthony Nguyen",
    author_email = "anknguyen@gmail.com",
    url = "https://github.com/clearskies/basebot",

    packages = ["basebot"],

    entry_points = {
        "console_scripts": ["basebot=basebot.bot:main"]
    }
)
<commit_msg>Bumped up version number<commit_after>#!/usr/bin/env python

import setuptools

setuptools.setup(
    name ="basebot",
    version = "1.0.4",
    license = "MIT",

    description = "a base IRC bot extensible with plugins",
    long_description = open("README.rst").read(),

    author = "Anthony Nguyen",
    author_email = "anknguyen@gmail.com",
    url = "https://github.com/clearskies/basebot",

    packages = ["basebot"],

    entry_points = {
        "console_scripts": ["basebot=basebot.bot:main"]
    }
)
<|endoftext|>


<commit_before>from setuptools import setup
from os import path
import io

here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file

def read(*filenames, **kwargs):
    encoding = kwargs.get('encoding', 'utf-8')
    sep = kwargs.get('sep', '\n')
    buf = []
    for filename in filenames:
        with io.open(filename, encoding=encoding) as f:
            buf.append(f.read())
    return sep.join(buf)

long_description = read('README.rst', 'CHANGES.txt')

setup(
    name='harold',
    author='Ilhan Polat',
    author_email='harold.of.python@gmail.com',
    url='https://github.com/ilayn/harold',
    version='1.0.0',
    description='A control systems library for Python3',
    long_description=long_description,
    license='MIT',
    classifiers=[
        'Development Status :: 5 - Stable',
        'Topic :: Software Development :: Build Tools',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Intended Audience :: Science/Research',
        'Intended Audience :: Developers',
        'Topic :: Software Development',
        'Topic :: Scientific/Engineering',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: Unix',
        'Operating System :: MacOS'
    ],
    packages=['harold'],
    package_dir={'harold': 'harold'},
    install_requires=['numpy', 'scipy', 'matplotlib', 'tabulate'],
    setup_requires=['pytest-runner'],
    tests_require=['numpy', 'pytest'],
    keywords='control-theory PID controller design industrial automation',
    extras_require={
        'dev': ['check-manifest'],
        'test': ['coverage'],
    },
)
<commit_msg>MAINT: replace status string<commit_after>from setuptools import setup
from os import path
import io

here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file

def read(*filenames, **kwargs):
    encoding = kwargs.get('encoding', 'utf-8')
    sep = kwargs.get('sep', '\n')
    buf = []
    for filename in filenames:
        with io.open(filename, encoding=encoding) as f:
            buf.append(f.read())
    return sep.join(buf)

long_description = read('README.rst', 'CHANGES.txt')

setup(
    name='harold',
    author='Ilhan Polat',
    author_email='harold.of.python@gmail.com',
    url='https://github.com/ilayn/harold',
    version='1.0.0',
    description='A control systems library for Python3',
    long_description=long_description,
    license='MIT',
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Topic :: Software Development :: Build Tools',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Intended Audience :: Science/Research',
        'Intended Audience :: Developers',
        'Topic :: Software Development',
        'Topic :: Scientific/Engineering',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: Unix',
        'Operating System :: MacOS'
    ],
    packages=['harold'],
    package_dir={'harold': 'harold'},
    install_requires=['numpy', 'scipy', 'matplotlib', 'tabulate'],
    setup_requires=['pytest-runner'],
    tests_require=['numpy', 'pytest'],
    keywords='control-theory PID controller design industrial automation',
    extras_require={
        'dev': ['check-manifest'],
        'test': ['coverage'],
    },
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
The setup script for napalm-logs
'''
import uuid

from setuptools import setup, find_packages
from pip.req import parse_requirements

__author__ = 'Mircea Ulinic <mircea.ulinic@gmail.com>'

install_reqs = parse_requirements('requirements.txt', session=uuid.uuid1())
reqs = [str(ir.req) for ir in install_reqs]

setup(
    name='napalm-logs',
    version='0.1.0',
    packages=find_packages(),
    author='Mircea Ulinic',
    author_email='mircea.ulinic@gmail.com',
    description='Network Automation and Programmability Abstraction Layer with Multivendor support: syslog parser',
    classifiers=[
        'Topic :: Utilities',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Operating System :: POSIX :: Linux',
        'Operating System :: POSIX :: Linux',
        'Operating System :: MacOS',
    ],
    url='https://github.com/napalm-automation/napalm-logs',
    include_package_data=True,
    install_requires=reqs,
    entry_points={
        'console_scripts': [
        ],
    }
)
<commit_msg>Set dev version and link CLI script<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
The setup script for napalm-logs
'''
import uuid

from setuptools import setup, find_packages
from pip.req import parse_requirements

__author__ = 'Mircea Ulinic <mircea.ulinic@gmail.com>'

install_reqs = parse_requirements('requirements.txt', session=uuid.uuid1())
reqs = [str(ir.req) for ir in install_reqs]

setup(
    name='napalm-logs',
    version='0.0.1a0.dev5',
    packages=find_packages(),
    author='Mircea Ulinic',
    author_email='mircea.ulinic@gmail.com',
    description='Network Automation and Programmability Abstraction Layer with Multivendor support: syslog parser',
    classifiers=[
        'Topic :: Utilities',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Operating System :: POSIX :: Linux',
        'Operating System :: POSIX :: Linux',
        'Operating System :: MacOS',
    ],
    url='https://github.com/napalm-automation/napalm-logs',
    include_package_data=True,
    install_requires=reqs,
    entry_points={
        'console_scripts': [
            'napalm-logs=napalm_logs.scripts.napalm_logs'
        ],
    }
)
<|endoftext|>


<commit_before>#! /usr/bin/env python3

import os

try:
    from setuptools import find_packages, setup
except AttributeError:
    from setuptools import find_packages, setup

NAME = 'OASYS1-XOPPY'
VERSION = '1.0.37'
ISRELEASED = False

DESCRIPTION = 'XOPPY: XOP (X-ray oriented programs) in Python'
README_FILE = os.path.join(os.path.dirname(__file__), 'README.txt')
LONG_DESCRIPTION = open(README_FILE).read()
AUTHOR = 'Manuel Sanchez del Rio, Luca Rebuffi, and Bioinformatics Laboratory, FRI UL'
AUTHOR_EMAIL = 'srio@esrf.eu, luca.rebuffi@elettra.eu'
URL = 'https://github.com/srio/Orange-XOPPY'
DOWNLOAD_URL = 'https://github.com/srio/Orange-XOPPY'
LICENSE = 'GPLv3'

KEYWORDS = (
    'X-ray optics',
    'simulator',
    'oasys1',
)

CLASSIFIERS = (
    'Development Status :: 5 - Production/Stable',
    'Environment :: X11 Applications :: Qt',
    'Environment :: Console',
    'Environment :: Plugins',
    'Programming Language :: Python :: 3',
    'Intended Audience :: Science/Research',
)

SETUP_REQUIRES = (
    'setuptools',
)

INSTALL_REQUIRES = (
    'oasys1>=1.1.38',
    'oasys1-srwlib',
    'pySRU',
)

PACKAGES = find_packages(exclude=('*.tests', '*.tests.*', 'tests.*', 'tests'))

PACKAGE_DATA = {
    "orangecontrib.xoppy.widgets.source":["icons/*.png", "icons/*.jpg"],
    "orangecontrib.xoppy.widgets.optics":["icons/*.png", "icons/*.jpg", "misc/*.*"],
}

NAMESPACE_PACAKGES = ["orangecontrib", "orangecontrib.xoppy", "orangecontrib.xoppy.widgets"]

ENTRY_POINTS = {
    'oasys.addons' : ("xoppy = orangecontrib.xoppy", ),
    'oasys.widgets' : (
        "XOPPY Sources = orangecontrib.xoppy.widgets.source",
        "XOPPY Optics = orangecontrib.xoppy.widgets.optics",
    ),
    #'oasys.menus' : ("xoppymenu = orangecontrib.xoppy.menu",)
}

import site, shutil, sys

if __name__ == '__main__':
    is_beta = False

    try:
        import PyMca5, PyQt4

        is_beta = True
    except:
        setup(
              name = NAME,
              version = VERSION,
              description = DESCRIPTION,
              long_description = LONG_DESCRIPTION,
              author = AUTHOR,
              author_email = AUTHOR_EMAIL,
              url = URL,
              download_url = DOWNLOAD_URL,
              license = LICENSE,
              keywords = KEYWORDS,
              classifiers = CLASSIFIERS,
              packages = PACKAGES,
              package_data = PACKAGE_DATA,
              #          py_modules = PY_MODULES,
              setup_requires = SETUP_REQUIRES,
              install_requires = INSTALL_REQUIRES,
              #extras_require = EXTRAS_REQUIRE,
              #dependency_links = DEPENDENCY_LINKS,
              entry_points = ENTRY_POINTS,
              namespace_packages=NAMESPACE_PACAKGES,
              include_package_data = True,
              zip_safe = False,
              )

        if is_beta: raise NotImplementedError("This version of XOPPY doesn't work with Oasys1 beta.\nPlease install OASYS1 final release: http://www.elettra.eu/oasys.html")
<commit_msg>bug fixing<commit_after>#! /usr/bin/env python3

import os

try:
    from setuptools import find_packages, setup
except AttributeError:
    from setuptools import find_packages, setup

NAME = 'OASYS1-XOPPY'
VERSION = '1.0.38'
ISRELEASED = False

DESCRIPTION = 'XOPPY: XOP (X-ray oriented programs) in Python'
README_FILE = os.path.join(os.path.dirname(__file__), 'README.txt')
LONG_DESCRIPTION = open(README_FILE).read()
AUTHOR = 'Manuel Sanchez del Rio, Luca Rebuffi, and Bioinformatics Laboratory, FRI UL'
AUTHOR_EMAIL = 'srio@esrf.eu, luca.rebuffi@elettra.eu'
URL = 'https://github.com/srio/Orange-XOPPY'
DOWNLOAD_URL = 'https://github.com/srio/Orange-XOPPY'
LICENSE = 'GPLv3'

KEYWORDS = (
    'X-ray optics',
    'simulator',
    'oasys1',
)

CLASSIFIERS = (
    'Development Status :: 5 - Production/Stable',
    'Environment :: X11 Applications :: Qt',
    'Environment :: Console',
    'Environment :: Plugins',
    'Programming Language :: Python :: 3',
    'Intended Audience :: Science/Research',
)

SETUP_REQUIRES = (
    'setuptools',
)

INSTALL_REQUIRES = (
    'oasys1>=1.1.41',
    'oasys1-srwlib',
    'pySRU',
)

PACKAGES = find_packages(exclude=('*.tests', '*.tests.*', 'tests.*', 'tests'))

PACKAGE_DATA = {
    "orangecontrib.xoppy.widgets.source":["icons/*.png", "icons/*.jpg"],
    "orangecontrib.xoppy.widgets.optics":["icons/*.png", "icons/*.jpg", "misc/*.*"],
}

NAMESPACE_PACAKGES = ["orangecontrib", "orangecontrib.xoppy", "orangecontrib.xoppy.widgets"]

ENTRY_POINTS = {
    'oasys.addons' : ("xoppy = orangecontrib.xoppy", ),
    'oasys.widgets' : (
        "XOPPY Sources = orangecontrib.xoppy.widgets.source",
        "XOPPY Optics = orangecontrib.xoppy.widgets.optics",
    ),
    #'oasys.menus' : ("xoppymenu = orangecontrib.xoppy.menu",)
}

import site, shutil, sys

if __name__ == '__main__':
    is_beta = False

    try:
        import PyMca5, PyQt4

        is_beta = True
    except:
        setup(
              name = NAME,
              version = VERSION,
              description = DESCRIPTION,
              long_description = LONG_DESCRIPTION,
              author = AUTHOR,
              author_email = AUTHOR_EMAIL,
              url = URL,
              download_url = DOWNLOAD_URL,
              license = LICENSE,
              keywords = KEYWORDS,
              classifiers = CLASSIFIERS,
              packages = PACKAGES,
              package_data = PACKAGE_DATA,
              #          py_modules = PY_MODULES,
              setup_requires = SETUP_REQUIRES,
              install_requires = INSTALL_REQUIRES,
              #extras_require = EXTRAS_REQUIRE,
              #dependency_links = DEPENDENCY_LINKS,
              entry_points = ENTRY_POINTS,
              namespace_packages=NAMESPACE_PACAKGES,
              include_package_data = True,
              zip_safe = False,
              )

        if is_beta: raise NotImplementedError("This version of XOPPY doesn't work with Oasys1 beta.\nPlease install OASYS1 final release: http://www.elettra.eu/oasys.html")
<|endoftext|>


<commit_before>import os
import re
import json
import csv

from parseCsv import parseCsvToken

def indent(definition, baseIndent):
    definition = definition.split('\n')
    for i in xrange(1, len(definition)):
        definition[i] = baseIndent + definition[i]
    definition = '\n'.join(definition)
    return definition

def defaultArgDefinition(key):
    return """updateArgs(args, JSON.parse(JSON.stringify(allArgs.{0})));""".format(key)

class Ecs(object):
    def __init__(self, ecs, inherits, commandHolders):
        self.ecs = ecs
        self.inherits = inherits
        self.commandHolders = commandHolders
    def reduce(self, rawEcs):
        ecs = {}
        commandHolders = {}
        for base in self.inherits:
            base = rawEcs[base]
            if len(base.inherits) > 0:
                return False
            for key, val in base.ecs.iteritems():
                ecs[key] = val
            for group, sdict in base.commandHolders.iteritems():
                if group not in commandHolders:
                    commandHolders[group] = {}
                for key, val in sdict.iteritems():
                    commandHolders[group][key] = val
        self.inherits = []
        for key, val in self.ecs.iteritems():
            ecs[key] = val
        for group, sdict in self.commandHolders.iteritems():
            if group not in commandHolders:
                commandHolders[group] = {}
            for key, val in sdict.iteritems():
                commandHolders[group][key] = val
        self.ecs = ecs
        self.commandHolders = commandHolders
        return True
    def makeFunction(self, ecsKey, baseIndent):
        ecsSet = ',\n'.join('{indent}{0}: {1}'.format(key, val, indent='        ') for key, val in self.ecs.iteritems())

        if 'refer' in self.commandHolders:
            if 'derive' not in self.commandHolders:
                self.commandHolders['derive'] = {}
            for key, val in self.commandHolders['refer'].iteritems():
                self.commandHolders['derive'][key] = 'allArgs[args["{0}"]].{1}'.format(val, key)

        if 'derive' in self.commandHolders:
            deriveText = ''.join('\n{indent}args["{0}"] = {1};'.format(key, val, indent='    ') for key, val in self.commandHolders['derive'].iteritems())
        else:
            deriveText = ''

        if 'default' in self.commandHolders:
            defaultText = ''.join('\n{indent}args["{0}"] = (args["{0}"] === undefined) ? {1} : args["{0}"];'.format(key, val, indent='    ') for key, val in self.commandHolders['default'].iteritems())
        else:
            defaultText = ''

        definition = """function(args){{{0}{1}{2}
    return {{
{ecsSet}
    }};
}}""".format(('\n    ' + defaultArgDefinition(ecsKey)) if self.getArg() else '', deriveText, defaultText, ecsSet=ecsSet)
        return indent(definition, baseIndent)
    def getArg(self):
        return self.commandHolders['arg'] if 'arg' in self.commandHolders else None
    def updateArgs(self, args):
        if not 'arg' in self.commandHolders:
            self.commandHolders['arg'] = args
        else:
            for key, val in args.iteritems():
                self.commandHolders['arg'][key] = val

class ArgWrapperEcs(object):
    def __init__(self, ref, arg):
        self.ref = ref
        self.arg = arg
    def makeFunction(self, ecsKey, baseIndent):
        definition = """function(args){{
    {0}
    return ecs.{1}(args);
}}""".format(defaultArgDefinition(ecsKey), self.ref)
        return indent(definition, baseIndent)
    def getArg(self):
        return self.arg

def makeEcsRef(ref):
    return 'ecs.{0}(args)'.format(ref)

def parseToken(token, key):
    if token == '#':
        return key
    if token[0] == '#':
        return token[1:]
    if token == '()':
        return makeEcsRef(key)
    try:
        return int(token)
    except ValueError:
        pass

    try:
        return float(token)
    except ValueError:
        pass

    if token[0] == '[':
        st = token[1:-1]
        return '[{0}]'.format(', '.join(str(parseToken(s.strip(), key)) for s in st.split(',')))  if st else '[]'

    if token[0] == '?':
        return '(args["{0}"] === undefined) ? {1} : args["{0}"]'.format(key, parseToken(token[1:], key))

    if token[0] == '"':
        return token

    mat = re.match('(.+)\(\)', token)
    if mat:
        return makeEcsRef(mat.group(1))
    else:
        return "args['{0}']".format(token)

def getFilesInEcsFolder(ext):
    for folder, _, files in os.walk('ecs'):
        for fil in files:
            if os.path.splitext(fil)[1] == ext:
                with open(os.path.join(folder, fil)) as f:
                    yield os.path.splitext(fil)[0], f

def compileEcs():
    quotedLines = []
    rawEcs = {}
    for fil, f in getFilesInEcsFolder('.ecs'):
        shouldReset = True
        for lin in f.xreadlines():
            if shouldReset:
                ecs = {}
                isQuoting = False
                inherits = []
                commandHolders = {}
                shouldReset = False

            if lin.strip() == '#':
                isQuoting = not isQuoting
                quotedLines.append('\n')
            elif isQuoting:
                quotedLines.append(lin)
            elif lin[:3] == '---':
                rawEcs[fil] = Ecs(ecs, inherits, commandHolders)
                fil = lin[3:].strip()
                shouldReset = True
            else:
                if not lin.strip():
                    continue
                mat = re.match('!(.+?) (.+)', lin)
                if mat:
                    group = mat.group(1)
                    if group == 'inherit':
                        inherits.append(mat.group(2))
                    else:
                        if group not in ['arg', 'derive', 'default', 'refer']:
                            print 'incorrect instruction', fil
                        mat2 = re.match('(.+?) (.+)', mat.group(2))
                        key = mat2.group(1)
                        val = parseCsvToken(mat2.group(2)) if (group == 'arg') else mat2.group(2)
                        if not group in commandHolders:
                            commandHolders[group] = {}
                        commandHolders[group][key] = val
                else:
                    try:
                        mat = re.match('(\w+): ?(.*)', lin)
                        key, val = mat.groups()
                    except AttributeError:
                        raise AttributeError(lin)
                    val = val if val else key
                    ecs[key] = parseToken(val, key)

        rawEcs[fil] = Ecs(ecs, inherits, commandHolders)

    chk = False
    while not chk:
        chk = True
        for ecs in rawEcs.values():
            chk = ecs.reduce(rawEcs) and chk

    csvIdentifiers = {}
    for fil, f in getFilesInEcsFolder('.csv'):
        csvKeys = []
        for i, row in enumerate(csv.reader(f)):
            if i == 0:
                keys = row
            else:
                tokens = [parseCsvToken(token) for token in row]
                defaultArgs = { key: token for key, token in zip(keys, tokens) if token is not None }
                key = defaultArgs['key']
                template = defaultArgs['template'] if 'template' in defaultArgs else fil
                if key in rawEcs:
                    rawEcs[key].updateArgs(defaultArgs)
                else:
                    rawEcs[key] = ArgWrapperEcs(template, defaultArgs)
                csvKeys.append(key)
        csvIdentifiers[fil] = csvKeys

    parameters = rawEcs['PARAMETERS'].commandHolders['arg']
    del rawEcs['PARAMETERS']

    allArgs = { key: raw.getArg() for key, raw in rawEcs.iteritems() if raw.getArg() }
    allEcs = { key: raw.makeFunction(key, '    ') for key, raw in rawEcs.iteritems() }

    ecsList = ',\n'.join('    {0}: {1}'.format(key, val) for key, val in allEcs.iteritems())

    ecsDefinition = """var PARAMETERS = {parameters};

var allArgs = {allArgs};

var ecs = {{
{ecsList}
}};

{quotedLines}

var csvIdentifiers = {csvIdentifiers}

var findKeyFor = function(csvId, key, val){{
    return _.chain(csvIdentifiers[csvId])
    .filter(function(argKey){{
        return (allArgs[argKey][key] == val);
    }})
    .first()
    .value();
}};

var updateArgs = function(args, defaultArgs){{
    _.each(defaultArgs, function(val, key){{
        if (args[key] !== undefined){{
            console.log('overlapping value ' + key + ' ' + val);
        }}
        args[key] = val;
    }});
}};

var makeEcs = function(key, args){{
    args = (args === undefined) ? {{}} : args;
    if (ecs[key] === undefined){{
        console.log('tried to build ' + key);
    }}
    return ecs[key](args);
}};

var makeAllEcs = function(csvId){{
    return _.map(csvIdentifiers[csvId], function(key){{
        return makeEcs(key, {{}});
    }});
}};
""".format(parameters=json.dumps(parameters, indent=4),
           allArgs=json.dumps(allArgs, indent=4),
           ecsList=ecsList,
           quotedLines=''.join(quotedLines),
           csvIdentifiers=json.dumps(csvIdentifiers, indent=4))
    print ecsDefinition

compileEcs()
<commit_msg>Support for true/false.<commit_after>import os
import re
import json
import csv

from parseCsv import parseCsvToken

def indent(definition, baseIndent):
    definition = definition.split('\n')
    for i in xrange(1, len(definition)):
        definition[i] = baseIndent + definition[i]
    definition = '\n'.join(definition)
    return definition

def defaultArgDefinition(key):
    return """updateArgs(args, JSON.parse(JSON.stringify(allArgs.{0})));""".format(key)

class Ecs(object):
    def __init__(self, ecs, inherits, commandHolders):
        self.ecs = ecs
        self.inherits = inherits
        self.commandHolders = commandHolders
    def reduce(self, rawEcs):
        ecs = {}
        commandHolders = {}
        for base in self.inherits:
            base = rawEcs[base]
            if len(base.inherits) > 0:
                return False
            for key, val in base.ecs.iteritems():
                ecs[key] = val
            for group, sdict in base.commandHolders.iteritems():
                if group not in commandHolders:
                    commandHolders[group] = {}
                for key, val in sdict.iteritems():
                    commandHolders[group][key] = val
        self.inherits = []
        for key, val in self.ecs.iteritems():
            ecs[key] = val
        for group, sdict in self.commandHolders.iteritems():
            if group not in commandHolders:
                commandHolders[group] = {}
            for key, val in sdict.iteritems():
                commandHolders[group][key] = val
        self.ecs = ecs
        self.commandHolders = commandHolders
        return True
    def makeFunction(self, ecsKey, baseIndent):
        ecsSet = ',\n'.join('{indent}{0}: {1}'.format(key, val, indent='        ') for key, val in self.ecs.iteritems())

        if 'refer' in self.commandHolders:
            if 'derive' not in self.commandHolders:
                self.commandHolders['derive'] = {}
            for key, val in self.commandHolders['refer'].iteritems():
                self.commandHolders['derive'][key] = 'allArgs[args["{0}"]].{1}'.format(val, key)

        if 'derive' in self.commandHolders:
            deriveText = ''.join('\n{indent}args["{0}"] = {1};'.format(key, val, indent='    ') for key, val in self.commandHolders['derive'].iteritems())
        else:
            deriveText = ''

        if 'default' in self.commandHolders:
            defaultText = ''.join('\n{indent}args["{0}"] = (args["{0}"] === undefined) ? {1} : args["{0}"];'.format(key, val, indent='    ') for key, val in self.commandHolders['default'].iteritems())
        else:
            defaultText = ''

        definition = """function(args){{{0}{1}{2}
    return {{
{ecsSet}
    }};
}}""".format(('\n    ' + defaultArgDefinition(ecsKey)) if self.getArg() else '', deriveText, defaultText, ecsSet=ecsSet)
        return indent(definition, baseIndent)
    def getArg(self):
        return self.commandHolders['arg'] if 'arg' in self.commandHolders else None
    def updateArgs(self, args):
        if not 'arg' in self.commandHolders:
            self.commandHolders['arg'] = args
        else:
            for key, val in args.iteritems():
                self.commandHolders['arg'][key] = val

class ArgWrapperEcs(object):
    def __init__(self, ref, arg):
        self.ref = ref
        self.arg = arg
    def makeFunction(self, ecsKey, baseIndent):
        definition = """function(args){{
    {0}
    return ecs.{1}(args);
}}""".format(defaultArgDefinition(ecsKey), self.ref)
        return indent(definition, baseIndent)
    def getArg(self):
        return self.arg

def makeEcsRef(ref):
    return 'ecs.{0}(args)'.format(ref)

def parseToken(token, key):
    if token == '#':
        return key
    if token[0] == '#':
        return token[1:]
    if token == '()':
        return makeEcsRef(key)
    if token in ['true', 'false']:
        return token
    try:
        return int(token)
    except ValueError:
        pass

    try:
        return float(token)
    except ValueError:
        pass

    if token[0] == '[':
        st = token[1:-1]
        return '[{0}]'.format(', '.join(str(parseToken(s.strip(), key)) for s in st.split(',')))  if st else '[]'

    if token[0] == '?':
        return '(args["{0}"] === undefined) ? {1} : args["{0}"]'.format(key, parseToken(token[1:], key))

    if token[0] == '"':
        return token

    mat = re.match('(.+)\(\)', token)
    if mat:
        return makeEcsRef(mat.group(1))
    else:
        return "args['{0}']".format(token)

def getFilesInEcsFolder(ext):
    for folder, _, files in os.walk('ecs'):
        for fil in files:
            if os.path.splitext(fil)[1] == ext:
                with open(os.path.join(folder, fil)) as f:
                    yield os.path.splitext(fil)[0], f

def compileEcs():
    quotedLines = []
    rawEcs = {}
    for fil, f in getFilesInEcsFolder('.ecs'):
        shouldReset = True
        for lin in f.xreadlines():
            if shouldReset:
                ecs = {}
                isQuoting = False
                inherits = []
                commandHolders = {}
                shouldReset = False

            if lin.strip() == '#':
                isQuoting = not isQuoting
                quotedLines.append('\n')
            elif isQuoting:
                quotedLines.append(lin)
            elif lin[:3] == '---':
                rawEcs[fil] = Ecs(ecs, inherits, commandHolders)
                fil = lin[3:].strip()
                shouldReset = True
            else:
                if not lin.strip():
                    continue
                mat = re.match('!(.+?) (.+)', lin)
                if mat:
                    group = mat.group(1)
                    if group == 'inherit':
                        inherits.append(mat.group(2))
                    else:
                        if group not in ['arg', 'derive', 'default', 'refer']:
                            print 'incorrect instruction', fil
                        mat2 = re.match('(.+?) (.+)', mat.group(2))
                        key = mat2.group(1)
                        val = parseCsvToken(mat2.group(2)) if (group == 'arg') else mat2.group(2)
                        if not group in commandHolders:
                            commandHolders[group] = {}
                        commandHolders[group][key] = val
                else:
                    try:
                        mat = re.match('(\w+): ?(.*)', lin)
                        key, val = mat.groups()
                    except AttributeError:
                        raise AttributeError(lin)
                    val = val if val else key
                    ecs[key] = parseToken(val, key)

        rawEcs[fil] = Ecs(ecs, inherits, commandHolders)

    chk = False
    while not chk:
        chk = True
        for ecs in rawEcs.values():
            chk = ecs.reduce(rawEcs) and chk

    csvIdentifiers = {}
    for fil, f in getFilesInEcsFolder('.csv'):
        csvKeys = []
        for i, row in enumerate(csv.reader(f)):
            if i == 0:
                keys = row
            else:
                tokens = [parseCsvToken(token) for token in row]
                defaultArgs = { key: token for key, token in zip(keys, tokens) if token is not None }
                key = defaultArgs['key']
                template = defaultArgs['template'] if 'template' in defaultArgs else fil
                if key in rawEcs:
                    rawEcs[key].updateArgs(defaultArgs)
                else:
                    rawEcs[key] = ArgWrapperEcs(template, defaultArgs)
                csvKeys.append(key)
        csvIdentifiers[fil] = csvKeys

    parameters = rawEcs['PARAMETERS'].commandHolders['arg']
    del rawEcs['PARAMETERS']

    allArgs = { key: raw.getArg() for key, raw in rawEcs.iteritems() if raw.getArg() }
    allEcs = { key: raw.makeFunction(key, '    ') for key, raw in rawEcs.iteritems() }

    ecsList = ',\n'.join('    {0}: {1}'.format(key, val) for key, val in allEcs.iteritems())

    ecsDefinition = """var PARAMETERS = {parameters};

var allArgs = {allArgs};

var ecs = {{
{ecsList}
}};

{quotedLines}

var csvIdentifiers = {csvIdentifiers}

var findKeyFor = function(csvId, key, val){{
    return _.chain(csvIdentifiers[csvId])
    .filter(function(argKey){{
        return (allArgs[argKey][key] == val);
    }})
    .first()
    .value();
}};

var updateArgs = function(args, defaultArgs){{
    _.each(defaultArgs, function(val, key){{
        if (args[key] !== undefined){{
            console.log('overlapping value ' + key + ' ' + val);
        }}
        args[key] = val;
    }});
}};

var makeEcs = function(key, args){{
    args = (args === undefined) ? {{}} : args;
    if (ecs[key] === undefined){{
        console.log('tried to build ' + key);
    }}
    return ecs[key](args);
}};

var makeAllEcs = function(csvId){{
    return _.map(csvIdentifiers[csvId], function(key){{
        return makeEcs(key, {{}});
    }});
}};
""".format(parameters=json.dumps(parameters, indent=4),
           allArgs=json.dumps(allArgs, indent=4),
           ecsList=ecsList,
           quotedLines=''.join(quotedLines),
           csvIdentifiers=json.dumps(csvIdentifiers, indent=4))
    print ecsDefinition

compileEcs()
<|endoftext|>


<commit_before># coding=utf-8
import io

from setuptools import setup

try:
    from pypandoc import convert

    def read_md(file_name):
        # http://stackoverflow.com/a/23265673/752142
        return convert(file_name, 'rst')
except ImportError:
    print("warning: pypandoc module not found, could not convert Markdown to RST")

    def read_md(file_name):
        try:
            return io.open(file_name, 'r', encoding='utf-8').read()
        except UnicodeDecodeError:
            return "Encoding problems with README.md"

# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
setup(
    name='django_cbtp_email',
    version='0.1.1',
    description=' Class-based mailer for Django using templates with inlined CSS.',

    # ########################################################################
    #
    # README.rst is generated from README.md:
    #
    # $ pandoc --from=markdown --to=rst README.md -o .tmp/README.rst
    #
    # ~ OR ~
    #
    # $ fab build
    # ########################################################################
    long_description=read_md('README.md'),

    url='https://github.com/illagrenan/django-cbtp-email',
    license='MIT',
    author='Vašek Dohnal',
    author_email='vaclav.dohnal@gmail.com',

    # The exclude makes sure that a top-level tests package doesn’t get
    # installed (it’s still part of the source distribution)
    # since that would wreak havoc.
    # find_packages(exclude=['tests*'])
    packages=['django_cbtp_email'],

    install_requires=['django', 'premailer', 'django-annoying'],
    include_package_data=True,
    classifiers=[
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Framework :: Django',
        'Framework :: Django :: 1.8',
        'Framework :: Django :: 1.10',
        'Framework :: Django :: 1.11',
        'License :: OSI Approved :: MIT License',
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Environment :: Console',
        'Intended Audience :: Developers'
    ],
)
<commit_msg>New release.<commit_after># coding=utf-8
import io

from setuptools import setup

try:
    from pypandoc import convert

    def read_md(file_name):
        # http://stackoverflow.com/a/23265673/752142
        return convert(file_name, 'rst')
except ImportError:
    print("warning: pypandoc module not found, could not convert Markdown to RST")

    def read_md(file_name):
        try:
            return io.open(file_name, 'r', encoding='utf-8').read()
        except UnicodeDecodeError:
            return "Encoding problems with README.md"

# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
setup(
    name='django_cbtp_email',
    version='0.1.2',
    description=' Class-based mailer for Django using templates with inlined CSS.',

    # ########################################################################
    #
    # README.rst is generated from README.md:
    #
    # $ pandoc --from=markdown --to=rst README.md -o .tmp/README.rst
    #
    # ~ OR ~
    #
    # $ fab build
    # ########################################################################
    long_description=read_md('README.md'),

    url='https://github.com/illagrenan/django-cbtp-email',
    license='MIT',
    author='Vašek Dohnal',
    author_email='vaclav.dohnal@gmail.com',

    # The exclude makes sure that a top-level tests package doesn’t get
    # installed (it’s still part of the source distribution)
    # since that would wreak havoc.
    # find_packages(exclude=['tests*'])
    packages=['django_cbtp_email'],

    install_requires=['django', 'premailer', 'django-annoying'],
    include_package_data=True,
    classifiers=[
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Framework :: Django',
        'Framework :: Django :: 1.8',
        'Framework :: Django :: 1.10',
        'Framework :: Django :: 1.11',
        'License :: OSI Approved :: MIT License',
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Environment :: Console',
        'Intended Audience :: Developers'
    ],
)
<|endoftext|>