def ensureFocusHandler():
    JS("""
    return (focusHandler !== null) ? focusHandler : (focusHandler =
            @{{createFocusHandler}}());
    """)

def createFocusHandler():
    JS("""
    return function(evt) {
      // This function is called directly as an event handler, so 'this' is
      // set up by the browser to be the input on which the event is fired. We
      // call focus() in a timeout or the element may be blurred when this event
      // ends.
      var div = this['parentNode'];
      if (div['onfocus']) {
        $wnd['setTimeout'](function() {
          div['focus']();
        }, 0);
      }
    };
    """)

def createFocusable0(focusHandler):
    JS("""
    var div = $doc['createElement']('div');
    div['tabIndex'] = 0;

    var input = $doc['createElement']('input');
    input['type'] = 'text';
    input['style']['opacity'] = 0;
    input['tabIndex'] = -1;
    input['style']['zIndex'] = -1;
    input['style']['width'] = '1px';
    input['style']['height'] = '1px';
    input['style']['overflow'] = 'hidden';
    input['style']['position'] = 'absolute';

    input['addEventListener']( 'focus', focusHandler, false);

    div['appendChild'](input);
    return div;
    """)

def createFocusable():
    ensureFocusHandler()
    return createFocusable0()

def ensureFocusHandler():
    JS("""
    return (focusHandler !== null) ? focusHandler : (focusHandler =
            @{{createFocusHandler}}());
    """)

def createFocusHandler():
    JS("""
    return function(evt) {
      // This function is called directly as an event handler, so 'this' is
      // set up by the browser to be the input on which the event is fired. We
      // call focus() in a timeout or the element may be blurred when this event
      // ends.
      var div = this['parentNode'];
      if (div['onfocus']) {
        $wnd['setTimeout'](function() {
          div['focus']();
        }, 0);
      }
    };
    """)

def createFocusable0(focusHandler):
    JS("""
    var div = $doc['createElement']('div');
    div['tabIndex'] = 0;

    var input = $doc['createElement']('input');
    input['type'] = 'text';
    input['style']['opacity'] = 0;
    input['tabIndex'] = -1;
    input['style']['zIndex'] = -1;
    input['style']['width'] = '1px';
    input['style']['height'] = '1px';
    input['style']['overflow'] = 'hidden';
    input['style']['position'] = 'absolute';

    input['addEventListener']( 'focus', focusHandler, false);

    div['appendChild'](input);
    return div;
    """)

def createFocusable():
    return createFocusable0(ensureFocusHandler())

Fix for IE 11 (Focus)

Fix for IE 11 (Focus)

IE presents itself as mozilla, so it trips on the bug.


from __future__ import absolute_import

import logging
import sys

from pip._vendor import pkg_resources
from pip._vendor.packaging import specifiers
from pip._vendor.packaging import version

logger = logging.getLogger(__name__)

def get_metadata(dist):
    if (isinstance(dist, pkg_resources.DistInfoDistribution) and
            dist.has_metadata('METADATA')):
        return dist.get_metadata('METADATA')
    elif dist.has_metadata('PKG-INFO'):
        return dist.get_metadata('PKG-INFO')

def check_requires_python(requires_python):
    if requires_python is None:
        # The package provides no information
        return True
    try:
        requires_python_specifier = specifiers.SpecifierSet(requires_python)
    except specifiers.InvalidSpecifier as e:
        logger.debug(
            "Package %s has an invalid Requires-Python entry - %s" % (
                 requires_python, e))
        return ValueError('Wrong Specifier')

    # We only use major.minor.micro
    python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
    if python_version not in requires_python_specifier:
        return False

from __future__ import absolute_import

import logging
import sys

from pip._vendor import pkg_resources
from pip._vendor.packaging import specifiers
from pip._vendor.packaging import version

logger = logging.getLogger(__name__)

def get_metadata(dist):
    if (isinstance(dist, pkg_resources.DistInfoDistribution) and
            dist.has_metadata('METADATA')):
        return dist.get_metadata('METADATA')
    elif dist.has_metadata('PKG-INFO'):
        return dist.get_metadata('PKG-INFO')

def check_requires_python(requires_python):
    """
    Check if the python version in used match the `requires_python` specifier passed.

    Return `True` if the version of python in use matches the requirement.
    Return `False` if the version of python in use does not matches the requirement.
    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    try:
        requires_python_specifier = specifiers.SpecifierSet(requires_python)
    except specifiers.InvalidSpecifier as e:
        logger.debug(
            "Package %s has an invalid Requires-Python entry - %s" % (
                 requires_python, e))
        raise specifiers.InvalidSpecifier(*e.args)

    # We only use major.minor.micro
    python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
    return python_version in requires_python_specifier

Update check_requires_python and describe behavior in docstring


from conans import ConanFile
from conans.tools import download, unzip
import os

VERSION = "0.0.1"

class CMakeHeaderLanguageConan(ConanFile):
    name = "cmake-header-language"
    version = os.environ.get("CONAN_VERSION_OVERRIDE", VERSION)
    generators = "cmake"
    requires = ("cmake-include-guard/master@smspillaz/cmake-include-guard",
                "cmake-unit/master@smspillaz/cmake-unit")
    url = "http://github.com/polysquare/cmake-header-language"
    license = "MIT"

    def source(self):
        zip_name = "cmake-header-language.zip"
        download("https://github.com/polysquare/"
                 "cmake-header-language/archive/{version}.zip"
                 "".format(version="v" + VERSION),
                 zip_name)
        unzip(zip_name)
        os.unlink(zip_name)

    def package(self):
        self.copy(pattern="*.cmake",
                  dst="cmake/cmake-header-language",
                  src="cmake-header-language-" + VERSION,
                  keep_path=True)

from conans import ConanFile
from conans.tools import download, unzip
import os

VERSION = "0.0.2"

class CMakeHeaderLanguageConan(ConanFile):
    name = "cmake-header-language"
    version = os.environ.get("CONAN_VERSION_OVERRIDE", VERSION)
    generators = "cmake"
    requires = ("cmake-include-guard/master@smspillaz/cmake-include-guard",
                "cmake-unit/master@smspillaz/cmake-unit")
    url = "http://github.com/polysquare/cmake-header-language"
    license = "MIT"

    def source(self):
        zip_name = "cmake-header-language.zip"
        download("https://github.com/polysquare/"
                 "cmake-header-language/archive/{version}.zip"
                 "".format(version="v" + VERSION),
                 zip_name)
        unzip(zip_name)
        os.unlink(zip_name)

    def package(self):
        self.copy(pattern="*.cmake",
                  dst="cmake/cmake-header-language",
                  src="cmake-header-language-" + VERSION,
                  keep_path=True)

Bump version: 0.0.1 -> 0.0.2

Bump version: 0.0.1 -> 0.0.2

[ci skip]


#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SciStack: the web app to build docker containers for reproducable science

"""
import os
import flask

app = flask.Flask(__name__)

@app.route("/")
def hello():
    return "Choose a domain!"

if __name__ == "__main__":
    app.run()

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SciStack: the web app to build docker containers for reproducable science

