# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe

def execute():
	frappe.reload_doc("setup", 'doctype', "company")
	frappe.reload_doc("accounts", 'doctype', "account")

	frappe.db.sql("""update tabAccount set account_type='Fixed Asset'
		where account_type='Fixed Asset Account'""")

	for d in (('Asset', 'Debit', 'No'), ('Liability', 'Credit', 'No'), ('Expense', 'Debit', 'Yes'),
			('Income', 'Credit', 'Yes')):
		frappe.db.sql("""update `tabAccount` set root_type = %s
			where debit_or_credit=%s and is_pl_account=%s""", d)

	frappe.db.sql("""update `tabAccount` set balance_must_be=debit_or_credit
		where ifnull(allow_negative_balance, 0) = 0""")

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe

def execute():
	frappe.reload_doc("setup", 'doctype', "company")
	frappe.reload_doc("accounts", 'doctype', "account")

	frappe.db.sql("""update tabAccount set account_type='Fixed Asset'
		where account_type='Fixed Asset Account'""")

	frappe.db.sql("""update `tabAccount` set report_type =
		if(is_pl_account=='Yes', 'Profit and Loss', 'Balance Sheet')""")

	frappe.db.sql("""update `tabAccount` set balance_must_be=debit_or_credit
		where ifnull(allow_negative_balance, 0) = 0""")

Patch to update old accounts property

Patch to update old accounts property


from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [('example', util.download_video())], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(), 'example_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = 'example_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4('example_faces')

    print('Successfully generated example_faces.mp4')

from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

movie_path = util.download_video() if len(sys.argv) <= 1 else sys.argv[1]
print('Detecting faces in movie {}'.format(movie_path))
movie_name = os.path.splitext(os.path.basename(movie_path))[0]

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [(movie_name, movie_path)], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(),
        movie_name + '_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = movie_name + '_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4(movie_name + '_faces')

    print('Successfully generated {:s}_faces.mp4'.format(movie_name))

Update face detect example to take a path argument


from .service import PluginService

__meta__ = {
    "name": "Plugin Manager",
    "class": PluginService,
    "deps": ["messaging", "simpledb", "appmanager"],
    "config": [
        {
            "name": "plugins",
            "loaders": [
                {"type": "env"},
                {"type": "sysvarfile"}
            ]
        }
    ]
}

from .service import PluginService

__meta__ = {
    "name": "Plugin Manager",
    "class": PluginService,
    "deps": ["messaging", "simpledb", "appmanager", "http"],
    "config": [
        {
            "name": "plugins",
            "loaders": [
                {"type": "env"},
                {"type": "sysvarfile"}
            ]
        }
    ]
}

Add http dependency for plugins.

Add http dependency for plugins.


from django.contrib import admin
from friendlyurls.models import *

class UrlMappingAdmin(admin.ModelAdmin):
  list_display = ('friendly_path', 'resolved_url', 'content_type', 'object')
admin.site.register(UrlMapping, UrlMappingAdmin)

from django.contrib import admin
from friendlyurls.models import *

class UrlMappingAdmin(admin.ModelAdmin):
  list_display = ('friendly_path', 'resolved_url', 'content_type', 'object')
  search_fields = ('friendly_path','content_type__name')
admin.site.register(UrlMapping, UrlMappingAdmin)

Allow searching of vanity urls

Allow searching of vanity urls


from rest_framework.views import APIView
from rest_framework import parsers
from rest_framework import renderers
from rest_framework.response import Response
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer

class ObtainAuthToken(APIView):
    throttle_classes = ()
    permission_classes = ()
    parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
    renderer_classes = (renderers.JSONRenderer,)

    def post(self, request):
        serializer = AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        token, created = Token.objects.get_or_create(user=user)
        return Response({'token': token.key})

obtain_auth_token = ObtainAuthToken.as_view()

from rest_framework.views import APIView
from rest_framework import parsers
from rest_framework import renderers
from rest_framework.response import Response
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer

class ObtainAuthToken(APIView):
    throttle_classes = ()
    permission_classes = ()
    parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
    renderer_classes = (renderers.JSONRenderer,)
    serializer_class = AuthTokenSerializer

    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        token, created = Token.objects.get_or_create(user=user)
        return Response({'token': token.key})

obtain_auth_token = ObtainAuthToken.as_view()

Set serializer_class on ObtainAuthToken view


from sqlalchemy import UniqueConstraint
from infosystem.common.subsystem import entity
from infosystem.database import db

class Policy(entity.Entity, db.Model):

    attributes = ['id', 'capability_id', 'role_id', 'bypass']
    domain_id = db.Column(db.CHAR(32), db.ForeignKey("domain.id"), nullable=False)
    capability_id = db.Column(db.CHAR(32), db.ForeignKey("capability.id"), nullable=False)
    role_id = db.Column(db.CHAR(32), db.ForeignKey("role.id"), nullable=True)
    bypass = db.Column(db.Boolean, nullable=False, default=False)
    __table_args__ = (UniqueConstraint('domain_id', 'capability_id', 'role_id', name='policy_uk'),)

    def __init__(self, id, domain_id, capability_id, role_id, bypass):
        super(Policy, self).__init__(id)
        self.domain_id = domain_id
        self.capability_id = capability_id
        self.role_id = role_id
        self.bypass = bypass

from sqlalchemy import UniqueConstraint
from infosystem.common.subsystem import entity
from infosystem.database import db

class Policy(entity.Entity, db.Model):

    attributes = ['id', 'capability_id', 'role_id', 'bypass']
    domain_id = db.Column(db.CHAR(32), db.ForeignKey("domain.id"), nullable=False)
    capability_id = db.Column(db.CHAR(32), db.ForeignKey("capability.id"), nullable=False)
    role_id = db.Column(db.CHAR(32), db.ForeignKey("role.id"), nullable=True)
    bypass = db.Column(db.Boolean, nullable=False, default=False)
    __table_args__ = (UniqueConstraint('domain_id', 'capability_id', 'role_id', name='policy_uk'),)

    def __init__(self, id, domain_id, capability_id, role_id=None, bypass=False):
        super(Policy, self).__init__(id)
        self.domain_id = domain_id
        self.capability_id = capability_id
        self.role_id = role_id
        self.bypass = bypass

Make role_id & bypass opt args in Policy __init__


#!/usr/bin/python2.7

del __builtins__.__dict__['__import__']
del __builtins__.__dict__['reload']

flag = "eval_is_fun"

def main():
    print "Hi, welcome to the flag database. We are under construction right now, so you cannot view the flags, or do anything."
    while True:
        command = raw_input("What would you like to do? ")
        try:
            result = eval(command)
            print "Here is the result of your command: %s" %(result)
        except:
            print "Invalid command, try again"

main()

#!/usr/bin/python2.7

import sys

del __builtins__.__dict__['__import__']
del __builtins__.__dict__['reload']

flag = "eval_is_fun"

class UnbufferedStream(object):
    def __init__(self, stream):
        self.stream = stream
    def write(self, data):
        self.stream.write(data)
        self.stream.flush()
    def __getattr__(self, attr):
        return getattr(self.stream, attr)

sys.stdout = UnbufferedStream(sys.stdout)
def main():
    while True:
        print "Welcome to the flag database! We are currently under construction. Please do not hack the flags."
        try:
            command = str(raw_input("What would you like to do? "))
            result = str(eval(command))
            print "This is the result: %s" %(result)
        except Exception, e:
            print "Invalid command!!!! EXITING!!!!!"
            return

main()

Fix Intro Eval with Unbuffered Streams

Fix Intro Eval with Unbuffered Streams


import urlparse

from django.conf import settings
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site

class Command(BaseCommand):

    def handle(self, *args, **options):
        parsed_url = urlparse.urlparse(settings.SITE_URL)
        Site.objects.all().update(domain=parsed_url.netloc,
                                  name=parsed_url.netloc)
        print "Done!"

import urlparse

from django.conf import settings
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site

from us_ignite.profiles.models import Interest

INTEREST_LIST = (
    ('SDN', 'sdn'),
    ('OpenFlow', 'openflow'),
    ('Ultra fast', 'ultra-fast'),
    ('Advanced wireless', 'advanced-wireless'),
    ('Low-latency', 'low-latency'),
    ('Local cloud/edge computing', 'local-cloud-edge-computing'),
    ('Healthcare', 'healthcare'),
    ('Education & Workforce development', 'education-workforce-development'),
    ('Energy', 'energy'),
    ('Transportation', 'transportation'),
    ('Advanced Manufacturing', 'advanced-manufacturing'),
    ('Public Safety', 'public-safety'),
)

class Command(BaseCommand):

    def handle(self, *args, **options):
        parsed_url = urlparse.urlparse(settings.SITE_URL)
        Site.objects.all().update(domain=parsed_url.netloc,
                                  name=parsed_url.netloc)
        print "Updated site URL."
        for name, slug in INTEREST_LIST:
            interest, is_new = (Interest.objects
                                .get_or_create(name=name, slug=slug))
            if is_new:
                print u'Imported interest: %s' % interest

Add initial data for the ``Interest`` model.


# -*- coding: utf-8 -*-

{
    "name": "Account Credit Transfer",
    "version": "1.0.2",
    "author": "XCG Consulting",
    "website": "http://www.openerp-experts.com",
    "category": 'Accounting',
    "description": """Account Voucher Credit Transfer Payment.
    You need to set up some things before using it.
    A credit transfer config link a bank with a parser
    A credit transfer parser link a parser with a template that you can upload
    """,

    "depends": [
        'base',
        'account_streamline',
    ],

    "data": [
        "security/ir.model.access.csv",
        "views/config.xml",
        "views/parser.xml",
        "views/res.bank.xml",
    ],

    'demo_xml': [],
    'test': [],
    'installable': True,
    'active': False,
    'external_dependencies': {
        'python': ['genshi']
    }
}

# -*- coding: utf-8 -*-

{
    "name": "Account Credit Transfer",
    "version": "1.0.3",
    "author": "XCG Consulting",
    "website": "http://www.openerp-experts.com",
    "category": 'Accounting',
    "description": """Account Voucher Credit Transfer Payment.
    You need to set up some things before using it.
    A credit transfer config link a bank with a parser
    A credit transfer parser link a parser with a template that you can upload
    """,

    "depends": [
        'base',
        'account_streamline',
    ],

    "data": [
        "security/ir.model.access.csv",
        "views/config.xml",
        "views/parser.xml",
        "views/res.bank.xml",
    ],

    'demo_xml': [],
    'test': [],
    'installable': True,
    'active': False,
    'external_dependencies': {
        'python': ['genshi']
    }
}

Change version to 1.0.3 (dev)

Change version to 1.0.3 (dev)


# Copyright 2012 Nebula, Inc.
# Copyright 2013 IBM Corp.
#
#    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.

from nova.tests.functional.api_sample_tests import test_servers

class ServersIpsJsonTest(test_servers.ServersSampleBase):
    sample_dir = 'server-ips'

    def test_get(self):
        # Test getting a server's IP information.
        uuid = self._post_server()
        response = self._do_get('servers/%s/ips' % uuid)
        self._verify_response('server-ips-resp', {}, response, 200)

    def test_get_by_network(self):
        # Test getting a server's IP information by network id.
        uuid = self._post_server()
        response = self._do_get('servers/%s/ips/private' % uuid)
        self._verify_response('server-ips-network-resp', {}, response, 200)

# Copyright 2012 Nebula, Inc.
# Copyright 2013 IBM Corp.
#
#    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.

from nova.tests import fixtures as nova_fixtures
from nova.tests.functional.api_sample_tests import test_servers

class ServersIpsJsonTest(test_servers.ServersSampleBase):
    sample_dir = 'server-ips'

    def test_get(self):
        # Test getting a server's IP information.
        uuid = self._post_server()
        response = self._do_get('servers/%s/ips' % uuid)
        self._verify_response('server-ips-resp', {}, response, 200)

    def test_get_by_network(self):
        # Test getting a server's IP information by network id.
        server_uuid = self._post_server()
        network_label = nova_fixtures.NeutronFixture.network_1['name']
        response = self._do_get('servers/%s/ips/%s' % (
            server_uuid, network_label))
        self._verify_response('server-ips-network-resp', {}, response, 200)

trivial: Make it obvious where we're getting our names from

Change-Id: Ib9aa790c8999e50a2a3587561604ff1e51666f38
Signed-off-by: Stephen Finucane <492121341a95b3c3aab646bed44634f739dd019b@redhat.com>


import sqlite3 as sql
import os
import sys
import logging
import benchmark

#  bmVerify(['final_r7', 'final_r8'], filepath="/home/ysun/disambig/newcode/all/", outdir = "/home/ayu/results_v2/")

# Text Files
txt_file = 'benchmark_errors.txt'
opened_file = open(txt_file, 'U')
log_file = 'benchmark_results.log'

# Logging
logging.basicConfig(filename=log_file, level=logging.DEBUG)
open(log_file, "w")

# Set Up SQL Connections
con = sql.connect('invnum_N_zardoz_with_invpat.sqlite3')

with con:

    con_cur = con.cursor()
    logging.info("Beginning to query database")
    con_cur.execute("CREATE INDEX IF NOT EXISTS index_invnum ON invpat (Invnum)");
    con_cur.execute("CREATE INDEX IF NOT EXISTS index_lastname ON invpat (Lastname)");
    con_cur.execute("CREATE INDEX IF NOT EXISTS index_firstname ON invpat (Firstname)");
    count = 0
    errors = 0
    success = 0

    while True:

        line_read = opened_file.readline()
        # print line_read

        if not line_read:
            print "EXITING"
            break
        count = count + 1
        if count%100 == 0:
            print "starting patent", count

Set up reading lines from file, print count for testing purposes


# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

class Channel(object):
  def __init__(self, name, branch, position, category_postfix, priority):
    self.branch = branch
    self.builder_postfix = '-' + name
    self.category_postfix = category_postfix
    self.name = name
    self.position = position
    self.priority = priority
    self.all_deps_path = '/' + branch + '/deps/all.deps'
    self.standalone_deps_path = '/' + branch + '/deps/standalone.deps'
    self.dartium_deps_path = '/' + branch + '/deps/dartium.deps'

# The channel names are replicated in the slave.cfg files for all
# dart waterfalls. If you change anything here please also change it there.
CHANNELS = [
  Channel('be', 'branches/bleeding_edge', 0, '', 4),
  Channel('dev', 'trunk', 1, '-dev', 2),
  Channel('stable', 'branches/1.9', 2, '-stable', 1),
  Channel('integration', 'branches/dartium_integration', 3, '-integration', 3),
]

CHANNELS_BY_NAME = {}
for c in CHANNELS:
  CHANNELS_BY_NAME[c.name] = c

# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

class Channel(object):
  def __init__(self, name, branch, position, category_postfix, priority):
    self.branch = branch
    self.builder_postfix = '-' + name
    self.category_postfix = category_postfix
    self.name = name
    self.position = position
    self.priority = priority
    self.all_deps_path = '/' + branch + '/deps/all.deps'
    self.standalone_deps_path = '/' + branch + '/deps/standalone.deps'
    self.dartium_deps_path = '/' + branch + '/deps/dartium.deps'

# The channel names are replicated in the slave.cfg files for all
# dart waterfalls. If you change anything here please also change it there.
CHANNELS = [
  Channel('be', 'branches/bleeding_edge', 0, '', 4),
  Channel('dev', 'trunk', 1, '-dev', 2),
  Channel('stable', 'branches/1.10', 2, '-stable', 1),
  Channel('integration', 'branches/dartium_integration', 3, '-integration', 3),
]

CHANNELS_BY_NAME = {}
for c in CHANNELS:
  CHANNELS_BY_NAME[c.name] = c

Make stable builder pull from 1.10

Make stable builder pull from 1.10

R=kasperl@google.com
BUG=

Review URL: https://codereview.chromium.org/1107673002

git-svn-id: 239fca9b83025a0b6f823aeeca02ba5be3d9fd76@294974 0039d316-1c4b-4281-b951-d872f2087c98


import sys
import bsddb3
from xclib.utf8 import utf8, unutf8

def perform(args):
    domain_db = bsddb3.hashopen(args.domain_db, 'c', 0o600)
    if args.get:
        print(unutf8(domain_db[utf8(args.get)]))
    elif args.put:
        domain_db[utf8(args.put[0])] = args.put[1]
    elif args.delete:
        del domain_db[utf8(args.delete)]
    elif args.unload:
        for k in list(domain_db.keys()):
            print('%s\t%s' % (unutf8(k), unutf8(domain_db[k])))
        # Should work according to documentation, but doesn't
        # for k, v in DOMAIN_DB.iteritems():
        #     print k, '\t', v
    elif args.load:
        for line in sys.stdin:
            k, v = line.rstrip('\r\n').split('\t', 1)
            domain_db[utf8(k)] = v
    domain_db.close()

# vim: tabstop=8 softtabstop=0 expandtab shiftwidth=4

import sys
import bsddb3
from xclib.utf8 import utf8, unutf8

def perform(args):
    domain_db = bsddb3.hashopen(args.domain_db, 'c', 0o600)
    if args.get:
        print(unutf8(domain_db[utf8(args.get)], 'illegal'))
    elif args.put:
        domain_db[utf8(args.put[0])] = args.put[1]
    elif args.delete:
        del domain_db[utf8(args.delete)]
    elif args.unload:
        for k in list(domain_db.keys()):
            print('%s\t%s' % (unutf8(k, 'illegal'), unutf8(domain_db[k], 'illegal')))
        # Should work according to documentation, but doesn't
        # for k, v in DOMAIN_DB.iteritems():
        #     print k, '\t', v
    elif args.load:
        for line in sys.stdin:
            k, v = line.rstrip('\r\n').split('\t', 1)
            domain_db[utf8(k)] = v
    domain_db.close()

# vim: tabstop=8 softtabstop=0 expandtab shiftwidth=4

Allow dumping illegal utf-8 contents

Allow dumping illegal utf-8 contents


#
# 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.
"""
DRAC Driver for remote system management using Dell Remote Access Card.
"""

from oslo.utils import importutils

from ironic.common import exception
from ironic.common.i18n import _
from ironic.drivers import base
from ironic.drivers.modules.drac import management
from ironic.drivers.modules.drac import power
from ironic.drivers.modules import pxe

class PXEDracDriver(base.BaseDriver):
    """Drac driver using PXE for deploy."""

    def __init__(self):
        if not importutils.try_import('pywsman'):
            raise exception.DriverLoadError(
                    driver=self.__class__.__name__,
                    reason=_('Unable to import pywsman library'))

        self.power = power.DracPower()
        self.deploy = pxe.PXEDeploy()
        self.management = management.DracManagement()
        self.vendor = pxe.VendorPassthru()

Add the PXE VendorPassthru interface to PXEDracDriver

Without the PXE VendorPassthru interface to expose the "pass_deploy_info"
method in the vendor_passthru endpoint of the API the DRAC it can't
continue the deployment after the ramdisk is booted.

Closes-Bug: #1379705
Change-Id: I21042cbb95a486742abfcb430471d01cd73b3a4a
(cherry picked from commit 78ec7d5336eb65ff845da7ea9f93d34b402f5a0f)


# -*- coding: utf-8 -*-
#
# 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.

"""
Provides bare images for standalone clusters.
"""

from tests.bare_image_provider import TagBareImageProvider
from tests.product.constants import BASE_IMAGES_TAG
from tests.product.constants import BASE_IMAGE_NAME

class NoHadoopBareImageProvider(TagBareImageProvider):
    def __init__(self):
        super(NoHadoopBareImageProvider, self).__init__(
            BASE_IMAGE_NAME, BASE_IMAGE_NAME,
            BASE_IMAGES_TAG, 'nohadoop')

# -*- coding: utf-8 -*-
#
# 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.

"""
Provides bare images for standalone clusters.
"""

import re

from tests.bare_image_provider import TagBareImageProvider
from tests.product.constants import BASE_IMAGES_TAG
from tests.product.constants import BASE_IMAGE_NAME

class NoHadoopBareImageProvider(TagBareImageProvider):
    def __init__(self):
        # encode base image name into name of created test image, to prevent image name clash.
        decoration = 'nohadoop_' + re.sub(r"[^A-Za-z0-9]", "_", BASE_IMAGE_NAME)
        super(NoHadoopBareImageProvider, self).__init__(
            BASE_IMAGE_NAME, BASE_IMAGE_NAME,
            BASE_IMAGES_TAG, decoration)

Use bare image name dependent on base image name


"""Asynchronous Slack API integration."""

import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())

__author__ = 'Jonathan Sharpe'
__version__ = '0.8.3'

"""Asynchronous Slack API integration."""

import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())

__author__ = 'Jonathan Sharpe'
__version__ = '0.8.4'

Bump version for Sphinx update

Bump version for Sphinx update


from readKanjiFile import *

def main():
    testDict = readKanjiFile('kanjiTestFile.txt')

    print('There are {} entries in this dictionary.'.format(len(testDict)))
    for entry in list(testDict.items())[0:15]:
        print(entry)

if __name__ == '__main__':
    main()

from readKanjiFile import *