"""
import os
import flask
import inspect

app = flask.Flask(__name__, static_url_path='')

# Home of any pre-build docker files
docker_file_path = os.path.join(os.path.dirname(os.path.abspath(
    inspect.getfile(inspect.currentframe()))), "..", "dockerfiles")

@app.route("/")
def hello():
    return "Choose a domain!"

@app.route("/dfview/<path:fname>")
def send_dockerfile(fname):
    with open(os.path.join(docker_file_path, fname)) as dfile:
        return_value = dfile.read()
    return return_value

if __name__ == "__main__":
    app.run()

Return pre-built dockerfile to user

Return pre-built dockerfile to user


#!/usr/bin/env python

NODE_VERSION = 'v0.11.10'
BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = '607907aed2c1dcdd3b5968a756a990ba3f47bca7'

#!/usr/bin/env python

NODE_VERSION = 'v0.11.10'
BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = '276722e68bb643e3ae3b468b701c276aeb884838'

Upgrade libchromiumcontent: Add support for acceptsFirstMouse.


#!/usr/bin/env python

import platform
import sys

BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = 'e4b283c22236560fd289fe59c03e50adf39e7c4b'

ARCH = {
    'cygwin': '32bit',
    'darwin': '64bit',
    'linux2': platform.architecture()[0],
    'win32': '32bit',
}[sys.platform]
DIST_ARCH = {
    '32bit': 'ia32',
    '64bit': 'x64',
}[ARCH]

TARGET_PLATFORM = {
  'cygwin': 'win32',
  'darwin': 'darwin',
  'linux2': 'linux',
  'win32': 'win32',
}[sys.platform]

verbose_mode = False

def enable_verbose_mode():
  print 'Running in verbose mode'
  global verbose_mode
  verbose_mode = True

def is_verbose_mode():
  return verbose_mode

#!/usr/bin/env python

import platform
import sys

BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = 'aa87035cc012ce0d533bb56b947bca81a6e71b82'

ARCH = {
    'cygwin': '32bit',
    'darwin': '64bit',
    'linux2': platform.architecture()[0],
    'win32': '32bit',
}[sys.platform]
DIST_ARCH = {
    '32bit': 'ia32',
    '64bit': 'x64',
}[ARCH]

TARGET_PLATFORM = {
  'cygwin': 'win32',
  'darwin': 'darwin',
  'linux2': 'linux',
  'win32': 'win32',
}[sys.platform]

verbose_mode = False

def enable_verbose_mode():
  print 'Running in verbose mode'
  global verbose_mode
  verbose_mode = True

def is_verbose_mode():
  return verbose_mode

Upgrade libchromiumcontent to fix generating node.lib


# Store various constants here

# Maximum file upload size (in bytes).
MAX_CONTENT_LENGTH = 1 * 1024 * 1024 * 1024

# Authentication constants
PWD_HASH_ALGORITHM = 'pbkdf2_sha256'
SALT_SIZE = 24
MIN_PASSWORD_LENGTH = 8
MAX_PASSWORD_LENGTH = 1024
HASH_ROUNDS = 50000
PWD_RESET_KEY_LENGTH = 32
# Length of time before recovery key expires, in minutes.
PWD_RESET_KEY_EXPIRATION = 1440

class Permissions:
  '''
  Enumerates administrator permissions. These values are independent of
  each other, but must be unique. Permissions should be stored in the session
  '''
  # Access to the admin page
  Admin = 0
  # Website admins.
  SiteAdmin = 1
  # Allowed to add and manage users.
  UserAdmin = 2
  # Allowed to run the room hassle.
  HassleAdmin = 3

# Store various constants here

# Maximum file upload size (in bytes).
MAX_CONTENT_LENGTH = 1 * 1024 * 1024 * 1024

# Authentication constants
PWD_HASH_ALGORITHM = 'pbkdf2_sha256'
SALT_SIZE = 24
MIN_PASSWORD_LENGTH = 8
MAX_PASSWORD_LENGTH = 1024
HASH_ROUNDS = 100000
PWD_RESET_KEY_LENGTH = 32
# Length of time before recovery key expires, in minutes.
PWD_RESET_KEY_EXPIRATION = 1440

class Permissions:
  '''
  Enumerates administrator permissions. These values are independent of
  each other, but must be unique. Permissions should be stored in the session
  '''
  # Access to the admin page
  Admin = 0
  # Website admins.
  SiteAdmin = 1
  # Allowed to add and manage users.
  UserAdmin = 2
  # Allowed to run the room hassle.
  HassleAdmin = 3

Set hash rounds back to 100000

Set hash rounds back to 100000

- Installed python-m2crypto package which speeds up pbkdf2 enough that
  100K rounds is fine again.


import unittest
import sys
import subprocess

if __name__ == '__main__':
    if len(sys.argv) > 1:
        unittest.main(module='flask_api.tests')
    else:
        subprocess.call([sys.executable, '-m', 'unittest', 'discover'])

import unittest

if __name__ == '__main__':
    unittest.main(module='flask_api.tests')

Simplify test execution to restore coverage measurement


__author__ = 's7a'

# All imports
from extras import KuceraFrancis
from resource import Resource
from os import path

# The Kucera Francis enrichment class
class KuceraFrancisEnricher:

    # Constructor for the Kucera Francis Enricher
    def __init__(self):
        self.kf = KuceraFrancis(path.join('data', 'kucera_francis.csv'))

    # Enrich the word
    def enrich_word(self, word):
        if self.kf.frequency(word) == 0:
            return Resource.link(word)
        return word

__author__ = 's7a'

# All imports
from extras import StemmedKuceraFrancis
from resource import Resource
from os import path

# The Kucera Francis enrichment class
class KuceraFrancisEnricher:

    # Constructor for the Kucera Francis Enricher
    def __init__(self):
        self.kf = StemmedKuceraFrancis(path.join('data', 'kucera_francis.csv'))

    # Enrich the word
    def enrich_word(self, word):
        if self.kf.frequency(word) == 0:
            return Resource.link(word)
        return word

Use stemmed Kucera Francis for Enrichment


class InvalidData(Exception):
    """
    Raised for by step validation process
    """
    pass

class Step(object):
    """
    A single step in a multistep process
    """
    def validate(self):
        raise NotImplementedError()  # pragma: no cover

class ProcessManager(object):
    """
    A multistep process handler
    """
    def validate_step(self, step):
        try:
            step.validate()
        except InvalidData:
            return False
        return True

    def get_next_step(self):
        for step in self:
            if not self.validate_step(step):
                return step

    def get_errors(self):
        errors = {}
        for step in self:
            try:
                step.validate()
            except InvalidData as error:
                errors[str(step)] = error
        return errors

    def is_complete(self):
        return not self.get_next_step()

    def __getitem__(self, step_id):
        for step in self:
            if str(step) == step_id:
                return step
        raise KeyError('%r is not a valid step' % (step_id,))

class InvalidData(Exception):
    """
    Raised for by step validation process
    """
    pass

class Step(object):
    """
    A single step in a multistep process
    """
    def validate(self):
        raise NotImplementedError()  # pragma: no cover

class ProcessManager(object):
    """
    A multistep process handler
    """
    def validate_step(self, step):
        try:
            step.validate()
        except InvalidData:
            return False
        return True

    def get_next_step(self):
        for step in self:
            if not self.validate_step(step):
                return step

    def get_errors(self):
        errors = {}
        for step in self:
            try:
                step.validate()
            except InvalidData as error:
                errors[str(step)] = error
        return errors

    def is_complete(self):
        return self.get_next_step() is None

    def __getitem__(self, step_id):
        for step in self:
            if str(step) == step_id:
                return step
        raise KeyError('%r is not a valid step' % (step_id,))

Check explicit that next step is None

Check explicit that next step is None


from lava_server.extension import LavaServerExtension

class DashboardExtension(LavaServerExtension):

    @property
    def app_name(self):
        return "dashboard_app"

    @property
    def name(self):
        return "Dashboard"

    @property
    def main_view_name(self):
        return "dashboard_app.views.bundle_stream_list"

    @property
    def description(self):
        return "Validation Dashboard"

    @property
    def version(self):
        import versiontools
        import dashboard_app
        return versiontools.format_version(dashboard_app.__version__)

    def contribute_to_settings(self, settings):
        super(DashboardExtension, self).contribute_to_settings(settings)
        settings['INSTALLED_APPS'].extend([
            "linaro_django_pagination",
            "south",
        ])
        settings['MIDDLEWARE_CLASSES'].append(
            'linaro_django_pagination.middleware.PaginationMiddleware')
        settings['RESTRUCTUREDTEXT_FILTER_SETTINGS'] = {
            "initial_header_level": 4}
        # TODO: Add dataview database support

from lava_server.extension import LavaServerExtension

class DashboardExtension(LavaServerExtension):

    @property
    def app_name(self):
        return "dashboard_app"

    @property
    def name(self):
        return "Dashboard"

    @property
    def main_view_name(self):
        return "dashboard_app.views.bundle_stream_list"

    @property
    def description(self):
        return "Validation Dashboard"

    @property
    def version(self):
        import versiontools
        import dashboard_app
        return versiontools.format_version(dashboard_app.__version__)

    def contribute_to_settings(self, settings):
        super(DashboardExtension, self).contribute_to_settings(settings)
        settings['INSTALLED_APPS'].extend([
            "linaro_django_pagination",
            "south",
        ])
        settings['MIDDLEWARE_CLASSES'].append(
            'linaro_django_pagination.middleware.PaginationMiddleware')
        settings['RESTRUCTUREDTEXT_FILTER_SETTINGS'] = {
            "initial_header_level": 4}

    def contribute_to_settings_ex(self, settings_module, settings_object):
        settings_module['DATAVIEW_DIRS'] = settings_object._settings.get(
            "DATAVIEW_DIRS", [])
        settings_module['DATAREPORT_DIRS'] = settings_object._settings.get(
            "DATAREPORT_DIRS", [])

Add support for configuring data views and reports


#    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.

"""Cinder OS API WSGI application."""

import sys
import warnings

from cinder import objects

warnings.simplefilter('once', DeprecationWarning)

from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import wsgi

from cinder import i18n
i18n.enable_lazy()

# Need to register global_opts
from cinder.common import config
from cinder import rpc
from cinder import version

CONF = cfg.CONF

def initialize_application():
    objects.register_all()
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup(CONF, "cinder")
    config.set_middleware_defaults()

    rpc.init(CONF)
    return wsgi.Loader(CONF).load_app(name='osapi_volume')

#    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.

"""Cinder OS API WSGI application."""

import sys
import warnings

from cinder import objects

warnings.simplefilter('once', DeprecationWarning)

from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import wsgi

from cinder import i18n
i18n.enable_lazy()

# Need to register global_opts
from cinder.common import config
from cinder.common import constants
from cinder import rpc
from cinder import service
from cinder import version

CONF = cfg.CONF

def initialize_application():
    objects.register_all()
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup(CONF, "cinder")
    config.set_middleware_defaults()

    rpc.init(CONF)
    service.setup_profiler(constants.API_BINARY, CONF.host)

    return wsgi.Loader(CONF).load_app(name='osapi_volume')

Initialize osprofiler in WSGI application

This patch adds missing initialization of OSProfiler
when Cinder API is running as WSGI application.

Change-Id: Ifaffa2d58eeadf5d47fafbdde5538d26bcd346a6


import queue
import threading

class Producer(object):

    def __init__(self, period_in_seconds, queue, function):
        self._period_in_seconds = period_in_seconds
        self._queue = queue
        self._function = function
        self._event = threading.Event()
        self._thread = threading.Thread(target=self._loop)

    def start(self):
        self._thread.start()

    def stop(self):
        self._event.set()
        self._thread.join()

    def _loop(self):
        while not self._event.wait(self._period_in_seconds):
            self.__put_item_into_the_queue()

    def __put_item_into_the_queue(self):
        try:
            self._queue.put(self._function)
        except queue.Full:
            pass

class Consumer(object):

    STOP_SENTINEL = "STOP"

    def __init__(self, queue, function):
        self._queue = queue
        self._function = function
        self._thread = threading.Thread(target=self._loop)
        self.no_date_from_the_queue = True

    def start(self):
        self._thread.start()

    def stop(self):
        self._queue.put(self.STOP_SENTINEL)
        self._thread.join()

    def _loop(self):
        for result in iter(self._queue.get, self.STOP_SENTINEL):
            self.no_date_from_the_queue = result is None
            if result:
                self._function(result)

try:
    import queue
except ImportError:
    import Queue
import threading

class Producer(object):

    def __init__(self, period_in_seconds, queue, function):
        self._period_in_seconds = period_in_seconds
        self._queue = queue
        self._function = function
        self._event = threading.Event()
        self._thread = threading.Thread(target=self._loop)

    def start(self):
        self._thread.start()

    def stop(self):
        self._event.set()
        self._thread.join()

    def _loop(self):
        while not self._event.wait(self._period_in_seconds):
            self.__put_item_into_the_queue()

    def __put_item_into_the_queue(self):
        try:
            self._queue.put(self._function)
        except queue.Full:
            pass

class Consumer(object):

    STOP_SENTINEL = "STOP"

    def __init__(self, queue, function):
        self._queue = queue
        self._function = function
        self._thread = threading.Thread(target=self._loop)
        self.no_date_from_the_queue = True

    def start(self):
        self._thread.start()

    def stop(self):
        self._queue.put(self.STOP_SENTINEL)
        self._thread.join()

    def _loop(self):
        for result in iter(self._queue.get, self.STOP_SENTINEL):
            self.no_date_from_the_queue = result is None
            if result:
                self._function(result)

Handle import error on older python versions


import csv
import os
import color

def _GetDataDirPath():
  return os.path.join(os.path.dirname(__file__), 'data')

def _GetCsvPath():
  return os.path.join(_GetDataDirPath(), 'dmccolors.csv')

def _GetCsvString():
  with open(_GetCsvPath()) as f:
    return f.read().strip()

def _CreateDmcColorFromRow(row):
  print row
  number = int(row[0])
  name = row[1]
  hex_color = row[5]
  red, green, blue = color.RGBColorFromHexString(hex_color)
  return DMCColor(number, name, red, green, blue)

class DMCColor(color.RGBColor):
  def __init__(self, number, name, red, green, blue):
    self.number = number
    self.name = name
    super(DMCColor, self).__init__(red, green, blue)

def main():
  csv_data = _GetCsvString()
  lines = csv_data.splitlines()

  # Skip first line
  lines = lines[1:]

  reader = csv.reader(lines, delimiter='\t')

  dmc_colors = list()
  for row in reader:
    dmc_colors.append(_CreateDmcColorFromRow(row))

  print dmc_colors

main()

import csv
import os
import color

def _GetDataDirPath():
  return os.path.join(os.path.dirname(__file__), 'data')

def _GetCsvPath():
  return os.path.join(_GetDataDirPath(), 'dmccolors.csv')

def _GetCsvString():
  with open(_GetCsvPath()) as f:
    return f.read().strip()

def _CreateDmcColorFromRow(row):
  number = int(row[0])
  name = row[1]
  hex_color = row[5]
  red, green, blue = color.RGBTupleFromHexString(hex_color)
  return DMCColor(number, name, red, green, blue)

# DMC Colors singleton
_dmc_colors = None

def _CreateDMCColors():
  global _dmc_colors
  csv_data = _GetCsvString()
  lines = csv_data.splitlines()

  # Skip first line
  lines = lines[1:]
  reader = csv.reader(lines, delimiter='\t')

  dmc_colors = set()
  for row in reader:
   dmc_colors.add(_CreateDmcColorFromRow(row))

  return dmc_colors

def GetDMCColors():
  global _dmc_colors
  if not _dmc_colors:
    _dmc_colors = frozenset(_CreateDMCColors())
  return _dmc_colors

class DMCColor(color.RGBColor):
  def __init__(self, number, name, red, green, blue):
    self.number = number
    self.name = name
    super(DMCColor, self).__init__(red, green, blue)

# Simple executable functionality for debugging.
def main():
  for color in GetDMCColors():
    print color

if __name__ == '__main__':
  main()

Add functionality to build the DMCColors set.


# Lint as: python3
# Copyright 2020 Google LLC. All Rights Reserved.
#
# 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.
"""Setup configuration of TensorFlow Enterprise client-side library."""

def make_required_install_packages():
  return [
      'absl-py',
      'cloudpickle',
      'google-api-python-client',
      'google-auth',
      'keras-tuner',
      'tensorflow>=1.15.0,<3.0',
      'tensorflow_datasets',
  ]

def make_required_test_packages():
  return ['mock', 'numpy']

# Lint as: python3
# Copyright 2020 Google LLC. All Rights Reserved.
#
# 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.
"""Setup configuration of TensorFlow Enterprise client-side library."""

def make_required_install_packages():
  return [
      'absl-py',
      'cloudpickle',
      'google-api-python-client',
      'google-auth',
      'keras-tuner',
      'tensorflow>=1.15.0,<3.0',
      'tensorflow_datasets<3.1.0',
  ]

def make_required_test_packages():
  return ['mock', 'numpy']

Set higher bound on Tensorflow_Datasets due to https://github.com/tensorflow/datasets/issues/2199

PiperOrigin-RevId: 321392671


from django.shortcuts import render
from django.http import Http404
from django.contrib.messages import success
from django.utils.translation import ugettext_lazy as _

from wagtail.wagtailcore.models import Page

from .models import HomePage, StaticPage
from category.models import Category
from .forms import ContactForm

def home_page(request, slug="home-page"):
    home_page = HomePage.objects.get(slug=slug)
    return render(request, "core/home_page.html", {
        "page": home_page,
        "categories": Category.objects.all()[:9]
    })

def static_page(request, slug=None):
    try:
        page = Page.objects.get(slug=slug)
    except Page.DoesNotExist:
        raise Http404
    if page.specific_class == HomePage:
        return home_page(request, page.slug)
    return render(request, "core/static_page.html", {
        "self": page.specific
    })

def contribute(request, slug=None):
    page = StaticPage.objects.get(slug=slug)
    return render(request, "core/contribute.html", {
        "self": page
    })

def contact_us(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            success(request, _("Your query has successfully been sent"))
    else:
        form = ContactForm()
    return render(request, "core/contact_us.html", {
        "contact_form": form
    })

from django.shortcuts import render
from django.http import Http404
from django.contrib.messages import success
from django.utils.translation import ugettext_lazy as _

from wagtail.wagtailcore.models import Page

from .models import HomePage, StaticPage
from category.models import Category
from .forms import ContactForm

def home_page(request, slug="home-page"):
    home_page = HomePage.objects.get(slug=slug)
    return render(request, "core/home_page.html", {
        "page": home_page,
        "categories": Category.objects.all()[:9]
    })

def static_page(request, slug=None):
    try:
        page = Page.objects.get(slug=slug)
    except Page.DoesNotExist:
        raise Http404
    if page.specific_class == HomePage:
        return home_page(request, page.slug)
    return render(request, "core/static_page.html", {
        "self": page.specific
    })

def contribute(request, slug=None):
    page = StaticPage.objects.get(slug=slug)
    return render(request, "core/contribute.html", {
        "self": page
    })

def contact_us(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            success(request, _("Your query has successfully been sent"))
            form = ContactForm()
    else:
        form = ContactForm()
    return render(request, "core/contact_us.html", {
        "contact_form": form
    })

Clear the contact form after it has been successfully posted.


import os
import hashlib

from fnmatch import fnmatchcase

def get_files(index):
    paths = []

    for dirpath, dirnames, filenames in os.walk(index.headers['root_path']):
        # Remove ignored directories
        dirnames = [d for d in dirnames if not index.ignores.match(d)]

        for filename in (f for f in filenames if not index.ignores.match(f)):
            # We want the path of the file, not its name
            path = os.path.join(dirpath, filename)

            # That path must be relative to the root, not absolute
            path = os.path.relpath(path, index.headers['root_path'])

            paths.append(path)

    return paths

def get_ignores(ignores_path):
    with open(ignores_path, 'r') as ignores_file:
        ignores = [line.strip() for line in ignores_file]

    return ignores

def get_hash(path):
    h = hashlib.sha1()

    with open(path, 'rb') as f:
        h.update(f.read())

    return h.hexdigest()

def get_new_and_missing(index):
    current_files = get_files(index)

    new_files = [path for path in current_files if path not in index.files]

    missing_files = [path for path in index.files.iterkeys() if path not in current_files]

    return new_files, missing_files

import os
import hashlib

def get_files(index):
    paths = []

    for dirpath, dirnames, filenames in os.walk(index.headers['root_path']):
        # Remove ignored directories
        dirnames[:] = [d for d in dirnames if not index.ignores.match(d)]

        for filename in (f for f in filenames if not index.ignores.match(f)):
            # We want the path of the file, not its name
            path = os.path.join(dirpath, filename)

            # That path must be relative to the root, not absolute
            path = os.path.relpath(path, index.headers['root_path'])

            paths.append(path)

    return paths

def get_ignores(ignores_path):
    with open(ignores_path, 'r') as ignores_file:
        ignores = [line.strip() for line in ignores_file]

    return ignores

def get_hash(path):
    h = hashlib.sha1()

    with open(path, 'rb') as f:
        h.update(f.read())

    return h.hexdigest()

def get_new_and_missing(index):
    current_files = get_files(index)

    new_files = [path for path in current_files if path not in index.files]

    missing_files = [path for path in index.files.iterkeys() if path not in current_files]

    return new_files, missing_files

Fix in-place os.walk() dirs modification


VERSION = (1, 0, 'rc_1')

def get_version():
    "Returns the version as a human-format string."
    v = '.'.join([str(i) for i in VERSION[:-1]])
    if VERSION[-1]:
        from django.utils.version import get_svn_revision
        v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision())
    return v

VERSION = (1, 0, 'final')

def get_version():
    "Returns the version as a human-format string."
    v = '.'.join([str(i) for i in VERSION[:-1]])
    if VERSION[-1]:
        from django.utils.version import get_svn_revision
        v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision())
    return v

Bump version number for Django 1.0 release

git-svn-id: 4f9f921b081c523744c7bf24d959a0db39629563@8960 bcc190cf-cafb-0310-a4f2-bffc1f526a37


from rest_framework import serializers

from .models import Upload

class UploadSerializer(serializers.ModelSerializer):
    class Meta:
        model = Upload
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['guid'].required = True

Make guid required in upload API

Make guid required in upload API


from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer

from .consumers import PRESENCE_ROOM
from .models import Campaign

def connect_info_object(sender, **kwargs):
    reference = kwargs.get('reference')
    if not reference:
        return
    if not reference.startswith('campaign:'):
        return
    namespace, campaign_value = reference.split(':', 1)
    try:
        campaign, ident = campaign_value.split('@', 1)
    except (ValueError, IndexError):
        return

    try:
        campaign_pk = int(campaign)
    except ValueError:
        return

    try:
        campaign = Campaign.objects.get(pk=campaign_pk)
    except Campaign.DoesNotExist:
        return

    provider = campaign.get_provider()
    iobj = provider.connect_request(ident, sender)
    broadcast_request_made(provider, iobj)

def broadcast_request_made(provider, iobj):
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        PRESENCE_ROOM.format(provider.campaign.id), {
            "type": "request_made",
            "data": provider.get_detail_data(iobj)
        }
    )

from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer

from .consumers import PRESENCE_ROOM
from .models import Campaign

def connect_info_object(sender, **kwargs):
    reference = kwargs.get('reference')
    if not reference:
        return
    if not reference.startswith('campaign:'):
        return
    namespace, campaign_value = reference.split(':', 1)
    try:
        campaign, ident = campaign_value.split('@', 1)
    except (ValueError, IndexError):
        return

    if not ident:
        return

    try:
        campaign_pk = int(campaign)
    except ValueError:
        return

    try:
        campaign = Campaign.objects.get(pk=campaign_pk)
    except Campaign.DoesNotExist:
        return

    provider = campaign.get_provider()
    iobj = provider.connect_request(ident, sender)
    broadcast_request_made(provider, iobj)

def broadcast_request_made(provider, iobj):
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        PRESENCE_ROOM.format(provider.campaign.id), {
            "type": "request_made",
            "data": provider.get_detail_data(iobj)
        }
    )

Fix non-iobj campaign request connection


from django.conf.urls.defaults import *

urlpatterns = patterns("core.views",
    url("^airport_list/(?P<south>.*)/(?P<west>.*)/(?P<north>.*)/(?P<east>.*)/",
        "airports_for_boundary", name="airports_for_boundary"),
)

from django.conf.urls.defaults import *

urlpatterns = patterns("core.views",
    url("^airport/list/(?P<south>.*)/(?P<west>.*)/(?P<north>.*)/(?P<east>.*)/",
        "airports_for_boundary", name="airports_for_boundary"),
)

Change URL pattern for airport list.

Change URL pattern for airport list.


"""
byceps.services.user.event_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2018 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime
from typing import Sequence