def main():
    testDict = readKanjiFile('kanjiTestFile.txt')

    print('There are {} entries in this dictionary.'.format(len(testDict)))
    for entry in list(testDict.items()):
        print(entry)

if __name__ == '__main__':
    main()

Test now prints out all kanji

Test now prints out all kanji


from sixquiprend.sixquiprend import app, db

class ChosenCard(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete="CASCADE"))
    game_id = db.Column(db.Integer, db.ForeignKey('game.id', ondelete="CASCADE"))
    card_id = db.Column(db.Integer, db.ForeignKey('card.id'))

    ################################################################################
    ## Serializer
    ################################################################################

    def serialize(self):
        from sixquiprend.models.card import Card
        return {
                'id': self.id,
                'user_id': self.user_id,
                'game_id': self.game_id,
                'card': Card.find(self.card_id)
                }

from sixquiprend.sixquiprend import app, db
from sixquiprend.models.card import Card

class ChosenCard(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete="CASCADE"))
    game_id = db.Column(db.Integer, db.ForeignKey('game.id', ondelete="CASCADE"))
    card_id = db.Column(db.Integer, db.ForeignKey('card.id'))

    ################################################################################
    ## Serializer
    ################################################################################

    def serialize(self):
        return {
                'id': self.id,
                'user_id': self.user_id,
                'game_id': self.game_id,
                'card': Card.find(self.card_id)
                }

Move an import to top

Move an import to top


from .base import *

DEBUG = False
ALLOWED_HOSTS = ['selling-online-overseas.export.great.gov.uk']
ADMINS = (('David Downes', 'david@downes.co.uk'),)

MIDDLEWARE_CLASSES += [
    'core.middleware.IpRestrictionMiddleware',
]

INSTALLED_APPS += [
    'raven.contrib.django.raven_compat'
]

RAVEN_CONFIG = {
    'dsn': os.environ.get('SENTRY_DSN'),
}

ip_check = os.environ.get('RESTRICT_IPS', False)
RESTRICT_IPS = ip_check == 'True' or ip_check == '1'

ALLOWED_IPS = []
ALLOWED_IP_RANGES = ['165.225.80.0/22', '193.240.203.32/29']

SECURE_SSL_REDIRECT = True
# XXX: This needs to be made longer once it is confirmed it works as desired
SECURE_HSTS_SECONDS = 31536000

from .base import *

DEBUG = False
ALLOWED_HOSTS = ['selling-online-overseas.export.great.gov.uk']
ADMINS = (('David Downes', 'david@downes.co.uk'),)

MIDDLEWARE_CLASSES += [
    'core.middleware.IpRestrictionMiddleware',
]

INSTALLED_APPS += [
    'raven.contrib.django.raven_compat'
]

RAVEN_CONFIG = {
    'dsn': os.environ.get('SENTRY_DSN'),
}

ip_check = os.environ.get('RESTRICT_IPS', False)
RESTRICT_IPS = ip_check == 'True' or ip_check == '1'

ALLOWED_IPS = []
ALLOWED_IP_RANGES = ['165.225.80.0/22', '193.240.203.32/29']

SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

Set the secure flag for both our cookies


def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration

    config = Configuration('interfaces', parent_package, top_path)

    config.add_data_dir('tests')
    config.add_data_dir('data')
    config.add_data_dir('script_templates')

    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup
    setup(**configuration(top_path='').todict())

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration

    config = Configuration('interfaces', parent_package, top_path)

    config.add_data_dir('tests')
    config.add_data_dir('script_templates')

    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup
    setup(**configuration(top_path='').todict())

Remove reference to non-existing data directory.

git-svn-id: 24f545668198cdd163a527378499f2123e59bf9f@513 ead46cd0-7350-4e37-8683-fc4c6f79bf00


"""
Teardown the CloudBolt resources (container_orchestrator, environment)
associated with this Kubernetes cluster.
"""
from common.methods import set_progress
from containerorchestrators.kuberneteshandler.models import Kubernetes

def run(job, *args, **kwargs):
    resource = job.resource_set.first()

    container_orchestrator = Kubernetes.objects.get(id=resource.container_orchestrator_id)
    environment = container_orchestrator.environment_set.first()

    container_orchestrator.delete()
    environment.delete()

"""
Teardown the CloudBolt resources (container_orchestrator, environment)
associated with this Kubernetes cluster.
"""
from common.methods import set_progress
from containerorchestrators.kuberneteshandler.models import Kubernetes
from utilities.run_command import execute_command

def run(job, *args, **kwargs):
    resource = job.resource_set.first()

    container_orchestrator = Kubernetes.objects.get(id=resource.container_orchestrator_id)
    environment = container_orchestrator.environment_set.first()

    container_orchestrator.delete()
    environment.delete()

    resource_dir = '/var/opt/cloudbolt/kubernetes/resource-{}'.format(resource_id)
    execute_command('rm -rf {}'.format(RESOURCE_LOCATION))

Remove config files from filesystem on teardown

[DEV-13843]


# -*- coding: utf-8 -*-
"""Command Line Interface."""

import argparse
import sys

def main(argv):
    """Entry point for the pic2map.py script."""
    args = parse_arguments(argv)
    print args

def parse_arguments(argv):
    """Parse command line arguments.

    :returns: Parsed arguments
    :rtype: argparse.Namespace

    """
    parser = argparse.ArgumentParser(
        description='Display pictures location in a map')
    args = parser.parse_args(argv)
    return args

if __name__ == '__main__':
    main(sys.argv[1:])

# -*- coding: utf-8 -*-
"""Command Line Interface."""

import argparse
import logging
import sys

def main(argv):
    """Entry point for the pic2map.py script."""
    args = parse_arguments(argv)
    print args

def configure_logging(log_level):
    """Configure logging based on command line argument.

    :param log_level: Log level passed form the command line
    :type log_level: int

    """
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)

    # Log to sys.stderr using log level
    # passed through command line
    log_handler = logging.StreamHandler()
    formatter = logging.Formatter('%(levelname)s: %(message)s')
    log_handler.setFormatter(formatter)
    log_handler.setLevel(log_level)
    root_logger.addHandler(log_handler)

def parse_arguments(argv):
    """Parse command line arguments.

    :returns: Parsed arguments
    :rtype: argparse.Namespace

    """
    parser = argparse.ArgumentParser(
        description='Display pictures location in a map')
    log_levels = ['debug', 'info', 'warning', 'error', 'critical']
    parser.add_argument(
        '-l', '--log-level',
        dest='log_level',
        choices=log_levels,
        default='warning',
        help=('Log level. One of {0} or {1} '
              '(%(default)s by default)'
              .format(', '.join(log_levels[:-1]), log_levels[-1])))

    args = parser.parse_args(argv)
    args.log_level = getattr(logging, args.log_level.upper())
    return args

if __name__ == '__main__':
    main(sys.argv[1:])

Add command line option to set log level


# coding: utf-8
from os.path import join, dirname, pardir, abspath
from shutil import copy
import subprocess

BOOTSTRAP = abspath(dirname(__file__))
ROOT = abspath(join(BOOTSTRAP, pardir))

# Path where venv will be created. It's imported by bootstrapX.Y.py
VIRTUALENV = abspath(join(BOOTSTRAP, pardir))

ACTIVATE  = join(VIRTUALENV, 'bin', 'activate_this.py')
WITH_VENV = join(BOOTSTRAP, 'with_venv.sh')

def with_venv(*args):
    """
    Runs the given command inside virtualenv.
    """
    cmd = list(args)
    cmd.insert(0, WITH_VENV)
    return subprocess.call(cmd)

def after_install(options, home_dir):
    copy(join(BOOTSTRAP, 'postactivate'), VIRTUALENV)
    with_venv('pip', 'install', '-r', join(ROOT, 'requirements.txt'))
    print "Done! Activate your virtualenv: source bin/activate"

# coding: utf-8
from os.path import join, dirname, pardir, abspath
from shutil import copy
import subprocess

BOOTSTRAP = abspath(dirname(__file__))
ROOT = abspath(join(BOOTSTRAP, pardir))

# Path where venv will be created. It's imported by bootstrapX.Y.py
VIRTUALENV = join(BOOTSTRAP, pardir)
VIRTUALENV_BIN = join(VIRTUALENV, 'bin')

ACTIVATE  = join(VIRTUALENV, 'bin', 'activate_this.py')
WITH_VENV = join(BOOTSTRAP, 'with_venv.sh')

def with_venv(*args):
    """
    Runs the given command inside virtualenv.
    """
    cmd = list(args)
    cmd.insert(0, WITH_VENV)
    return subprocess.call(cmd)

def after_install(options, home_dir):
    copy(join(BOOTSTRAP, 'postactivate'), VIRTUALENV_BIN)
    with_venv('pip', 'install', '-r', join(ROOT, 'requirements.txt'))
    print "Done! Activate your virtualenv: source bin/activate"

Fix wrong destination for postactivate file.


import map
import curses

# Set up Curses screen
screen = curses.initscr()

curses.noecho()
screen.keypad(True)
curses.cbreak()
curses.halfdelay(5)     # Wait for half a second for input before continuing
curses.start_color()

curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)

# Initialize the map
m = map.Map(screen, "data/test_data.txt")

i = 0

while True:
    # Check for exit key
    char = screen.getch()
    if char == ord('q'):
        break

    # Advance the simulation
    m.print_cells(x=10, y=10)
    m.update_cells()

# Clean up
curses.nocbreak()
screen.keypad(False)
curses.echo()

curses.endwin()

import map
import curses

# Set up Curses screen
screen = curses.initscr()

curses.noecho()
screen.keypad(True)
curses.cbreak()
curses.halfdelay(5)     # Wait for half a second for input before continuing
curses.start_color()

curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)

# Initialize the map
m = map.Map(screen, "data/test_data.txt")

while True:
    # Check for exit key
    char = screen.getch()
    if char != -1:
        break

    # Advance the simulation
    m.print_cells(x=10, y=10)
    m.update_cells()

# Clean up
curses.nocbreak()
screen.keypad(False)
curses.echo()

curses.endwin()

Make program close on any keypress

Make program close on any keypress


# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from telemetry import test
from telemetry.page import page_measurement

class PicaMeasurement(page_measurement.PageMeasurement):
  def MeasurePage(self, _, tab, results):
    result = int(tab.EvaluateJavaScript('__pica_load_time'))
    results.Add('Total', 'ms', result)

class Pica(test.Test):
  test = PicaMeasurement
  page_set = 'page_sets/pica.json'

# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from telemetry import test
from telemetry.page import page_measurement

class PicaMeasurement(page_measurement.PageMeasurement):
  def CustomizeBrowserOptions(self, options):
    # Needed for native custom elements (document.register)
    options.AppendExtraBrowserArg('--enable-experimental-web-platform-features')

  def MeasurePage(self, _, tab, results):
    result = int(tab.EvaluateJavaScript('__pica_load_time'))
    results.Add('Total', 'ms', result)

class Pica(test.Test):
  test = PicaMeasurement
  page_set = 'page_sets/pica.json'

Enable native custom elements for Pica benchmark

R=tonyg@chromium.org
BUG=245358

Review URL: https://codereview.chromium.org/22884003

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@217042 0039d316-1c4b-4281-b951-d872f2087c98


BROKER_URL = 'amqp://couchbase:couchbase@ci.sc.couchbase.com:5672/broker'
CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_EXCHANGE = 'perf_results'
CELERY_RESULT_PERSISTENT = False

BROKER_URL = 'amqp://couchbase:couchbase@172.23.97.73:5672/broker'
CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_EXCHANGE = 'perf_results'
CELERY_RESULT_PERSISTENT = False

Use broker IP instead of domain name

Use broker IP instead of domain name

Change-Id: Ide27c97a00c18ac62c1a92e2ec51c74c5af4cf30
Reviewed-on: http://review.couchbase.org/81029
Tested-by: Build Bot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Pavel Paulau <dd88eded64e90046a680e3a6c0828ceb8fe8a0e7@gmail.com>


# -*- coding: utf-8 -*-
# Copyright (c) 2013-2014 Simon Jagoe
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the 3-clause BSD license.  See the LICENSE.txt file for details.
from __future__ import absolute_import, unicode_literals

try:
    import coverage
except ImportError:
    coverage = None

from mock import Mock, patch

from ..coverage import Coverage
from ..testing import unittest

@unittest.skipIf(coverage is None, 'Coverage is not installed')
class TestCoverage(unittest.TestCase):

    @patch('coverage.coverage')
    def test_coverage(self, coverage_func):
        coverage_object = Mock()
        coverage_func.return_value = coverage_object
        coverage_object.start = Mock()
        coverage_object.stop = Mock()
        coverage_object.save = Mock()

        cov = Coverage()
        coverage_func.assert_called_once_with()
        cov.setup()
        coverage_object.start.assert_called_once_with()
        self.assertFalse(coverage_object.stop.called)
        self.assertFalse(coverage_object.save.called)
        cov.teardown()
        coverage_object.stop.assert_called_once_with()
        coverage_object.save.assert_called_once_with()

# -*- coding: utf-8 -*-
# Copyright (c) 2013-2014 Simon Jagoe
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the 3-clause BSD license.  See the LICENSE.txt file for details.
from __future__ import absolute_import, unicode_literals

try:
    import coverage
    from ..coverage import Coverage
except ImportError:
    coverage = None
    Coverage = None

from mock import Mock, patch

from ..testing import unittest

@unittest.skipIf(coverage is None, 'Coverage is not installed')
class TestCoverage(unittest.TestCase):

    @patch('coverage.coverage')
    def test_coverage(self, coverage_func):
        coverage_object = Mock()
        coverage_func.return_value = coverage_object
        coverage_object.start = Mock()
        coverage_object.stop = Mock()
        coverage_object.save = Mock()

        cov = Coverage()
        coverage_func.assert_called_once_with()
        cov.setup()
        coverage_object.start.assert_called_once_with()
        self.assertFalse(coverage_object.stop.called)
        self.assertFalse(coverage_object.save.called)
        cov.teardown()
        coverage_object.stop.assert_called_once_with()
        coverage_object.save.assert_called_once_with()

Fix test error when coverage is not installed


import logging

import yaml

l = logging.getLogger(__name__)

def _replace_with_type(type_, replace_type, data):
    if isinstance(data, type_):
        return replace_type(data)
    return data

class Config(dict):

    def __init__(self, items=None):
        if items is not None:
            if hasattr(items, 'items'):
                items = list(items.items())
            for i, (k, v) in enumerate(items):
                items[i] = (k, _replace_with_type(dict, Config, v))
            super().__init__(items)
        else:
            super().__init__()

    def __getattr__(self, key):
        if key in self:
            return self[key]
        else:
            l.warn("AttrDict: did not find key '{}' in keys {}", key, self.keys())

            if l.getEffectiveLevel() <= logging.INFO:
                import inspect
                stack = inspect.stack(1)[1:]
                l.info("-- AttrDict stack --")
                for info in reversed(stack):
                    l.info('  File "{0[1]}", line {0[2]}, in {0[3]} -- {1}',
                           info, info[4][-1].strip())
                l.info("-- AttrDict stack -- end")

            return Config()  # return empty 'dict' as default

def read_file(filename):
    l.debug("reading config file: '{}'", filename)
    with open(filename) as f:
        config = Config(yaml.safe_load(f))
    l.debug("config: {!s}", config)
    return config

import logging

import yaml

l = logging.getLogger(__name__)

def _replace_with_type(type_, replace_type, data):
    if isinstance(data, type_):
        return replace_type(data)
    return data

class Config(dict):

    def __init__(self, items=None):
        if items is not None:
            if hasattr(items, 'items'):
                items = list(items.items())
            for i, (k, v) in enumerate(items):
                items[i] = (k, _replace_with_type(dict, self.__class__, v))
            super().__init__(items)
        else:
            super().__init__()

    def __getattr__(self, key):
        if key in self:
            return self[key]
        else:
            l.warn("AttrDict: did not find key '{}' in {}", key, self.keys())

            if l.getEffectiveLevel() <= logging.INFO:
                import inspect
                stack = inspect.stack(1)[1:]
                l.info("-- AttrDict stack --")
                for info in reversed(stack):
                    l.info('  File "{0[1]}", line {0[2]}, in {0[3]} -- {1}',
                           info, info[4][-1].strip())
                l.info("-- AttrDict stack -- end")

            return self.__class__()  # return empty 'Config' as default

def read_file(filename):
    l.debug("reading config file: '{}'", filename)
    with open(filename) as f:
        config = Config(yaml.safe_load(f))
    l.debug("config: {!s}", config)
    return config

Use dynamic self.__class__ and not name directly


from pyramid.response import Response
from pi_director.models.models import (
    DBSession,
    MyModel,
    )
from pi_director.models.UserModel import UserModel

def authorize_user(email):
    user=DBSession.query(UserModel).filter(UserModel.email==email).one()
    user.AccessLevel=2
    DBSession.flush()

def delete_user(email):
    DBSession.query(UserModel).filter(UserModel.email==email).delete()

def get_users():
    UserList=DBSession.query(UserModel).all()
    return UserList

def make_an_admin(request):
    email=request.matchdict['email']

    '''First, make sure there aren't already admins in the system'''
    res=DBSession.query(UserModel).filter(UserModel.AccessLevel==2).first()
    if res != None:
        msg="User already an admin: {user}".format(user=res.email)
        return False
    user=DBSession.query(UserModel).filter(UserModel.email==email).first()
    user.AccessLevel=2
    DBSession.flush()
    return True

from pyramid.response import Response
from pi_director.models.models import (
    DBSession,
    MyModel,
    )
from pi_director.models.UserModel import UserModel

def authorize_user(email):
    user=DBSession.query(UserModel).filter(UserModel.email==email).one()
    user.AccessLevel=2
    DBSession.flush()

def delete_user(email):
    DBSession.query(UserModel).filter(UserModel.email==email).delete()

def get_users():
    UserList=DBSession.query(UserModel).all()
    return UserList

def make_an_admin(request):
    email=request.matchdict['email']

    '''First, make sure there aren't already admins in the system'''
    res=DBSession.query(UserModel).filter(UserModel.AccessLevel==2).first()
    if res != None:
        msg="User already an admin: {user}".format(user=res.email)
        return False
    user=DBSession.query(UserModel).filter(UserModel.email==email).first()
    if user == None:
        user=UserModel()
        user.email=email
        DBSession.add(user)
    user.AccessLevel=2
    DBSession.flush()
    return True

Create the user if it isn't already in the database first, then make it an admin.


from conans import ConanFile, CMake

class SocketwConan(ConanFile):
    name = "SocketW"
    version = "3.10.36"
    license = "GNU Lesser General Public License v2.1"
    url = "https://github.com/RigsOfRods/socketw/issues"
    description = "SocketW is a library which provides cross-platform socket abstraction"
    settings = "os", "compiler", "build_type", "arch"
    #options = {"shared": [True, False]}
    #default_options = "shared=False"
    generators = "cmake"
    exports_sources = "src/*", "CMakeLists.txt", "LICENSE", "README"

    def requirements(self):
        self.requires.add('OpenSSL/1.0.2@conan/stable')

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["SocketW"]

from conans import ConanFile, CMake

class SocketwConan(ConanFile):
    name = "SocketW"
    version = "3.10.36"
    license = "GNU Lesser General Public License v2.1"
    url = "https://github.com/RigsOfRods/socketw/issues"
    description = "SocketW is a library which provides cross-platform socket abstraction"
    settings = "os", "compiler", "build_type", "arch"
    #options = {"shared": [True, False]}
    #default_options = "shared=False"
    generators = "cmake"
    exports_sources = "src/*", "CMakeLists.txt", "LICENSE", "README"

    def requirements(self):
        self.requires.add('OpenSSL/1.0.2@conan/stable')

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = tools.collect_libs(self)

Use collect_libs for finding libs

Use collect_libs for finding libs


# -*- coding: utf-8 -*-

from django_jinja.base import Library
import jinja2

register = Library()

@register.filter
@jinja2.contextfilter
def datetimeformat(ctx, value, format='%H:%M / %d-%m-%Y'):
    return value.strftime(format)

@register.global_function
def hello(name):
    return "Hello" + name

# -*- coding: utf-8 -*-

from django_jinja.library import Library
import jinja2

register = Library()

@register.filter
@jinja2.contextfilter
def datetimeformat(ctx, value, format='%H:%M / %d-%m-%Y'):
    return value.strftime(format)

@register.global_function
def hello(name):
    return "Hello" + name

Adjust the example_projects to work

Adjust the example_projects to work


import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()

class Restaurant(Base):

    __tablename__ = 'restaurant'

    name = Column(String(80), nullable = False)
    id = Column(Integer, primary_key = True)

    @property
    def serialize(self):
        return {
            'name': self.name,
            'id': self.id,
        }

class MenuItem(Base):

    __tablename__ = 'menu_item'

    name = Column(String(80), nullable = False)
    id = Column(Integer,primary_key = True)
    course = Column(String(250))
    description = Column(String(250))
    price = Column(String(8))
    restaurant_id = Column(Integer, ForeignKey('restaurant.id'))
    restaurant = relationship(Restaurant)

    @property
    def serialize(self):
        return {
            'name': self.name,
            'description': self.description,
            'id': self.id,
            'price': self.price,
            'course': self.course,
        }

engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.create_all(engine)

import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()

class Restaurant(Base):

    __tablename__ = 'restaurant'

    name = Column(String(80), nullable = False)
    description = Column(String(250))
    id = Column(Integer, primary_key = True)

    @property
    def serialize(self):
        return {
            'name': self.name,
            'description': self.description,
            'id': self.id,
        }

class MenuItem(Base):

    __tablename__ = 'menu_item'

    name = Column(String(80), nullable = False)
    id = Column(Integer,primary_key = True)
    course = Column(String(250))
    description = Column(String(250))
    price = Column(String(8))
    restaurant_id = Column(Integer, ForeignKey('restaurant.id'))
    restaurant = relationship(Restaurant)

    @property
    def serialize(self):
        return {
            'name': self.name,
            'description': self.description,
            'id': self.id,
            'price': self.price,
            'course': self.course,
        }

engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.create_all(engine)

Add description column to Restaurant

feat: Add description column to Restaurant


# -*- coding: utf-8 -*-

# libgreader
# Copyright (C) 2012  Matt Behrens <askedrelic@gmail.com>
# Python library for the Google Reader API

__author__  = "Matt Behrens <askedrelic@gmail.com>"
__version__ = "0.8.0"
__copyright__ = "Copyright (C) 2012  Matt Behrens"

from .googlereader import GoogleReader
from .auth import AuthenticationMethod, ClientAuthMethod, OAuthMethod, OAuth2Method
from .items import *
from .url import ReaderUrl

# -*- coding: utf-8 -*-

# libgreader
# Copyright (C) 2012  Matt Behrens <askedrelic@gmail.com>
# Python library for the Google Reader API

__author__  = "Matt Behrens <askedrelic@gmail.com>"
__version__ = "0.8.0"
__copyright__ = "Copyright (C) 2012  Matt Behrens"

try:
    import requests
except ImportError:
    # Will occur during setup.py install
    pass
else:
    from .googlereader import GoogleReader
    from .auth import AuthenticationMethod, ClientAuthMethod, OAuthMethod, OAuth2Method
    from .items import *
    from .url import ReaderUrl

Fix import error during setup.py install


from django.apps import AppConfig

#from .binding.base import BindingMetaclass
from .package_checks import check_all

class ChannelsConfig(AppConfig):

    name = "channels"
    verbose_name = "Channels"

    def ready(self):
        # Check versions
        check_all()
        # Do django monkeypatches
        from .hacks import monkeypatch_django
        monkeypatch_django()
        # Instantiate bindings
        #BindingMetaclass.register_all()

from django.apps import AppConfig

# We import this here to ensure the reactor is installed very early on
# in case other packages accidentally import twisted.internet.reactor
# (e.g. raven does this).
import daphne.server  # noqa

#from .binding.base import BindingMetaclass
from .package_checks import check_all

class ChannelsConfig(AppConfig):

    name = "channels"
    verbose_name = "Channels"

    def ready(self):
        # Check versions
        check_all()
        # Do django monkeypatches
        from .hacks import monkeypatch_django
        monkeypatch_django()
        # Instantiate bindings
        #BindingMetaclass.register_all()

Add early import to fix problems with other packages and Twisted.


# -*- coding: utf-8 -*-

import pytest

from cookiecutter import generate
from cookiecutter import exceptions

@pytest.mark.usefixtures('clean_system')
def test_pre_gen_hook(tmpdir):
    context = {
        'cookiecutter': {
            "repo_dir": "foobar",
            "abort_pre_gen": "yes",
            "abort_post_gen": "no"
        }
    }

    with pytest.raises(exceptions.FailedHookException):
        generate.generate_files(
            repo_dir='tests/hooks-abort-render',
            context=context,
            output_dir=str(tmpdir)
        )

    assert not tmpdir.join('foobar').isdir()

@pytest.mark.usefixtures('clean_system')
def test_post_gen_hook(tmpdir):
    context = {
        'cookiecutter': {
            "repo_dir": "foobar",
            "abort_pre_gen": "no",
            "abort_post_gen": "yes"
        }
    }

    with pytest.raises(exceptions.FailedHookException):
        generate.generate_files(
            repo_dir='tests/hooks-abort-render',
            context=context,
            output_dir=str(tmpdir)
        )

    assert not tmpdir.join('foobar').isdir()

Test that an error in post_gen_project aborts generation


from psautohint import autohint
from psautohint import psautohint

baseDir = "tests/data/source-code-pro"
masters = ("Black", "Bold", "ExtraLight", "Light", "Medium", "Regular", "Semibold")

glyphList = None

fonts = []
for master in masters:
    print("Hinting %s" % master)

    path = "%s/%s/font.otf" % (baseDir, master)
    font = autohint.openOpenTypeFile(path, "font.otf", None)
    names = font.getGlyphList()
    info = font.getFontInfo(font.getPSName(), path, False, False, [], [])
    info = info.getFontInfo()

    if glyphList is None:
        glyphList = names
    else:
        assert glyphList == names

    glyphs = []
    for name in names:
        glyph = font.convertToBez(name, False)
        glyphs.append(glyph[0])
    fonts.append(psautohint.autohint(info, glyphs, False, False, False))

glyphs = []
for i in range(len(glyphList)):
    glyphs.append([f[i] for f in fonts])

print("MM Hinting")
glyphs = psautohint.autohintmm(info, glyphs, masters, True)

from psautohint import autohint
from psautohint import psautohint

baseDir = "tests/data/source-code-pro"
masters = ("Black", "Bold", "ExtraLight", "Light", "Medium", "Regular", "Semibold")

glyphList = None

fonts = []
for master in masters:
    print("Hinting %s" % master)

    options = autohint.ACOptions()
    options.quiet = True

    path = "%s/%s/font.ufo" % (baseDir, master)
    font = autohint.openUFOFile(path, "font.ufo", False, options)
    font.useProcessedLayer = False
    names = font.getGlyphList()
    info = font.getFontInfo(font.getPSName(), path, False, False, [], [])
    info = info.getFontInfo()

    if glyphList is None:
        glyphList = names
    else:
        assert glyphList == names

    glyphs = []
    for name in glyphList:
        glyph = font.convertToBez(name, False, True)[0]
        if not glyph:
            glyph = "%%%s\n" % name
        glyphs.append(glyph)
    fonts.append(psautohint.autohint(info, glyphs, False, False, False))

glyphs = []
for i in range(len(glyphList)):
    glyphs.append([f[i] for f in fonts])

print("MM Hinting")
glyphs = psautohint.autohintmm(info, glyphs, masters, True)

Use the UFOs not the OTFs

Use the UFOs not the OTFs

Oops, the OTF are not interpolation compatible due to overlap removal, I
should have use the UFOs all along. Now the script passes without
errors, still need to verify the output.


import argparse
from dataactcore.models.errorInterface import ErrorInterface
from dataactcore.models.jobTrackerInterface import JobTrackerInterface
from dataactcore.models.userInterface import UserInterface
from dataactcore.models.validationInterface import ValidationInterface
from sqlalchemy import MetaData, Table
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql import update

def reset_alembic(alembic_version):

    engine_list = [
        ErrorInterface().engine,
        JobTrackerInterface().engine,
        UserInterface().engine,
        ValidationInterface().engine,
    ]

    for e in engine_list:
        Session = sessionmaker(bind=e)
        session = Session()
        metadata = MetaData(bind=e)
        alembic_table = Table('alembic_version', metadata, autoload=True)
        u = update(alembic_table)
        u = u.values({"version_num": alembic_version})
        session.execute(u)
        session.commit()

parser = argparse.ArgumentParser\
    (description="Reset alembic version tables across broker databases.")
parser.add_argument(
    'version', help="Version to set the Alembic migration tables to.")
v = vars(parser.parse_args())['version']
reset_alembic(v)

import argparse

from sqlalchemy import MetaData, Table
from sqlalchemy.sql import update

from dataactcore.interfaces.db import GlobalDB
from dataactvalidator.app import createApp

def reset_alembic(alembic_version):

    with createApp().app_context():
        db = GlobalDB.db()

        engine = db.engine
        sess = db.session
        metadata = MetaData(bind=engine)
        alembic_table = Table('alembic_version', metadata, autoload=True)
        u = update(alembic_table)
        u = u.values({"version_num": alembic_version})
        sess.execute(u)
        sess.commit()

parser = argparse.ArgumentParser\
    (description="Reset alembic version table.")
parser.add_argument(
    'version', help="Version to set the Alembic migration table to.")
v = vars(parser.parse_args())['version']
reset_alembic(v)

Remove db interfaces from the alembic version reset helper script.

Arguably, this script is no longer especially useful now that we
only have a single database for the broker. That said, removed the
interfaces in case folks are still using it.


from fabric import api as __api

# Setup some default values.
__api.env.deploy_user = 'webapps'

from denim.paths import (cd_deploy, cd_package, deploy_path, package_path)
from denim import (scm, service, system, virtualenv, webserver)
from denim.decorators import deploy_env

@__api.task(name="help")
def show_help():
    """
    Help on common operations.
    """
    from denim.environment import get_environments
    import denim

    print """
Common operations with Denim (%(version)s).

Provision server:
> fab {%(environments)s} init

Deploy (require a source control revision to be supplied. i.e. master):
> fab {%(environments)s} deploy:{revision}

Status of service:
> fab {%(environments)s} service.status

""" % {
        'environments': '|'.join(get_environments()),
        'version': denim.__version__,
    }

@__api.task
def environment():
    """
    Environments defined in fabfile.
    """
    from denim.environment import get_environments
    print 'Environments defined in fab file:'
    print ', '.join(get_environments())

from fabric import api as _api

# Setup some default values.
_api.env.deploy_user = 'webapps'

from denim.paths import (cd_deploy, cd_application, deploy_path, application_path)
from denim import (scm, service, system, virtualenv, webserver)
from denim.decorators import deploy_env

# Pending deprecation
from denim.paths import (cd_package, package_path)

@_api.task(name="help")
def show_help():
    """
    Help on common operations.
    """
    from denim.environment import get_environments
    import denim

    print """
Common operations with Denim (%(version)s).

Provision server:
> fab {%(environments)s} init

Deploy (require a source control revision to be supplied. i.e. master):
> fab {%(environments)s} deploy:{revision}

Status of service:
> fab {%(environments)s} service.status

""" % {
        'environments': '|'.join(get_environments()),
        'version': denim.__version__,
    }