from ...database import db
from ...typing import UserID

from .models.event import UserEvent, UserEventData

def create_event(event_type: str, user_id: UserID, data: UserEventData) -> None:
    """Create a user event."""
    event = _build_event(event_type, user_id, data)

    db.session.add(event)
    db.session.commit()

def _build_event(event_type: str, user_id: UserID, data: UserEventData
                ) -> UserEvent:
    """Assemble, but not persist, a user event."""
    now = datetime.utcnow()

    return UserEvent(now, event_type, user_id, data)

def get_events_for_user(user_id: UserID) -> Sequence[UserEvent]:
    """Return the events for that user."""
    return UserEvent.query \
        .filter_by(user_id=user_id) \
        .order_by(UserEvent.occurred_at) \
        .all()

"""
byceps.services.user.event_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2018 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime
from typing import Optional, Sequence

from ...database import db
from ...typing import UserID

from .models.event import UserEvent, UserEventData

def create_event(event_type: str, user_id: UserID, data: UserEventData) -> None:
    """Create a user event."""
    event = _build_event(event_type, user_id, data)

    db.session.add(event)
    db.session.commit()

def _build_event(event_type: str, user_id: UserID, data: UserEventData,
                 occurred_at: Optional[datetime]=None) -> UserEvent:
    """Assemble, but not persist, a user event."""
    if occurred_at is None:
        occurred_at = datetime.utcnow()

    return UserEvent(occurred_at, event_type, user_id, data)

def get_events_for_user(user_id: UserID) -> Sequence[UserEvent]:
    """Return the events for that user."""
    return UserEvent.query \
        .filter_by(user_id=user_id) \
        .order_by(UserEvent.occurred_at) \
        .all()

Allow to provide a custom `occurred_at` value when building a user event


import unittest

from datetime import date as vanilla_date, timedelta

from calexicon.dates import DistantDate

class TestDistantDate(unittest.TestCase):
    def test_subtraction(self):
        dd = DistantDate(10000, 1, 1)
        self.assertIsInstance(dd - vanilla_date(9999, 1, 1), timedelta)
        self.assertIsInstance(dd - timedelta(0), DistantDate)

    def test_subtract_correct_result(self):
        dd = DistantDate(10000, 1, 2)
        dd2 = DistantDate(10000, 1, 1)
        self.assertEqual(dd - dd2, timedelta(days=1))

    def test_subtract_vanilla_date_from_distant_date(self):
        dd = DistantDate(10000, 1, 2)
        d = vanilla_date(9984, 2, 29)
        x = 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 15 * 365 + 3 + 2
        self.assertEqual(dd - d, timedelta(days=x))

import unittest

from datetime import date as vanilla_date, timedelta

from calexicon.calendars import ProlepticJulianCalendar
from calexicon.dates import DateWithCalendar, DistantDate

class TestDistantDate(unittest.TestCase):
    def test_subtraction(self):
        dd = DistantDate(10000, 1, 1)
        self.assertIsInstance(dd - vanilla_date(9999, 1, 1), timedelta)
        self.assertIsInstance(dd - timedelta(0), DistantDate)

    def test_subtract_correct_result(self):
        dd = DistantDate(10000, 1, 2)
        dd2 = DistantDate(10000, 1, 1)
        self.assertEqual(dd - dd2, timedelta(days=1))

    def test_subtract_vanilla_date_from_distant_date(self):
        dd = DistantDate(10000, 1, 2)
        d = vanilla_date(9984, 2, 29)
        x = 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 15 * 365 + 3 + 2
        self.assertEqual(dd - d, timedelta(days=x))

    def test_equality(self):
        dd = DistantDate(2010, 8, 1)
        ProlepticJulianCalendar().bless(dd)
        dwc = DateWithCalendar(ProlepticJulianCalendar, DistantDate(2010, 8, 1))
        self.assertTrue(dwc == dd)

Add a passing test for equality.

Add a passing test for equality.

Narrow down problems with constructing a date far in the future.


"""Site container for an HTTP server.