@_api.task
def environments():
    """
    Environments defined in fabfile.
    """
    from denim.environment import get_environments
    print 'Environments defined in fab file:'
    print ', '.join(get_environments())

Break out items pending deprecation, remove double underscores


from major import Major

class Concentration(Major):
	def __init__(self, dept="NONE"):
		super().__init__(dept, path="concentrations/")

if __name__ == '__main__':
	tmp = [
		Concentration(dept="Asian")
	]
	for i in tmp:
		print(i)

from major import Major

class Concentration(Major):
	def __init__(self, dept="NONE"):
		super().__init__(dept, path="concentrations/")

	def getConcentrationRequirement(self, string):
		return self.requirements[string]

if __name__ == '__main__':
	tmp = [
		Concentration(dept="Asian")
	]
	for i in tmp:
		print(i)

Add a getConcentrationRequirement to corrospond to getMajorRequirement


def getContainerDetails(container):
    ip = 'N/A'
    if container.state().network != None and container.state().network.get('eth0') != None:
        if len(container.state().network.get('eth0')['addresses']) > 0:
            ip = container.state().network['eth0']['addresses'][0].get('address', 'N/A')

    return {
        'name': container.name,
        'status': container.status,
        'ip': ip,
        'ephemeral': container.ephemeral,
        'image': ''.join(container.config.get('image.os') + ' ' + container.config.get('image.release') + ' ' + container.config.get('image.architecture')),
        'created_at': container.created_at
    }

def getContainerDetails(container):
    ip = 'N/A'
    if container.state().network != None and container.state().network.get('eth0') != None:
        if len(container.state().network.get('eth0')['addresses']) > 0:
            ip = container.state().network['eth0']['addresses'][0].get('address', 'N/A')

    image = 'N/A'
    if container.config.get('image.os') != None and container.config.get('image.release') != None and container.config.get('image.architecture') != None:
        image = ''.join(container.config.get('image.os') + ' ' + container.config.get('image.release') + ' ' + container.config.get('image.architecture'))

    return {
        'name': container.name,
        'status': container.status,
        'ip': ip,
        'ephemeral': container.ephemeral,
        'image': image,
        'created_at': container.created_at
    }

Fix container list bug when missing image


"""
MemoryDebugger extension

See documentation in docs/topics/extensions.rst
"""

import gc

from scrapy import signals
from scrapy.exceptions import NotConfigured
from scrapy.utils.trackref import live_refs

class MemoryDebugger(object):

    def __init__(self, stats):
        self.stats = stats

    @classmethod
    def from_crawler(cls, crawler):
        if not crawler.settings.getbool('MEMDEBUG_ENABLED'):
            raise NotConfigured
        o = cls(crawler.stats)
        crawler.signals.connect(o.engine_stopped, signals.engine_stopped)
        return o

    def engine_stopped(self):
        gc.collect()
        self.stats.set_value('memdebug/gc_garbage_count', len(gc.garbage))
        for cls, wdict in live_refs.iteritems():
            if not wdict:
                continue
            self.stats.set_value('memdebug/live_refs/%s' % cls.__name__, len(wdict))

"""
MemoryDebugger extension

See documentation in docs/topics/extensions.rst
"""

import gc

from scrapy import signals
from scrapy.exceptions import NotConfigured
from scrapy.utils.trackref import live_refs

class MemoryDebugger(object):

    def __init__(self, stats):
        self.stats = stats

    @classmethod
    def from_crawler(cls, crawler):
        if not crawler.settings.getbool('MEMDEBUG_ENABLED'):
            raise NotConfigured
        o = cls(crawler.stats)
        crawler.signals.connect(o.spider_closed, signal=signals.spider_closed)
        return o

    def spider_closed(self, spider, reason):
        gc.collect()
        self.stats.set_value('memdebug/gc_garbage_count', len(gc.garbage), spider=spider)
        for cls, wdict in live_refs.iteritems():
            if not wdict:
                continue
            self.stats.set_value('memdebug/live_refs/%s' % cls.__name__, len(wdict), spider=spider)

Fix logging of stats collected by MemoryDebugger extension.

Stats are printed on spider_closed event;
engine_stopped signal is called after spider_closed signal,
so stats for MemoryDebugger extension were not printed to user.


# This file is executed via setup.py and imported via __init__.py

__version__ = "0.2.0.dev"
# For Python versioning scheme, see:
# https://www.python.org/dev/peps/pep-0440/#version-scheme

# This file is executed via setup.py and imported via __init__.py

__version__ = "0.2.0"
# For Python versioning scheme, see:
# https://www.python.org/dev/peps/pep-0440/#version-scheme

Bump version number to 0.2.0

Bump version number to 0.2.0


import os

def split_path(path):
    """
    Split a url path into its sub-paths.

    A url's sub-paths consist of all substrings ending in / and starting at
    the start of the url.
    """
    paths = ['/']
    path = path.rstrip('/')

    while path:
        paths.insert(1, path + '/')
        path = os.path.split(path)[0]
        if path == '/':
            break
    return paths

from collections import deque

def split_path(path):
    """
    Split a url path into its sub-paths.

    A url's sub-paths consist of all substrings ending in / and starting at
    the start of the url.

    eg: /path/containing/subpaths/ becomes:

        /
        /path/
        /path/containing/
        /path/containing/subpaths/
    """
    paths = deque()
    path = path or '/'
    while path:
        path = path.rpartition('/')[0]
        paths.appendleft(path + '/')
    return list(paths)

Refactor split_path code for brevity and clarity


from binascii import hexlify
import os

def generate_api_token():
    key = hexlify(os.urandom(30)).decode()
    dashes_key = ""
    for idx, char in enumerate(key):
        if idx % 15 == 0 and idx != len(key)-1:
            dashes_key += "-"
        else:
            dashes_key += char

    final = "uclapi" + dashes_key

    return final

def generate_app_id():
    key = hexlify(os.urandom(5)).decode()
    final = "A" + key

    return final

from binascii import hexlify
from random import choice

import os
import string

def generate_api_token():
    key = hexlify(os.urandom(30)).decode()
    dashes_key = ""
    for idx, char in enumerate(key):
        if idx % 15 == 0 and idx != len(key)-1:
            dashes_key += "-"
        else:
            dashes_key += char

    final = "uclapi" + dashes_key

    return final

def generate_app_id():
    key = hexlify(os.urandom(5)).decode()
    final = "A" + key

    return final

def generate_app_client_id():
    client_id = ''.join(random.choice(string.digits, k=16))
    client_id += "."
    client_id += ''.join(random.choice(string.digits, k=16))

    return client_id

def generate_app_client_secret():
    client_secret = ''.join(random.choice(string.ascii_lowercase + string.digits, k=64))

    return client_secret

Add helpers to the dashboard code to generate OAuth keys


"""
automatically maintains the latest git tag + revision info in a python file

"""

import imp
import os
import subprocess

def get_project_version(version_file):
    version_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), version_file)
    try:
        module = imp.load_source("verfile", version_file)
        file_ver = module.__version__
    except:  # pylint: disable=bare-except
        file_ver = None

    try:
        proc = subprocess.Popen(["git", "describe", "--always"],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout, _ = proc.communicate()
        if stdout:
            git_ver = stdout.splitlines()[0].strip().decode("utf-8")
            if git_ver and ((git_ver != file_ver) or not file_ver):
                open(version_file, "w").write("__version__ = '%s'\n" % git_ver)
                return git_ver
    except OSError:
        pass

    if not file_ver:
        raise Exception("version not available from git or from file %r"
                        % version_file)

    return file_ver

if __name__ == "__main__":
    import sys
    get_project_version(sys.argv[1])

"""
automatically maintains the latest git tag + revision info in a python file

"""

import importlib
import os
import subprocess

def get_project_version(version_file):
    version_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), version_file)
    try:
        module = importlib.load_module(version_file)
        file_ver = module.__version__
    except:  # pylint: disable=bare-except
        file_ver = None

    try:
        proc = subprocess.Popen(["git", "describe", "--always"],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout, _ = proc.communicate()
        if stdout:
            git_ver = stdout.splitlines()[0].strip().decode("utf-8")
            if git_ver and ((git_ver != file_ver) or not file_ver):
                open(version_file, "w").write("__version__ = '%s'\n" % git_ver)
                return git_ver
    except OSError:
        pass

    if not file_ver:
        raise Exception("version not available from git or from file %r"
                        % version_file)

    return file_ver

if __name__ == "__main__":
    import sys
    get_project_version(sys.argv[1])

Migrate from deprecated imp to importlib


import os

import sdv

project = u'stix-validator'
copyright = u'2015, The MITRE Corporation'
version = sdv.__version__
release = version

extensions = [
    'sphinx.ext.autodoc',
    'sphinxcontrib.napoleon',
]

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'

exclude_patterns = ['_build']
pygments_style = 'sphinx'

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if not on_rtd:  # only import and set the theme if we're building docs locally
    import sphinx_rtd_theme
    html_theme = 'sphinx_rtd_theme'
    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
else:
    html_theme = 'default'

html_show_sourcelink = False
htmlhelp_basename = 'stix-validatordoc'

latex_elements = {}
latex_documents = [
  ('index', 'stix-validator.tex', u'stix-validator Documentation',
   u'The MITRE Corporation', 'manual'),
]

import os

import sdv

project = u'stix-validator'
copyright = u'2015, The MITRE Corporation'
version = sdv.__version__
release = version

extensions = [
    'sphinx.ext.autodoc',
    'sphinxcontrib.napoleon',
]

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'

rst_prolog = """
**Version**: {}
""".format(release)

exclude_patterns = ['_build']
pygments_style = 'sphinx'

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if not on_rtd:  # only import and set the theme if we're building docs locally
    import sphinx_rtd_theme
    html_theme = 'sphinx_rtd_theme'
    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
else:
    html_theme = 'default'

html_show_sourcelink = False
htmlhelp_basename = 'stix-validatordoc'

latex_elements = {}
latex_documents = [
  ('index', 'stix-validator.tex', u'stix-validator Documentation',
   u'The MITRE Corporation', 'manual'),
]

Add package version to rst_prolog.

Add package version to rst_prolog.


import ConfigParser
import json
import os
import unittest

from webserver import Httpd
from network import get_lan_ip

from selenium import webdriver

class WebDriverBaseTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = create_driver()

        cls.webserver = Httpd(host=get_lan_ip())
        cls.webserver.start()

    @classmethod
    def tearDownClass(cls):
        cls.webserver.stop()
        if cls.driver:
            cls.driver.quit()

def create_driver():
    capabilities = {
        'xwalkOptions': {
            'androidPackage': 'org.xwalk.xwalkdrivertest',
            'androidActivity': '.XwalkDriverTestActivity',
        }
    }
    return webdriver.Remote('http://localhost:9515', capabilities)

import ConfigParser
import json
import os
import unittest

from webserver import Httpd
from network import get_lan_ip

from selenium import webdriver

class WebDriverBaseTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = create_driver()

        cls.webserver = Httpd(host=get_lan_ip())
        cls.webserver.start()

    @classmethod
    def tearDownClass(cls):
        cls.webserver.stop()
        if cls.driver:
            cls.driver.quit()

def create_driver():
    capabilities = {
        'xwalkOptions': {
            'androidPackage': 'org.xwalk.xwalkdrivertest',
            'androidActivity': '.XwalkdrivertestActivity',
        }
    }
    return webdriver.Remote('http://localhost:9515', capabilities)

[xwalkdriver] Update activity name for crosswalk android package rule changed


#!/usr/bin/env python
# -*- coding: utf-8 -*
import json
from django import forms
from django.template.loader import render_to_string

from .models import Field, Option, FieldOption

class JSONField(forms.TextInput):
    model = Field
    def render(self, name, value, attrs=None):
        elements = []
        values = json.loads(value)
        objs = self.model.objects.all()
        for obj in objs:
            o = {}
            o['name'] = obj.name
            o['slug'] = obj.slug

            element_attr = {}
            element_attr['name'] = obj.name
            element_attr['slug'] = obj.slug
            """
            element_attr['value'] = '1'
            element_attr['obj_value'] = values.get(obj.slug, '')
            """

            if obj.type in ["checkbox", "radiobox"]:
                obj_value = []
                fo = FieldOption.objects.filter(field=obj)
                for i in fo:
                    key = "{}_{}".format(obj.slug, i.option.slug)
                    obj_value.append(values.get(key, ''))
                element_attr['list'] = zip(fo, obj_value)

            o['element'] = render_to_string(
                "admin/opps/fields/json_{}.html".format(obj.type),
                dictionary=element_attr
            )
            elements.append(o)

        return render_to_string(
            "admin/opps/fields/json.html",
            {"elements": elements,
             "name": name,
             "value": value})

#!/usr/bin/env python
# -*- coding: utf-8 -*
import json
from django import forms
from django.template.loader import render_to_string

from .models import Field, FieldOption

class JSONField(forms.TextInput):
    model = Field
    def render(self, name, value, attrs=None):
        elements = []
        try:
            values = json.loads(value)
        except TypeError:
            values = {}
        objs = self.model.objects.filter(
            application__contains=self.attrs.get('_model', None))
        for obj in objs:
            o = {}
            o['name'] = obj.name
            o['slug'] = obj.slug

            element_attr = {}
            element_attr['name'] = obj.name
            element_attr['slug'] = obj.slug
            """
            element_attr['value'] = '1'
            element_attr['obj_value'] = values.get(obj.slug, '')
            """

            if obj.type in ["checkbox", "radiobox"]:
                obj_value = []
                fo = FieldOption.objects.filter(field=obj)
                for i in fo:
                    key = "{}_{}".format(obj.slug, i.option.slug)
                    obj_value.append(values.get(key, ''))
                element_attr['list'] = zip(fo, obj_value)

            o['element'] = render_to_string(
                "admin/opps/fields/json_{}.html".format(obj.type),
                dictionary=element_attr
            )
            elements.append(o)

        return render_to_string(
            "admin/opps/fields/json.html",
            {"elements": elements,
             "name": name,
             "value": value})

Fix bug TypeError, not exist values (json) is dict None


#!/usr/bin/env python
# -*- coding: utf-8 -*-

VERSION = (0, 1, 4)

__version__ = ".".join(map(str, VERSION))
__status__ = "Development"
__description__ = u"Poll App for Opps CMS"

__author__ = u"Bruno Cezar Rocha"
__credits__ = []
__email__ = u"rochacbruno@gmail.com"
__license__ = u"MIT License"
__copyright__ = u"Copyright 2013, YACOWS"

#!/usr/bin/env python
# -*- coding: utf-8 -*-

VERSION = (0, 1, 4)

__version__ = ".".join(map(str, VERSION))
__status__ = "Development"
__description__ = u"Poll App for Opps CMS"

__author__ = u"Bruno Cezar Rocha"
__credits__ = []
__email__ = u"rochacbruno@gmail.com"
__license__ = u"MIT License"
__copyright__ = u"Copyright 2013, Opps Projects"

Fix Copyright application, YACOWS to Opps Projects


from __future__ import absolute_import

from sentry.api.base import DocSection
from sentry.api.bases import GroupEndpoint
from sentry.api.serializers import serialize
from sentry.api.paginator import DateTimePaginator
from sentry.models import Event, Group
from sentry.utils.apidocs import scenario, attach_scenarios

@scenario('ListAvailableSamples')
def list_available_samples_scenario(runner):
    group = Group.objects.filter(project=runner.default_project).first()
    runner.request(
        method='GET',
        path='/issues/%s/events/' % group.id
    )

class GroupEventsEndpoint(GroupEndpoint):
    doc_section = DocSection.EVENTS

    @attach_scenarios([list_available_samples_scenario])
    def get(self, request, group):
        """
        List an Issue's Events
        ``````````````````````

        This endpoint lists an issue's events.

        :pparam string issue_id: the ID of the issue to retrieve.
        :auth: required
        """

        events = Event.objects.filter(
            group=group
        )

        query = request.GET.get('query')
        if query:
            events = events.filter(
                message__iexact=query,
            )

        return self.paginate(
            request=request,
            queryset=events,
            order_by='-datetime',
            on_results=lambda x: serialize(x, request.user),
            paginator_cls=DateTimePaginator,
        )

from __future__ import absolute_import

from sentry.api.base import DocSection
from sentry.api.bases import GroupEndpoint
from sentry.api.serializers import serialize
from sentry.api.paginator import DateTimePaginator
from sentry.models import Event, Group
from sentry.utils.apidocs import scenario, attach_scenarios

@scenario('ListAvailableSamples')
def list_available_samples_scenario(runner):
    group = Group.objects.filter(project=runner.default_project).first()
    runner.request(
        method='GET',
        path='/issues/%s/events/' % group.id
    )

class GroupEventsEndpoint(GroupEndpoint):
    doc_section = DocSection.EVENTS

    @attach_scenarios([list_available_samples_scenario])
    def get(self, request, group):
        """
        List an Issue's Events
        ``````````````````````

        This endpoint lists an issue's events.

        :pparam string issue_id: the ID of the issue to retrieve.
        :auth: required
        """

        events = Event.objects.filter(
            group=group
        )

        query = request.GET.get('query')
        if query:
            events = events.filter(
                message__icontains=query,
            )

        return self.paginate(
            request=request,
            queryset=events,
            order_by='-datetime',
            on_results=lambda x: serialize(x, request.user),
            paginator_cls=DateTimePaginator,
        )

Make event search actually useful

Make event search actually useful


import os
from qtpy.uic import loadUi

def load_ui(ui_filename, baseinstance):
    ui_filename = os.path.split(ui_filename)[-1]

    # directory containing this file
    filename = __file__
    if not os.path.isdir(filename):
        filename = os.path.split(filename)[0]
    # get the location of the designer directory
    # this function assumes that all ui files are there
    filename = os.path.join(filename, '..', '..',  'designer')

    # put together the full path to the ui file
    filename = os.path.join(filename, ui_filename)
    return loadUi(filename, baseinstance=baseinstance)

import os
from qtpy.uic import loadUi

def load_ui(ui_filename, baseinstance):
    cwd = os.getcwd()
    ui_filename = os.path.split(ui_filename)[-1]

    # get the location of the designer directory
    # this function assumes that all ui files are there
    filename = os.path.join(cwd, 'designer', ui_filename)

    return loadUi(filename, baseinstance=baseinstance)

Fix path for designer directory with ui files


# -*- coding: utf-8 -*-

from socketIO_client import SocketIO, LoggingNamespace

def on_bbb_response(*args):
    print('on_bbb_response', args)

def on_chat_message_response(*args):
    print(args)

with SocketIO('http://192.168.0.110', 8080, LoggingNamespace) as socketIO:
    socketIO.emit('hello', {'xxx': 'yyy'}, on_bbb_response)
    # socketIO.wait_for_callbacks(seconds=1)

    socketIO.on('chat message', on_chat_message_response)

print('hello')

# -*- coding: utf-8 -*-

from socketIO_client import SocketIO, LoggingNamespace

def on_bbb_response(*args):
    print('on_bbb_response', args)

def on_chat_message_response(*args):
    print(args)

with SocketIO('http://192.168.0.110', 8080, LoggingNamespace) as socketIO:
    socketIO.emit('hello', {'xxx': 'yyy'}, on_bbb_response)
    # socketIO.wait_for_callbacks(seconds=1)

    socketIO.on('chat_message', on_chat_message_response)

print('hello')

Correct chat message event name

Correct chat message event name


from django.apps import AppConfig

class OstinatoBlogConfig(AppConfig):
    name = 'ostinato.blog'
    label = 'ost_blog'
    verbose_name = 'Ostinato Blog Engine'

from django.apps import AppConfig

class OstinatoBlogConfig(AppConfig):
    name = 'ostinato.blog'
    label = 'ostinato_blog'
    verbose_name = 'Ostinato Blog Engine'

Correct app label of ostinato_blog

Correct app label of ostinato_blog


import logging

from addons.base.models import BaseNodeSettings, BaseStorageAddon

logger = logging.getLogger(__name__)

class NodeSettings(BaseStorageAddon, BaseNodeSettings):
    pass

import logging

from addons.base.models import BaseNodeSettings, BaseStorageAddon

logger = logging.getLogger(__name__)

class NodeSettings(BaseStorageAddon, BaseNodeSettings):
    # Required overrides
    complete = True
    has_auth = True

Add required overrides to osfstorage.NodeSettings


#!/usr/bin/env python

"""
This module contains the Remote extension to :class:`Table <agate.table.Table>`.
"""

import agate
import requests
import six

def from_url(cls, url, callback=agate.Table.from_csv, binary=False, **kwargs):
    """
    Download a remote file and pass it to a :class:`.Table` parser.

    :param url:
        URL to a file to load.
    :param callback:
        The method to invoke to create the table. Typically either
        :meth:`agate.Table.from_csv` or :meth:`agate.Table.from_json`, but
        it could also be a method provided by an extension.
    :param binary:
        If :code:`False` the downloaded data will be processed as a string,
        otherwise it will be treated as binary data. (e.g. for Excel files)
    """
    r = requests.get(url)

    if binary:
        content = six.BytesIO(r.content)
    else:
        if six.PY2:
            content = six.StringIO(r.content.decode('utf-8'))
        else:
            content = six.StringIO(r.text)

    return callback(content, **kwargs)

agate.Table.from_url = classmethod(from_url)

#!/usr/bin/env python

"""
This module contains the Remote extension to :class:`Table <agate.table.Table>`.
"""

import agate
import requests
import six

def from_url(cls, url, callback=agate.Table.from_csv, requests_encoding=None, binary=False, **kwargs):
    """
    Download a remote file and pass it to a :class:`.Table` parser.

    :param url:
        URL to a file to load.
    :param callback:
        The method to invoke to create the table. Typically either
        :meth:`agate.Table.from_csv` or :meth:`agate.Table.from_json`, but
        it could also be a method provided by an extension.
    :param requests_encoding:
        An encoding to pass to requests for use when decoding the response
        content. (e.g. force use of 'utf-8-sig' when CSV has a BOM).
    :param binary:
        If :code:`False` the downloaded data will be processed as a string,
        otherwise it will be treated as binary data. (e.g. for Excel files)
    """
    r = requests.get(url)

    if requests_encoding:
        r.encoding = requests_encoding

    if binary:
        content = six.BytesIO(r.content)
    else:
        if six.PY2:
            content = six.StringIO(r.content.decode('utf-8'))
        else:
            content = six.StringIO(r.text)

    return callback(content, **kwargs)

agate.Table.from_url = classmethod(from_url)

Add 'requests_encoding' parameter Allows user to override Requests' 'educated guess' about encoding of a response. Useful when loading a remote CSV that has a BOM that has been served with a 'text/csv' content-type, which Requests guesses needs a 'ISO-8859-1' encoding.


from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# Database
engine = create_engine('sqlite:///files/chats.db', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
                                        autoflush=False,
                                        bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
  # import all modules here that might define models so that
  # they will be registered properly on the metadata.  Otherwise
  # you will have to import them first before calling init_db()
  import scraper.models
  Base.metadata.create_all(bind=engine)

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.pool import StaticPool

# Database
engine = create_engine('sqlite:///files/chats.db', convert_unicode=True,
                        connect_args= {'check_same_thread': False},
                        poolclass=StaticPool)
db_session = scoped_session(sessionmaker(autocommit=False,
                                        autoflush=False,
                                        bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
  # import all modules here that might define models so that
  # they will be registered properly on the metadata.  Otherwise
  # you will have to import them first before calling init_db()
  import scraper.models
  Base.metadata.create_all(bind=engine)

Allow sharing db connection across threads


import asyncio
import uuid
import json

import requests
from requests.exceptions import HTTPError

from pyeventstore.events import (get_all_events,
                                 start_subscription,
                                 publish_events)
from pyeventstore.stream_page import StreamPage

class Client:

    def __init__(self, host, secure=False, port=2113):
        proto = "https" if secure else "http"
        self.uri_base = '{}://{}:{}'.format(proto, host, port)

    @asyncio.coroutine
    def publish_events(self, stream_name, events):
        uri = self.stream_head_uri(stream_name)
        yield from publish_events(uri, events)

    def stream_head_uri(self, stream_name):
        return '{}/streams/{}'.format(self.uri_base, stream_name)

    @asyncio.coroutine
    def get_all_events(self, stream_name):
        head_uri = self.stream_head_uri(stream_name)
        return (yield from get_all_events(head_uri))

    @asyncio.coroutine
    def subscribe(self, stream_name, interval_seconds=1):
        head_uri = self.stream_head_uri(stream_name)
        return (yield from start_subscription(head_uri, interval_seconds))

    def get_projection(self, projection_name):
        uri = self.uri_base + '/projection/{}'.format(projection_name)
        headers = {'Accept': 'application/json'}
        response = requests.get(uri, headers=headers)
        return response.json()

    def get_projection_state(self, projection_name, partition=None):
        uri = self.uri_base + '/projection/{}/state'.format(projection_name)
        headers = {'Accept': 'application/json'}
        params = {}
        if partition:
            params['partition'] = partition
        response = requests.get(uri, headers=headers, params=params)
        return response.json()

import asyncio
import uuid
import json

from pyeventstore.events import (get_all_events,
                                 start_subscription,
                                 publish_events)

class Client:

    def __init__(self, host, secure=False, port=2113):
        proto = "https" if secure else "http"
        self.uri_base = '{}://{}:{}'.format(proto, host, port)

    @asyncio.coroutine
    def publish_events(self, stream_name, events):
        uri = self.stream_head_uri(stream_name)
        yield from publish_events(uri, events)

    def stream_head_uri(self, stream_name):
        return '{}/streams/{}'.format(self.uri_base, stream_name)

    @asyncio.coroutine
    def get_all_events(self, stream_name):
        head_uri = self.stream_head_uri(stream_name)
        return (yield from get_all_events(head_uri))

    @asyncio.coroutine
    def subscribe(self, stream_name, interval_seconds=1):
        head_uri = self.stream_head_uri(stream_name)
        return (yield from start_subscription(head_uri, interval_seconds))

Remove projections methods for now

Remove projections methods for now


# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from .processor import MinidumpProcessor

from uwsgidecoratorsfallback import spool

import logging

logger = logging.getLogger(__name__)

@spool
def do_process_uploaded_crash(*args, **kwargs):
    minproc = MinidumpProcessor()
    minproc.process(kwargs['crash_id'])
    logger.info('processed: %s' % (kwargs['crash_id']))

# vim:set shiftwidth=4 softtabstop=4 expandtab: */

# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from .processor import MinidumpProcessor

from uwsgidecoratorsfallback import spool

import logging

logger = logging.getLogger(__name__)

@spool
def do_process_uploaded_crash(env):
    minproc = MinidumpProcessor()
    minproc.process(env['crash_id'])
    logger.info('processed: %s' % (env['crash_id']))

# vim:set shiftwidth=4 softtabstop=4 expandtab: */

Revert "make the uwsgi spooler code also work with the fallback"

This reverts commit 84ab847b444fbd41b9cc17e5c79a609efdcdf6cf.


from TwircBot import TwircBot as tw

bot = tw("config/sampleConfig.sample")
bot.print_config()
bot.connect()

from TwircBot import TwircBot as tw
import sys

bot = tw(sys.argv[1])
bot.print_config()
bot.connect()

Modify runTwirc.py to accept system arguments


from transformations.BackTranslation import BackTranslation
from transformations.ButterFingersPerturbation import ButterFingersPerturbation
from transformations.ChangeNamedEntities import ChangeNamedEntities
from transformations.SentenceTransformation import SentenceTransformation
from transformations.WithoutPunctuation import WithoutPunctuation

class TransformationsList(SentenceTransformation):

    def __init__(self):
        transformations = []
        transformations.append(ButterFingersPerturbation())
        transformations.append(WithoutPunctuation())
        transformations.append(ChangeNamedEntities())
        transformations.append(BackTranslation())
        self.transformations = transformations

    def generate(self, sentence: str):
        print(f"Original Input : {sentence}")
        generations = {"Original": sentence}
        for transformation in self.transformations:
            generations[transformation.name()] = transformation.generate(sentence)
        return generations

from transformations.BackTranslation import BackTranslation
from transformations.ButterFingersPerturbation import ButterFingersPerturbation
from transformations.ChangeNamedEntities import ChangeNamedEntities
from transformations.SentenceTransformation import SentenceTransformation
from transformations.WithoutPunctuation import WithoutPunctuation

class TransformationsList(SentenceTransformation):

    def __init__(self):
        transformations = [ButterFingersPerturbation(), WithoutPunctuation(), ChangeNamedEntities(), BackTranslation()]
        self.transformations = transformations

    def generate(self, sentence: str):
        print(f"Original Input : {sentence}")
        generations = {"Original": sentence}
        for transformation in self.transformations:
            generations[transformation.name()] = transformation.generate(sentence)
        return generations

Add interface for source+label pertubation


from bs4 import BeautifulSoup

#uses beautiful soup to parse html file
#finds the correct span tag
#Gets the percentage of ink left in the printer
soup = BeautifulSoup(open("test/test.html"))
res =  soup.find('span',{'class':'hpConsumableBlockHeaderText'}).text
num = res[24] + res[25]

file = open('test/data.csv', 'w+')
file.write(num + ",")

Write information from test.html to csv file


from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from zope.interface import implements

class UserhostCommand(ModuleData, Command):
	implements(IPlugin, IModuleData, ICommand)

	name = "UserhostCommand"
	core = True

	def userCommands(self):
		return [ ("USERHOST", 1, self) ]

	def parseParams(self, user, params, prefix, tags):
		if not params:
			user.sendSingleError("UserhostParams", irc.ERR_NEEDMOREPARAMS, "USERHOST", "Not enough parameters")
			return None
		return {
			"nicks": params[:5]
		}

	def execute(self, user, data):
		userHosts = []
		for nick in data["nicks"]:
			if nick not in self.ircd.userNicks:
				continue
			targetUser = self.ircd.users[self.ircd.userNicks[nick]]
			output = targetUser.nick
			if self.ircd.runActionUntilValue("userhasoperpermission", targetUser, "", users=[targetUser]):
				output += "*"
			output += "="
			if user.metadataKeyExists("away"):
				output += "-"
			else:
				output += "+"
			output += "{}@{}".format(targetUser.ident, targetUser.host())
			userHosts.append(output)
		user.sendMessage(irc.RPL_USERHOST, " ".join(userHosts))
		return True

userhostCmd = UserhostCommand()

from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from zope.interface import implements

class UserhostCommand(ModuleData, Command):
	implements(IPlugin, IModuleData, ICommand)

	name = "UserhostCommand"
	core = True

	def userCommands(self):
		return [ ("USERHOST", 1, self) ]

	def parseParams(self, user, params, prefix, tags):
		if not params:
			user.sendSingleError("UserhostParams", irc.ERR_NEEDMOREPARAMS, "USERHOST", "Not enough parameters")
			return None
		return {
			"nicks": params[:5]
		}

	def execute(self, user, data):
		userHosts = []
		for nick in data["nicks"]:
			if nick not in self.ircd.userNicks:
				continue
			targetUser = self.ircd.users[self.ircd.userNicks[nick]]
			output = targetUser.nick
			if self.ircd.runActionUntilValue("userhasoperpermission", targetUser, "", users=[targetUser]):
				output += "*"
			output += "="
			if targetUser.metadataKeyExists("away"):
				output += "-"
			else:
				output += "+"
			output += "{}@{}".format(targetUser.ident, targetUser.host())
			userHosts.append(output)
		user.sendMessage(irc.RPL_USERHOST, " ".join(userHosts))
		return True

userhostCmd = UserhostCommand()

Check away status of the target, not user, of USERHOST