A Web Site Process Bus object is used to connect applications, servers,
and frameworks with site-wide services such as daemonization, process
reload, signal handling, drop privileges, PID file management, logging
for all of these, and many more.

The 'plugins' module defines a few abstract and concrete services for
use with the bus. Some use tool-specific channels; see the documentation
for each class.
"""

from cherrypy.process.wspbus import bus  # noqa
from cherrypy.process import plugins, servers  # noqa

"""Site container for an HTTP server.

A Web Site Process Bus object is used to connect applications, servers,
and frameworks with site-wide services such as daemonization, process
reload, signal handling, drop privileges, PID file management, logging
for all of these, and many more.

The 'plugins' module defines a few abstract and concrete services for
use with the bus. Some use tool-specific channels; see the documentation
for each class.
"""

from .wspbus import bus
from . import plugins, servers

__all__ = ('bus', 'plugins', 'servers')

Use __all__ to avoid linter errors

Use __all__ to avoid linter errors


import io
import pcpp

class FortranPreprocessor(pcpp.Preprocessor):
    def __init__(self):
        super(pcpp.Preprocessor, self).__init__()

    def parse_to_string_lines(self, text):
        with io.StringIO() as f:
            self.parse(text)
            self.write(f)
            f.seek(0)
            result = f.readlines()
        return result

import io
import pcpp

class FortranPreprocessor(pcpp.Preprocessor):
    def __init__(self):
        super(FortranPreprocessor, self).__init__()

    def parse_to_string_lines(self, text):
        with io.StringIO() as f:
            self.parse(text)
            self.write(f)
            f.seek(0)
            result = f.readlines()
        return result

Fix super() call (properly) for py2.7

Fix super() call (properly) for py2.7


# coding: utf-8

import logging
import psutil
from subprocess import PIPE

class FfmpegProcess(object):
    def __init__(self):
        self._cmdline = None
        self._process = None
        self._paused = False

    def run(self):
        if self._cmdline is None:
            logging.debug('cmdline is not yet defined')
            return

        if not self.running:
            logging.debug('starting ffmpeg with command-line:\n`%s`',
                    self.cmdline)

            # stdin pipe is required to shutdown ffmpeg gracefully (see below)
            self._process = psutil.Popen(self._cmdline, stdin=PIPE)

    def stop(self):
        if self.paused:
            self.unpause()

        if self.running:
            logging.debug('stopping ffmpeg process')

            # emulate 'q' keyboard press to shutdown ffmpeg
            self._process.communicate(input='q')
            self._process.wait()

    @property
    def running(self):
        return self._process is not None and self._process.is_running()

    def pause(self):
        if self.running:
            if not self._paused:
                logging.debug('suspending ffmpeg process')

                self._process.suspend()
                self._paused = True

    def unpause(self):
        if self.running:
            if self._paused:
                logging.debug('resuming ffmpeg process')

                self._process.resume()
                self._paused = False

    @property
    def paused(self):
        return self._paused

    @property
    def cmdline(self):
        return self._cmdline

    @cmdline.setter
    def cmdline(self, value):
        self._cmdline = value

# coding: utf-8

import logging
import psutil
from subprocess import PIPE

class FfmpegProcess(object):
    def __init__(self):
        self._cmdline = None
        self._process = None
        self._paused = False

    def run(self):
        if self._cmdline is None:
            logging.debug('cmdline is not yet defined')
            return

        if not self.running:
            logging.debug('starting ffmpeg with command-line:\n`%s`',
                    self.cmdline)

            # stdin pipe is required to shutdown ffmpeg gracefully (see below)
            self._process = psutil.Popen(self._cmdline, stdin=PIPE)

    def stop(self):
        if self.paused:
            self.unpause()

        if self.running:
            logging.debug('stopping ffmpeg process')

            # emulate 'q' keyboard press to shutdown ffmpeg
            self._process.communicate(input='q')
            self._process.wait()

    @property
    def running(self):
        return self._process is not None and self._process.is_running()

    def pause(self):
        if self.running:
            if not self._paused:
                logging.debug('suspending ffmpeg process')

                self._process.suspend()
                self._paused = True

    def unpause(self):
        if self.running:
            if self._paused:
                logging.debug('resuming ffmpeg process')

                self._process.resume()
                self._paused = False

    @property
    def paused(self):
        return self._paused and self.running

    @property
    def cmdline(self):
        return self._cmdline

    @cmdline.setter
    def cmdline(self, value):
        self._cmdline = value

Implement pause property more accurately


import unittest

try:
    import spotpy
except ImportError:
    import sys
    sys.path.append(".")
    import spotpy

from spotpy.examples.spot_setup_hymod_python import spot_setup

class TestFast(unittest.TestCase):
    def setUp(self):

        self.spot_setup = spot_setup()
        self.rep = 800 # REP must be a multiply of amount of parameters which are in 7 if using hymod
        self.timeout = 10  # Given in Seconds

    def test_fast(self):
        sampler = spotpy.algorithms.fast(self.spot_setup, parallel="seq", dbname='test_FAST', dbformat="ram",
                                          sim_timeout=self.timeout)
        results = []

        sampler.sample(self.rep)
        results = sampler.getdata()
        self.assertEqual(800,len(results))

if __name__ == '__main__':
    unittest.main()

import unittest

try:
    import spotpy
except ImportError:
    import sys
    sys.path.append(".")
    import spotpy

from spotpy.examples.spot_setup_hymod_python import spot_setup

class TestFast(unittest.TestCase):
    def setUp(self):

        self.spot_setup = spot_setup()
        self.rep = 200 # REP must be a multiply of amount of parameters which are in 7 if using hymod
        self.timeout = 10  # Given in Seconds

    def test_fast(self):
        sampler = spotpy.algorithms.fast(self.spot_setup, parallel="seq", dbname='test_FAST', dbformat="ram",
                                          sim_timeout=self.timeout)
        results = []

        sampler.sample(self.rep)
        results = sampler.getdata()
        self.assertEqual(200,len(results))

if __name__ == '__main__':
    unittest.main()

Reduce amounts of runs for fast test analysis


# coding: utf-8
"""a Python frontend to ontologies
"""
from __future__ import absolute_import
from __future__ import unicode_literals

__version__ = 'dev'
__author__ = 'Martin Larralde'
__author_email__ = 'martin.larralde@ens-paris-saclay.fr'
__license__ = "MIT"

from .ontology import Ontology
from .term import Term, TermList
from .relationship import Relationship
from .synonym import Synonym, SynonymType

# Dynamically get the version of the installed module
try:
    import pkg_resources
    __version__ = pkg_resources.get_distribution(__name__).version
except Exception:
    pkg_resources = None
finally:
    del pkg_resources

# coding: utf-8
"""a Python frontend to ontologies
"""
from __future__ import absolute_import
from __future__ import unicode_literals

__version__ = 'dev'
__author__ = 'Martin Larralde'
__author_email__ = 'martin.larralde@ens-paris-saclay.fr'
__license__ = "MIT"

from .ontology import Ontology
from .term import Term, TermList
from .relationship import Relationship
from .synonym import Synonym, SynonymType
from .description import Description

# Dynamically get the version of the installed module
try:
    import pkg_resources
    __version__ = pkg_resources.get_distribution(__name__).version
except Exception:
    pkg_resources = None
finally:
    del pkg_resources

Add `Description` to top-level imports

Add `Description` to top-level imports


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

from django.db import models
from django_orm.postgresql.fields.arrays import ArrayField
from django_orm.postgresql.fields.interval import IntervalField
from django_orm.postgresql.fields.bytea import ByteaField
from django_orm.postgresql.manager import PgManager

class IntModel(models.Model):
    lista = ArrayField(dbtype='int')
    objects = PgManager()

class TextModel(models.Model):
    lista = ArrayField(dbtype='text')
    objects = PgManager()

class DoubleModel(models.Model):
    lista = ArrayField(dbtype='double precision')
    objects = PgManager()

class VarcharModel(models.Model):
    lista = ArrayField(dbtype='varchar(40)')
    objects = PgManager()

class IntervalModel(models.Model):
    iv = IntervalField()
    objects = PgManager()

class ByteaModel(models.Model):
    bb = ByteaField()
    objects = PgManager()

from django_orm.postgresql.geometric.fields import PointField, CircleField
from django_orm.postgresql.geometric.fields import LsegField, BoxField
from django_orm.postgresql.geometric.fields import PathField, PolygonField

class GeomModel(models.Model):
    pt = PointField()
    pl = PolygonField()
    ln = LsegField()
    bx = BoxField()
    cr = CircleField()
    ph = PathField()

    objects = PgManager()

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

from django.db import models
from django_orm.postgresql.fields.arrays import ArrayField
from django_orm.postgresql.fields.interval import IntervalField
from django_orm.postgresql.fields.bytea import ByteaField
from django_orm.manager import Manager

class IntModel(models.Model):
    lista = ArrayField(dbtype='int')
    objects = Manager()

class TextModel(models.Model):
    lista = ArrayField(dbtype='text')
    objects = Manager()

class DoubleModel(models.Model):
    lista = ArrayField(dbtype='double precision')
    objects = Manager()

class VarcharModel(models.Model):
    lista = ArrayField(dbtype='varchar(40)')
    objects = Manager()

class IntervalModel(models.Model):
    iv = IntervalField()
    objects = Manager()

class ByteaModel(models.Model):
    bb = ByteaField()
    objects = Manager()

from django_orm.postgresql.geometric.fields import PointField, CircleField
from django_orm.postgresql.geometric.fields import LsegField, BoxField
from django_orm.postgresql.geometric.fields import PathField, PolygonField

class GeomModel(models.Model):
    pt = PointField()
    pl = PolygonField()
    ln = LsegField()
    bx = BoxField()
    cr = CircleField()
    ph = PathField()

    objects = Manager()

Fix tests with last changes on api.

Fix tests with last changes on api.


from .base_settings import *
import os

INSTALLED_APPS += [
    'data_aggregator.apps.DataAggregatorConfig',
    'webpack_loader',
]

if os.getenv('ENV') == 'localdev':
    DEBUG = True
    DATA_AGGREGATOR_ACCESS_GROUP = 'u_test_group'
    DATA_AGGREGATOR_THREADING_ENABLED = False
    RESTCLIENTS_DAO_CACHE_CLASS = None
    DATA_AGGREGATOR_THREADING_ENABLED = False
else:
    DATA_AGGREGATOR_ACCESS_GROUP = os.getenv('ACCESS_GROUP', '')
    DATA_AGGREGATOR_THREADING_ENABLED = True

WEBPACK_LOADER = {
    'DEFAULT': {
        'BUNDLE_DIR_NAME': 'data_aggregator/bundles/',
        'STATS_FILE': os.path.join(BASE_DIR, 'data_aggregator', 'static', 'webpack-stats.json'),
    }
}

RESTCLIENTS_CANVAS_POOL_SIZE = 100
ACADEMIC_CANVAS_ACCOUNT_ID = '84378'

from .base_settings import *
import os

INSTALLED_APPS += [
    'data_aggregator.apps.DataAggregatorConfig',
    'webpack_loader',
]

if os.getenv('ENV') == 'localdev':
    DEBUG = True
    DATA_AGGREGATOR_ACCESS_GROUP = 'u_test_group'
    DATA_AGGREGATOR_THREADING_ENABLED = False
    RESTCLIENTS_DAO_CACHE_CLASS = None
    DATA_AGGREGATOR_THREADING_ENABLED = False
else:
    DATA_AGGREGATOR_ACCESS_GROUP = os.getenv('ACCESS_GROUP', '')
    DATA_AGGREGATOR_THREADING_ENABLED = True

WEBPACK_LOADER = {
    'DEFAULT': {
        'BUNDLE_DIR_NAME': 'data_aggregator/bundles/',
        'STATS_FILE': os.path.join(BASE_DIR, 'data_aggregator', 'static', 'webpack-stats.json'),
    }
}

RESTCLIENTS_CANVAS_POOL_SIZE = 50
ACADEMIC_CANVAS_ACCOUNT_ID = '84378'

Revert "Increase rest client pool size to 100"


"""Django page CMS test suite module"""
from djangox.test.depth import alltests

def suite():
    return alltests(__file__, __name__)

"""Django page CMS test suite module"""
import unittest

def suite():
    suite = unittest.TestSuite()
    from pages.tests.test_functionnal import FunctionnalTestCase
    from pages.tests.test_unit import UnitTestCase
    from pages.tests.test_regression import RegressionTestCase
    from pages.tests.test_pages_link import LinkTestCase
    from pages.tests.test_auto_render import AutoRenderTestCase
    suite.addTest(unittest.makeSuite(FunctionnalTestCase))
    suite.addTest(unittest.makeSuite(UnitTestCase))
    suite.addTest(unittest.makeSuite(RegressionTestCase))
    suite.addTest(unittest.makeSuite(LinkTestCase))
    suite.addTest(unittest.makeSuite(AutoRenderTestCase))
    return suite

Remove the dependency to django-unittest-depth


"""Utils macros

Utility macros
"""

def macros(macro, environ, *args, **kwargs):
    """Return a list of available macros"""

    s = "\n".join(["* %s" % k for k in environ["macros"].keys()])

    return environ["parser"].generate(s, environ=environ)

"""Utils macros

Utility macros
"""

from inspect import getdoc

def macros(macro, environ, *args, **kwargs):
    """Return a list of available macros"""

    macros = environ["macros"].items()
    s = "\n".join(["== %s ==\n%s\n" % (k, getdoc(v)) for k, v in macros])

    return environ["parser"].generate(s, environ=environ)

Change the output of <<macros>>

examples/web/wiki: Change the output of <<macros>>


from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
import views.charts
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'stats_app.views.home', name='home'),
    # url(r'^stats_app/', include('stats_app.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^graph.png$', views.charts.display_graph, name='graph'),
    url(r'^charts.html$', views.charts.display_full_page, name='graph_page'),
)

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
import views.charts
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'stats_app.views.home', name='home'),
    # url(r'^stats_app/', include('stats_app.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^graph.png$', views.charts.display_graph, name='graph'),
    url(r'^$', views.charts.display_full_page, name='graph_page'),
)

Make graphs show up at http://<domain-name> instead


# -*- encoding:utf-8 -*-
# Template tag
from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    if start == today:
        result += "aujourd'hui "
    else:
        result += "le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    return result

# -*- encoding:utf-8 -*-
# Template tag
from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template
import locale

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    # Hack! get the correct user local from the request
    loc = locale.getlocale()
    locale.setlocale(locale.LC_ALL, 'fr_CA.UTF8')

    if start == today:
        result += "Aujourd'hui "
    else:
        result += "Le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    locale.setlocale(locale.LC_ALL, loc)
    return result

Print date in fr_CA locale

hack: Print date in fr_CA locale


import numpy
import theano
import theano.tensor as T

class Linear():

	def __init__(self, rng, input, n_in, n_out, W=None, b=None):

		self.input = input

		if W is None:
			W_values = numpy.asarray(
				rng.uniform(
					low = -0.01, #low=-numpy.sqrt(6. / (n_in + n_out)),
					high = 0.01, #high=numpy.sqrt(6. / (n_in + n_out)),
					size=(n_in, n_out)
				),
				dtype=theano.config.floatX
			)
			W = theano.shared(value=W_values, name='W', borrow=True)

		if b is None:
			b_values = numpy.zeros((n_out,), dtype=theano.config.floatX)
			b = theano.shared(value=b_values, name='b', borrow=True)

		self.W = W
		self.b = b

		self.output = T.dot(input, self.W) + self.b

		# parameters of the model
		self.params = [self.W, self.b]

import numpy
import theano
import theano.tensor as T

class Linear():

	def __init__(self, rng, input, n_in, n_out, W_values=None, b_values=None):

		self.input = input

		if W_values is None:
			W_values = numpy.asarray(
				rng.uniform(
					low = -0.01, #low=-numpy.sqrt(6. / (n_in + n_out)),
					high = 0.01, #high=numpy.sqrt(6. / (n_in + n_out)),
					size=(n_in, n_out)
				),
				dtype=theano.config.floatX
			)
		W = theano.shared(value=W_values, name='W', borrow=True)

		if b_values is None:
			b_values = numpy.zeros((n_out,), dtype=theano.config.floatX)
		#	b_values = numpy.asarray(
		#		rng.uniform(
		#			low = -0.01, #low=-numpy.sqrt(6. / (n_in + n_out)),
		#			high = 0.01, #high=numpy.sqrt(6. / (n_in + n_out)),
		#			size=(n_out,)
		#		),
		#		dtype=theano.config.floatX
			)
		b = theano.shared(value=b_values, name='b', borrow=True)

		self.W = W
		self.b = b

		self.output = T.dot(input, self.W) + self.b

		# parameters of the model
		self.params = [self.W, self.b]

Initialize from argument or using a uniform distribution


VERSION = (0, 8, 4, "pbs", 7)
__version__ = '.'.join(map(str, VERSION))

VERSION = (0, 8, 4, "pbs", 8)
__version__ = '.'.join(map(str, VERSION))

Bump version as instructed by bamboo.

Bump version as instructed by bamboo.


# -*- coding: utf-8 -*-
'''
Manage RDP Service on Windows servers
'''

def __virtual__():
    '''
    Load only if network_win is loaded
    '''
    return 'rdp' if 'rdp.enable' in __salt__ else False

def enabled(name):
    '''
    Enable RDP the service on the server
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    stat = __salt__['rdp.status']()
    if not stat:
        ret['changes'] = {'enabled rdp': True}

    if __opts__['test']:
        ret['result'] = None
        return ret

    ret['result'] = __salt__['rdp.enable']()
    return ret

def disabled(name):
    '''
    Disable RDP the service on the server
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    stat = __salt__['rdp.status']()
    if stat:
        ret['changes'] = {'disable rdp': True}

    if __opts__['test']:
        return ret

    ret['result'] = __salt__['rdp.disable']()
    return ret

# -*- coding: utf-8 -*-
'''
Manage RDP Service on Windows servers
'''

def __virtual__():
    '''
    Load only if network_win is loaded
    '''
    return 'rdp' if 'rdp.enable' in __salt__ else False

def enabled(name):
    '''
    Enable RDP the service on the server
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    stat = __salt__['rdp.status']()
    if not stat:
        ret['changes'] = {'enabled rdp': True}

    if __opts__['test']:
        ret['result'] = stat
        return ret

    ret['result'] = __salt__['rdp.enable']()
    return ret

def disabled(name):
    '''
    Disable RDP the service on the server
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    stat = __salt__['rdp.status']()
    if stat:
        ret['changes'] = {'disable rdp': True}

    if __opts__['test']:
        ret['result'] = stat
        return ret

    ret['result'] = __salt__['rdp.disable']()
    return ret

Return proper results for 'test=True'

Return proper results for 'test=True'


import os.path
import sys

from perf.tests import get_output
from perf.tests import unittest

class SystemTests(unittest.TestCase):
    def test_show(self):
        args = [sys.executable, '-m', 'perf', 'system', 'show']
        proc = get_output(args)

        regex = ('(Run "%s -m perf system tune" to tune the system configuration to run benchmarks'
                 '|OK! System ready for benchmarking'
                 '|WARNING: no operation available for your platform)'
                 % os.path.basename(sys.executable))
        self.assertRegex(proc.stdout, regex, msg=proc)

        self.assertEqual(proc.returncode, 2, msg=proc)

if __name__ == "__main__":
    unittest.main()

import os.path
import sys

from perf.tests import get_output
from perf.tests import unittest

class SystemTests(unittest.TestCase):
    def test_show(self):
        args = [sys.executable, '-m', 'perf', 'system', 'show']
        proc = get_output(args)

        regex = ('(Run "%s -m perf system tune" to tune the system configuration to run benchmarks'
                 '|OK! System ready for benchmarking'
                 '|WARNING: no operation available for your platform)'
                 % os.path.basename(sys.executable))
        self.assertRegex(proc.stdout, regex, msg=proc)

        # The return code is either 0 if the system is tuned or 2 if the
        # system isn't
        self.assertIn(proc.returncode, (0, 2), msg=proc)

if __name__ == "__main__":
    unittest.main()

Fix test_show test to support tuned systems


#!/usr/bin/env python
# encoding: utf-8

from __future__ import absolute_import, unicode_literals
from .text_exporter import TextExporter
from .util import get_tags_count

class TagExporter(TextExporter):
    """This Exporter can convert entries and journals into json."""
    names = ["tags"]
    extension = "tags"

    @classmethod
    def export_entry(cls, entry):
        """Returns a markdown representation of a single entry."""
        return ", ".join(entry.tags)

    @classmethod
    def export_journal(cls, journal):
        """Returns a json representation of an entire journal."""
        tag_counts = get_tags_count(journal)
        result = ""
        if not tag_counts:
            return '[No tags found in journal.]'
        elif min(tag_counts)[0] == 0:
            tag_counts = filter(lambda x: x[0] > 1, tag_counts)
            result += '[Removed tags that appear only once.]\n'
        result += "\n".join("{0:20} : {1}".format(tag, n) for n, tag in sorted(tag_counts, reverse=True))
        return result

#!/usr/bin/env python
# encoding: utf-8

from __future__ import absolute_import, unicode_literals
from .text_exporter import TextExporter
from .util import get_tags_count

class TagExporter(TextExporter):
    """This Exporter can lists the tags for entries and journals, exported as a plain text file."""
    names = ["tags"]
    extension = "tags"

    @classmethod
    def export_entry(cls, entry):
        """Returns a list of tags for a single entry."""
        return ", ".join(entry.tags)

    @classmethod
    def export_journal(cls, journal):
        """Returns a list of tags and their frequency for an entire journal."""
        tag_counts = get_tags_count(journal)
        result = ""
        if not tag_counts:
            return '[No tags found in journal.]'
        elif min(tag_counts)[0] == 0:
            tag_counts = filter(lambda x: x[0] > 1, tag_counts)
            result += '[Removed tags that appear only once.]\n'
        result += "\n".join("{0:20} : {1}".format(tag, n) for n, tag in sorted(tag_counts, reverse=True))
        return result

Update `Tag` exporter code documentation.


import rx
import concurrent.futures
import time

seconds = [5, 1, 2, 4, 3]

def sleep(t):
    time.sleep(t)
    return t

def output(result):
    print '%d seconds' % result

with concurrent.futures.ProcessPoolExecutor(5) as executor:
    rx.Observable.from_(seconds).flat_map(
        lambda s: executor.submit(sleep, s)
    ).subscribe(output)

# 1 seconds
# 2 seconds
# 3 seconds
# 4 seconds
# 5 seconds

from __future__ import print_function

import rx
import concurrent.futures
import time

seconds = [5, 1, 2, 4, 3]

def sleep(t):
    time.sleep(t)
    return t

def output(result):
    print('%d seconds' % result)

with concurrent.futures.ProcessPoolExecutor(5) as executor:
    rx.Observable.from_(seconds).flat_map(
        lambda s: executor.submit(sleep, s)
    ).subscribe(output)

# 1 seconds
# 2 seconds
# 3 seconds
# 4 seconds
# 5 seconds

Fix parallel example for Python 3

Fix parallel example for Python 3


"""
Module with the HardwareDevice model.
"""

from launch_control.utils.json import PlainOldData

class HardwareDevice(PlainOldData):
    """
    Model representing any HardwareDevice

    A device is just a "device_type" attribute with a bag of properties
    and a human readable description. Individual device types can be
    freely added. For simplicity some common types of devices are
    provided as class properties DEVICE_xxx.

    Instances will come from a variety of factory classes, each capable
    of enumerating devices that it understands. The upside of having a
    common class like this is that it's easier to store it in the
    database _and_ not have to agree on a common set of properties for,
    say, all CPUs.

    If you want you can create instances manually, like this:
    >>> cpu = HardwareDevice(HardwareDevice.DEVICE_CPU,
    ...     u"800MHz OMAP3 Processor")
    >>> cpu.attributes[u'machine'] = u'arm'
    >>> cpu.attributes[u'mhz'] = '800'
    >>> cpu.attributes[u'vendor'] = u'Texas Instruments'
    """

    DEVICE_CPU = "device.cpu"
    DEVICE_MEM = "device.mem"
    DEVICE_USB = "device.usb"
    DEVICE_PCI = "device.pci"
    DEVICE_BOARD = "device.board"

    __slots__ = ('device_type', 'desc', 'attributes')

    def __init__(self, device_type, description, attributes=None):
        self.device_type = device_type
        self.description = description
        self.attributes = attributes or {}

"""
Module with the HardwareDevice model.
"""

from launch_control.utils.json import PlainOldData

class HardwareDevice(PlainOldData):
    """
    Model representing any HardwareDevice

    A device is just a "device_type" attribute with a bag of properties
    and a human readable description. Individual device types can be
    freely added. For simplicity some common types of devices are
    provided as class properties DEVICE_xxx.

    Instances will come from a variety of factory classes, each capable
    of enumerating devices that it understands. The upside of having a
    common class like this is that it's easier to store it in the
    database _and_ not have to agree on a common set of properties for,
    say, all CPUs.

    If you want you can create instances manually, like this:
    >>> cpu = HardwareDevice(HardwareDevice.DEVICE_CPU,
    ...     u"800MHz OMAP3 Processor")
    >>> cpu.attributes[u'machine'] = u'arm'
    >>> cpu.attributes[u'mhz'] = '800'
    >>> cpu.attributes[u'vendor'] = u'Texas Instruments'
    """

    DEVICE_CPU = "device.cpu"
    DEVICE_MEM = "device.mem"
    DEVICE_USB = "device.usb"
    DEVICE_PCI = "device.pci"
    DEVICE_BOARD = "device.board"

    __slots__ = ('device_type', 'description', 'attributes')

    def __init__(self, device_type, description, attributes=None):
        self.device_type = device_type
        self.description = description
        self.attributes = attributes or {}

Fix slot name in HardwareDevice

Fix slot name in HardwareDevice


from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, HTML, Submit, Button, Fieldset
from django.forms import ModelForm, Textarea
from core.models import Game

class GameForm(ModelForm):
    class Meta:
        model = Game
        exclude = ['owner', 'date_published']
        widgets = {
            'description': Textarea(attrs={'cols': 100, 'rows': 15})
        }

    def __init__(self, *args, **kwargs):
        super(GameForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                '{{ heading }}',
                'name',
                'description',
                'link',
                HTML("""{% if form.image.value %}<img class="img-responsive" src="{{ MEDIA_URL }}{{ form.image.value }}">
                {% endif %}"""),
                'image',
                'tags',
                'group',
                'event_name',
                'game_file'
            ),
            FormActions(
                Submit('save', 'Save'),
                Button('cancel', 'Cancel', onclick='history.go(-1);', css_class="btn-default")
            )
        )

from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, HTML, Submit, Button, Fieldset
from django.forms import ModelForm, Textarea
from core.models import Game

class GameForm(ModelForm):
    class Meta:
        model = Game
        exclude = ['owner', 'date_published']
        widgets = {
            'description': Textarea(attrs={'cols': 100, 'rows': 15})
        }

    def __init__(self, *args, **kwargs):
        super(GameForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                '{{ heading }}',
                'name',
                'description',
                HTML("""{% if form.image.value %}<img class="img-responsive" src="{{ MEDIA_URL }}{{ form.image.value }}">
                {% endif %}"""),
                'image',
                'tags',
                'group',
                'event_name',
                'game_file'
            ),
            FormActions(
                Submit('save', 'Save'),
                Button('cancel', 'Cancel', onclick='history.go(-1);', css_class="btn-default")
            )
        )

Remove unused field from game form

Remove unused field from game form


import pytest

from tests.lib import PipTestEnvironment

@pytest.mark.network
def test_timeout(script: PipTestEnvironment) -> None:
    result = script.pip(
        "--timeout",
        "0.0001",
        "install",
        "-vvv",
        "INITools",
        expect_error=True,
    )
    assert (
        "Could not fetch URL https://pypi.org/simple/initools/: "
        "connection error: HTTPSConnectionPool(host='pypi.org', port=443): "
        "Max retries exceeded with url: /simple/initools/ "
    ) in result.stdout

import pytest

from tests.lib import PipTestEnvironment

@pytest.mark.network
def test_timeout(script: PipTestEnvironment) -> None:
    result = script.pip(
        "--timeout",
        "0.00001",
        "install",
        "-vvv",
        "INITools",
        expect_error=True,
    )
    assert (
        "Could not fetch URL https://pypi.org/simple/initools/: "
        "connection error: HTTPSConnectionPool(host='pypi.org', port=443): "
        "Max retries exceeded with url: /simple/initools/ "
    ) in result.stdout

Decrease timeout to make test less flaky


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

import os
import sys
sys.path.append('./../../')

from pyogi.ki2converter import *
from pyogi.kifu import *

if __name__ == '__main__':

    for n in range(0, 50000):

        n1 = (n // 10000)
        n2 = int(n < 10000)

        relpath = '~/data/shogi/2chkifu/{0}000{1}/{2:0>5}.KI2'.format(n1, n2, n)
        kifile = os.path.expanduser(relpath)

        if not os.path.exists(kifile):
            continue

        ki2converter = Ki2converter()
        ki2converter.from_path(kifile)

        csa = ki2converter.to_csa()

        kifu = Kifu(csa)
        res = kifu.get_forking(['OU', 'HI'])
        if res[2] or res[3]:
            print(kifu.players)

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

import os
import sys
import pandas as pd
sys.path.append('./../../')

from pyogi.ki2converter import *
from pyogi.kifu import *

if __name__ == '__main__':

    res_table = []

    for n in range(0, 50000):

        n1 = (n // 10000)
        n2 = int(n < 10000)

        relpath = '~/data/shogi/2chkifu/{0}000{1}/{2:0>5}.KI2'.format(n1, n2, n)
        kifile = os.path.expanduser(relpath)

        if not os.path.exists(kifile):
            continue

        ki2converter = Ki2converter()
        ki2converter.from_path(kifile)

        csa = ki2converter.to_csa()

        if not csa:
            continue

        kifu = Kifu(csa)
        res = kifu.get_forking(['OU', 'HI'])
        if res[2] or res[3]:
            print(kifu.players)

        # Output
        # 1. sente forked | gote forked
        # 2. (sente won & sente forked) | (gote won & gote forked)
        res_table.append(
            [res[2] != [] or res[3] != [],
             (kifu.sente_win and res[2]!=[]) or
             ((not kifu.sente_win) and res[3]!=[])])

    df = pd.DataFrame(res_table, columns=['fork', 'fork&win'])
    pd.crosstab(df.loc[:, 'fork'], df.loc[:, 'fork&win'])

Add sum up part using pd.crosstab

Add sum up part using pd.crosstab


import json
from flask import Blueprint, render_template

import database as db
from database.model import Team

bp = Blueprint('public', __name__)

@bp.route("/map")
def map_page():
    return render_template("public/map.html")

@bp.route("/map_teams")
def map_teams():
    qry = db.session.query(Team).filter_by(confirmed=True).filter_by(deleted=False).filter_by(backup=False)
    data = []
    for item in qry:
        if item.location is not None:
            data.append({"lat": item.location.lat,
                         "lon": item.location.lon,
                         "name": item.name})
    return json.dumps(data)

import json
from flask import Blueprint, render_template

import database as db
from database.model import Team

bp = Blueprint('public', __name__)

@bp.route("/map")
def map_page():
    return render_template("public/map.html")

@bp.route("/map_teams")
def map_teams():
    qry = db.session.query(Team).filter_by(confirmed=True).filter_by(deleted=False).filter_by(backup=False)
    data_dict = {}
    for item in qry:
        if item.location is not None:
            ident = "%s%s" % (item.location.lat, item.location.lon)
            if ident not in data_dict:
                data_dict[ident] = {
                    "lat": item.location.lat,
                     "lon": item.location.lon,
                     "name": item.name
                }
            else:
                data_dict[ident]["name"] += "<br>" + item.name
    data = [entry for entry in data_dict.itervalues()]
    return json.dumps(data)

Add multi team output in markers

Add multi team output in markers

Signed-off-by: Dominik Pataky <46f1a0bd5592a2f9244ca321b129902a06b53e03@netdecorator.org>


from django.views.generic import TemplateView

from admin.base.settings import KEEN_CREDENTIALS

from admin.base.utils import OSFAdmin

class MetricsView(OSFAdmin, TemplateView):
    template_name = 'metrics/osf_metrics.html'

    def get_context_data(self, **kwargs):

        kwargs.update(KEEN_CREDENTIALS.copy())
        return super(MetricsView, self).get_context_data(**kwargs)

from django.views.generic import TemplateView
from django.contrib.auth.mixins import PermissionRequiredMixin

from admin.base.settings import KEEN_CREDENTIALS

from admin.base.utils import OSFAdmin

class MetricsView(OSFAdmin, TemplateView, PermissionRequiredMixin):
    template_name = 'metrics/osf_metrics.html'
    permission_required = 'admin.view_metrics'

    def get_context_data(self, **kwargs):

        kwargs.update(KEEN_CREDENTIALS.copy())
        return super(MetricsView, self).get_context_data(**kwargs)

Add view metrics permission to metrics view


#!/usr/bin/env python
# encoding: utf-8
"""
"""
from bottle import route, run, template, request
import urllib2
import urllib

import sys
import os
from whoosh.index import create_in, open_dir
from whoosh.fields import *
from whoosh.qparser import QueryParser, MultifieldParser
from whoosh.query import *

@route('/')
def index():
  return template('search')

@route('/epsg',method="POST")
def index():
  ix = open_dir("../index")
  result = []
  with ix.searcher(closereader=False) as searcher:
    parser = MultifieldParser(["code","name","area","type"], ix.schema)
    query = request.POST.get('fulltext').strip()
    myquery = parser.parse(query)

    results = searcher.search(myquery, limit = 600)

    num_results = len(results)

    for r in results:
      result.append(r)

  return template('results',result=result, query=query,num_results=num_results)

run(host='localhost', port=8080)

#!/usr/bin/env python
# encoding: utf-8
"""
"""
from bottle import route, run, template, request
import urllib2
import urllib

import sys
import os
from whoosh.index import create_in, open_dir
from whoosh.fields import *
from whoosh.qparser import QueryParser, MultifieldParser
from whoosh.query import *

@route('/')
def index():
  return template('search')

@route('/epsg',method="POST")
def index():
  ix = open_dir("../index")
  result = []
  with ix.searcher(closereader=False) as searcher:
    parser = MultifieldParser(["code","name","area","type"], ix.schema)
    query = request.POST.get('fulltext').strip()
    select = request.POST.get('type').strip()
    status = request.POST.get('invalid')
    print status, "status"
    if status == None:
      status = u"Valid"
    print status, "status2"

    query = query + " type:" + select + " status:" + status # change status from id tu text
    print query
    myquery = parser.parse(query)

    results = searcher.search(myquery, limit = 600)

    num_results = len(results)

    for r in results:
      result.append(r)

  return template('results',result=result, query=query,num_results=num_results)

run(host='localhost', port=8080)

Add advanced search by select type or status


# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

from __future__ import print_function

import responses
import simplesqlite
from click.testing import CliRunner
from sqlitebiter._enum import ExitCode
from sqlitebiter.sqlitebiter import cmd

from .common import print_traceback
from .dataset import complex_json

class Test_TableUrlLoader(object):

    @responses.activate
    def test_normal(self):
        url = "https://example.com/complex_jeson.json"
        responses.add(
            responses.GET,
            url,
            body=complex_json,
            content_type='text/plain; charset=utf-8',
            status=200)
        runner = CliRunner()
        db_path = "test_complex_json.sqlite"

        with runner.isolated_filesystem():
            result = runner.invoke(cmd, ["url", url, "-o", db_path])
            print_traceback(result)

            assert result.exit_code == ExitCode.SUCCESS

            con = simplesqlite.SimpleSQLite(db_path, "r")
            expected = set([
                'ratings', 'screenshots_4', 'screenshots_3', 'screenshots_5', 'screenshots_1',
                'screenshots_2', 'tags', 'versions', 'root'])

            assert set(con.get_table_name_list()) == expected

# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

from __future__ import print_function

import responses
import simplesqlite
from click.testing import CliRunner
from sqlitebiter._enum import ExitCode
from sqlitebiter.sqlitebiter import cmd

from .common import print_traceback
from .dataset import complex_json

class Test_url_subcommand(object):

    @responses.activate
    def test_normal(self):
        url = "https://example.com/complex_jeson.json"
        responses.add(
            responses.GET,
            url,
            body=complex_json,
            content_type='text/plain; charset=utf-8',
            status=200)
        runner = CliRunner()
        db_path = "test_complex_json.sqlite"

        with runner.isolated_filesystem():
            result = runner.invoke(cmd, ["url", url, "-o", db_path])
            print_traceback(result)

            assert result.exit_code == ExitCode.SUCCESS

            con = simplesqlite.SimpleSQLite(db_path, "r")
            expected = set([
                'ratings', 'screenshots_4', 'screenshots_3', 'screenshots_5', 'screenshots_1',
                'screenshots_2', 'tags', 'versions', 'root'])

            assert set(con.get_table_name_list()) == expected

Fix a test class name

Fix a test class name


#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
import youtube_dl_server as ydl_server

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
    'sphinxcontrib.httpdomain',
]

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'youtube-dl-api-server'
copyright = '2013, Jaime Marquínez Ferrándiz'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = ydl_server.__version__
# The short X.Y version.
version = '.'.join(release.split('.')[:2])

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import datetime
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
import youtube_dl_server as ydl_server

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
    'sphinxcontrib.httpdomain',
]

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'youtube-dl-api-server'
copyright = '2013-{now:%Y}, Jaime Marquínez Ferrándiz'.format(now=datetime.datetime.now())

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = ydl_server.__version__
# The short X.Y version.
version = '.'.join(release.split('.')[:2])

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']

Use the current year in the copyright

docs: Use the current year in the copyright


Bump version to clean releases

Bump version to clean releases


"""A pytest plugin for using pyfakefs as a fixture

When pyfakefs is installed, the "fs" fixture becomes available.

:Usage:

def my_fakefs_test(fs):
    fs.create_file('/var/data/xx1.txt')
    assert os.path.exists('/var/data/xx1.txt')
"""
import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher

Patcher.SKIPMODULES.add(py)  # Ignore pytest components when faking filesystem

@pytest.fixture
def fs(request):
    """ Fake filesystem. """
    patcher = Patcher()
    patcher.setUp()
    request.addfinalizer(patcher.tearDown)
    return patcher.fs

"""A pytest plugin for using pyfakefs as a fixture

When pyfakefs is installed, the "fs" fixture becomes available.

:Usage:

def my_fakefs_test(fs):
    fs.create_file('/var/data/xx1.txt')
    assert os.path.exists('/var/data/xx1.txt')
"""
import linecache

import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher

Patcher.SKIPMODULES.add(py)  # Ignore pytest components when faking filesystem
Patcher.SKIPMODULES.add(linecache)  # Seems to be used by pytest internally

@pytest.fixture
def fs(request):
    """ Fake filesystem. """
    patcher = Patcher()
    patcher.setUp()
    request.addfinalizer(patcher.tearDown)
    return patcher.fs

Add linecache module to skipped modules for pytest plugin

- see #381
- fixes the problem under Python 3, but not under Python 2


"""
This package contains core modules and classes for representing structures and
operations on them.
"""

__author__ = "Shyue Ping Ong"
__date__ = "Dec 15, 2010 7:21:29 PM"

from .periodic_table import *
from .composition import *
from .structure import *
from .structure_modifier import *
from .bonds import *
from .lattice import *
from .sites import *
from .operations import *
from .units import *

Add units to Core import.

Add units to Core import.

Former-commit-id: 0f1c678c7da36ebc85827601645f6729a11e5f41 [formerly 80676409b706f3927b463afef6aa844d00aeb107]
Former-commit-id: f99f3956f55a26845ce5ce583545a0413e4f36ce


"""Infiltration module.

"""
import numpy as np
from scipy.optimize import fsolve

def green_ampt_cum_infiltration(F, psi, dtheta, K, t):
    """The Green-Ampt cumulative infiltration equation.

    """
    tmp = psi*dtheta

    # np.log(x) computes ln(x)
    return F - tmp*np.log(1 + F/tmp) - K*t

if __name__ == '__main__':
    psi = 16.7
    dtheta = 0.34
    K = 0.65
    t = 1

    F = K*t # initial guess

    print fsolve(green_ampt_cum_infiltration,
                 F, args=(psi, dtheta, K, t), full_output=True)

"""Infiltration module.

"""
import numpy as np
from scipy.optimize import fsolve

def _green_ampt_cum_eq(F, psi, dtheta, K, t):
    """The Green-Ampt cumulative infiltration equation

    """
    tmp = psi*dtheta

    # np.log(x) computes ln(x)
    return F - tmp*np.log(1 + F/tmp) - K*t

def green_ampt_cum_infiltration(psi, dtheta, K, t):
    """Compute the Green-Ampt cumulative infiltration

    Compute the potential cumulative infiltration up to time `t`,
    using Green-Ampt.

    Parameters
    ----------
    psi : array_like
        Soil suction head at wetting front.
    dtheta : array_like
        Ratio of initial effective saturation to effective porosity.
    K : array_like
        Saturated hydraulic conductivity.
    t : array_like
        Time since beginning of event

    Returns
    -------
    soln : array_like
        Cumulative infiltration up to time `t`.

    Raises
    ------
    ValueError - If no solution can be found.

    """

    F = K*t # initial guess

    soln, infodict, ierr, mesg = fsolve(_green_ampt_cum_eq, F,
                                        args=(psi, dtheta, K, t),
                                        full_output=True)

    if ierr == 1:
        return soln
    else:
        raise ValueError(mesg)

def test_basic_green_ampt():
    """Test the Green-Ampt cumulative infiltration solution"""

    psi = 16.7
    dtheta = 0.34
    K = 0.65
    t = 1

    result = green_ampt_cum_infiltration(psi, dtheta, K, t)

    assert np.allclose(result, [3.16641923])

ENH: Change the API and add a test and documentation


import sys, os

if sys.version_info >= (2, 4):
    import doctest
else:
    raise ImportError("Python 2.4 doctest required")

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

def test():
    for doc in ['SQLObject.txt']:
        doctest.testfile(doc, optionflags=doctest.ELLIPSIS)

if __name__ == '__main__':
    test()

import sys, os

if sys.version_info >= (2, 4):
    import doctest
else:
    raise ImportError("Python 2.4 doctest required")

sys.path.insert(
    0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

def test():
    for doc in ['SQLObject.txt']:
        doctest.testfile(doc, optionflags=doctest.ELLIPSIS)

if __name__ == '__main__':
    test()

Make sure checkout is first on sys.path

Make sure checkout is first on sys.path

git-svn-id: fe2f45b2405132b4a9af5caedfc153c2e6f542f4@894 95a46c32-92d2-0310-94a5-8d71aeb3d4b3


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

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
project = u'dotnetexample'
copyright = u'2015, rtfd'
author = u'rtfd'
version = '0.1'
release = '0.1'
language = None
exclude_patterns = ['_build']
pygments_style = 'sphinx'
todo_include_todos = False
html_theme = 'sphinx_rtd_theme'
htmlhelp_basename = 'dotnetexampledoc'
extensions = ['autoapi.extension', 'sphinxcontrib.dotnetdomain']

autoapi_type = 'dotnet'
autoapi_dir = 'example/Identity/src/'
autoapi_keep_files = True

import os

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
DIR = os.path.join(SITE_ROOT, autoapi_dir)
if not os.path.exists(DIR):
    os.system('git clone https://github.com/aspnet/Identity %s' % os.path.join(SITE_ROOT, 'example/Identity'))

Make sure example repo exists

Make sure example repo exists


from rest_framework import serializers
from measurement.models import Measurement
from threshold_value.models import ThresholdValue
from calendar import timegm
from alarm.models import Alarm

class GraphSeriesSerializer(serializers.ModelSerializer):
    x = serializers.SerializerMethodField('get_time')
    y = serializers.SerializerMethodField('get_value')

    class Meta:
        fields = ['x', 'y']

    def get_time(self, obj):
        return int(timegm(obj.time.utctimetuple())) * 1000  # Milliseconds since epoch, UTC

    def get_value(self, obj):
        return obj.value

class MeasurementGraphSeriesSerializer(GraphSeriesSerializer):
    alarm = serializers.SerializerMethodField('get_alarm')

    def __init__(self, *args, **kwargs):
        self.alarm_dict = kwargs.pop('alarm_dict', None)
        super(MeasurementGraphSeriesSerializer, self).__init__(*args, **kwargs)
        if not self.alarm_dict:
            self.fields.pop('alarm')

    def get_alarm(self, obj):
        if obj.id in self.alarm_dict:
            alarm = self.alarm_dict[obj.id]
            serializer = SimpleAlarmSerializer(alarm)
            return serializer.data
        return None

    class Meta(GraphSeriesSerializer.Meta):
        model = Measurement
        fields = GraphSeriesSerializer.Meta.fields + ['alarm']

class ThresholdValueGraphSeriesSerializer(GraphSeriesSerializer):
    class Meta(GraphSeriesSerializer.Meta):
        model = ThresholdValue

class SimpleAlarmSerializer(serializers.ModelSerializer):
    class Meta:
        model = Alarm
        fields = ('id', 'time_created', 'is_treated', 'treated_text')

from rest_framework import serializers
from measurement.models import Measurement
from threshold_value.models import ThresholdValue
from calendar import timegm
from alarm.models import Alarm

class GraphSeriesSerializer(serializers.ModelSerializer):
    x = serializers.SerializerMethodField('get_time')
    y = serializers.SerializerMethodField('get_value')

    class Meta:
        fields = ['x', 'y']

    def get_time(self, obj):
        return int(timegm(obj.time.utctimetuple())) * 1000  # Milliseconds since epoch, UTC

    def get_value(self, obj):
        return obj.value

class MeasurementGraphSeriesSerializer(GraphSeriesSerializer):
    alarm = serializers.SerializerMethodField('get_alarm')

    def __init__(self, *args, **kwargs):
        self.alarm_dict = kwargs.pop('alarm_dict', None)
        super(MeasurementGraphSeriesSerializer, self).__init__(*args, **kwargs)
        if not self.alarm_dict:
            self.fields.pop('alarm')

    def get_alarm(self, obj):
        if obj.id in self.alarm_dict:
            alarm = self.alarm_dict[obj.id]
            serializer = SimpleAlarmSerializer(alarm)
            return serializer.data
        return None

    class Meta(GraphSeriesSerializer.Meta):
        model = Measurement
        fields = GraphSeriesSerializer.Meta.fields + ['alarm']

class ThresholdValueGraphSeriesSerializer(GraphSeriesSerializer):
    class Meta(GraphSeriesSerializer.Meta):
        model = ThresholdValue

class SimpleAlarmSerializer(serializers.ModelSerializer):
    class Meta:
        model = Alarm
        fields = ['is_treated']

Simplify SimpleAlarmSerializer to improve the performance of the graph_data endpoint


#!/bin/env python
# -*- coding: utf8 -*-

import koji

def upload(builds):
    """ Takes a list of one or more Koji build IDs (passed to it from
    consumer.py) and sends the appropriate image files off to cloud
    services. """
    if isinstance(builds, list):
        for build in builds:
            pass
    else:
        # TODO: Not sure if this is the proper way to handle this.
        raise Exception("Build upload function must take a list.")
        return  # TODO: Does this need to go here?

#!/bin/env python
# -*- coding: utf8 -*-

import koji

from pprint import pprint

def upload(builds):
    """ Takes a list of one or more Koji build IDs (passed to it from
    consumer.py) and sends the appropriate image files off to cloud
    services. """
    if isinstance(builds, list):
        # Create a Koji connection to the Fedora Koji instance
        koji_server = "https://koji.fedoraproject.org/kojihub"
        koji_session = koji.ClientSession(koji_server)
        if len(builds) == 1:
            print "\nRESULTS FOR listTaskOutput():\n"
            pprint(koji_session.listTaskOutput())
            print "\nRESULTS FOR getTaskResult():\n"
            pprint(koji_session.getTaskResult())
        elif len(builds) >= 2:
            #koji.multicall = True
            for build in builds:
                print "\nPLACEHOLDER FOR MULTICALL BUILD SITUATION\n"
            #results = koji.multiCall()
            #koji.multicall = False  # TODO: Is this needed?
    else:
        # TODO: Not sure if this is the proper way to handle this.
        raise Exception("Build upload function must take a list.")
        return  # TODO: Does this need to go here?

Add some koji API code for testing getting build results/output.


import smbus
import time

ADDRESS = 4
CMD_READ_ANALOG = 1
VOLT12 = 650
VOLT18 = 978

def map_range(x, in_min, in_max, out_min, out_max):
    out_delta = out_max - out_min
    in_delta = in_max - in_min

    return (x - in_min) * out_delta / in_delta + out_min

class Voltage:
    def __init__(self):
        self.bus = smbus.SMBus(1)

    def get_data(self):
        voltage_time = time.time();
        voltage_raw = self.bus.read_word_data(ADDRESS, CMD_READ_ANALOG)
        voltage = map_range(voltage_raw, VOLT12, VOLT18, 12, 18)

        return [
            (voltage_time, "voltage_raw", voltage_raw),
            (voltage_time, "voltage", voltage)
        ]

import smbus
import time

ADDRESS = 4
CMD_READ_ANALOG = 1
VOLT12 = 650
VOLT18 = 978

def map_range(x, in_min, in_max, out_min, out_max):
    out_delta = out_max - out_min
    in_delta = in_max - in_min

    return (x - in_min) * out_delta / in_delta + out_min

class Voltage:
    def __init__(self):
        self.bus = smbus.SMBus(1)

    def get_data(self):
        voltage_time = time.time()
        voltage_raw = self.bus.read_word_data(ADDRESS, CMD_READ_ANALOG)
        voltage = map_range(voltage_raw, VOLT12, VOLT18, 12, 18)

        return [
            (voltage_time, "voltage_raw", voltage_raw),
            (voltage_time, "voltage", voltage)
        ]

Fix some minor formatting issues

Fix some minor formatting issues