import argparse
import sys

from . import eccodes

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--selfcheck', default=False, action='store_true')
    args = parser.parse_args()
    if args.selfcheck:
        eccodes.codes_get_api_version()
        print("Your system is ready.")
    else:
        raise RuntimeError("Command not recognised. See usage with --help.")

if __name__ == '__main__':
    main()

#
# Copyright 2017-2018 European Centre for Medium-Range Weather Forecasts (ECMWF).
#
# 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.
#
# Authors:
#   Alessandro Amici - B-Open - https://bopen.eu
#

import argparse

from . import eccodes

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--selfcheck', default=False, action='store_true')
    args = parser.parse_args()
    if args.selfcheck:
        eccodes.codes_get_api_version()
        print("Your system is ready.")
    else:
        raise RuntimeError("Command not recognised. See usage with --help.")

if __name__ == '__main__':
    main()

Add copyright noticeand Authors comment.


from django.contrib import admin

from .models import Post

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    # list view
    date_hierarchy = 'pub_date'
    list_display = ('title', 'pub_date')
    list_filter = ('pub_date',)
    search_fields = ('title', 'text')
    # form view
    fieldsets = (
        (None, {
            'fields': (
                'title', 'slug', 'author', 'text',
            )}),
        ('Related', {
            'fields': (
                'tags', 'startups')}),
    )
    filter_horizontal = ('startups',)
    filter_vertical = ('tags',)
    prepopulated_fields = {"slug": ("title",)}

from django.contrib import admin

from .models import Post

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    # list view
    date_hierarchy = 'pub_date'
    list_display = ('title', 'pub_date')
    list_filter = ('pub_date',)
    search_fields = ('title', 'text')
    # form view
    fieldsets = (
        (None, {
            'fields': (
                'title', 'slug', 'author', 'text',
            )}),
        ('Related', {
            'fields': (
                'tags', 'startups')}),
    )
    filter_horizontal = ('tags', 'startups',)
    prepopulated_fields = {"slug": ("title",)}

Ch23: Use horizontal filter for M2M in PostAdmin.


# Basic test of dynamic code generation
import unittest

import stdio
from ctypes import POINTER, c_int

class DynModTest(unittest.TestCase):
    def test_fopen(self):
        self.failUnlessEqual(stdio.fopen.restype, POINTER(stdio.FILE))
        self.failUnlessEqual(stdio.fopen.argtypes, [stdio.STRING, stdio.STRING])

    def test_constants(self):
        self.failUnlessEqual(stdio.O_RDONLY, 0)
        self.failUnlessEqual(stdio.O_WRONLY, 1)
        self.failUnlessEqual(stdio.O_RDWR, 2)

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

# Basic test of dynamic code generation
import unittest
import os, glob

import stdio
from ctypes import POINTER, c_int

class DynModTest(unittest.TestCase):
    def tearDown(self):
        for fnm in glob.glob(stdio._gen_basename + ".*"):
            try:
                os.remove(fnm)
            except IOError:
                pass

    def test_fopen(self):
        self.failUnlessEqual(stdio.fopen.restype, POINTER(stdio.FILE))
        self.failUnlessEqual(stdio.fopen.argtypes, [stdio.STRING, stdio.STRING])

    def test_constants(self):
        self.failUnlessEqual(stdio.O_RDONLY, 0)
        self.failUnlessEqual(stdio.O_WRONLY, 1)
        self.failUnlessEqual(stdio.O_RDWR, 2)

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

Clean up generated files in the tearDown method.

git-svn-id: ac2c3632cb6543e7ab5fafd132c7fe15057a1882@52711 6015fed2-1504-0410-9fe1-9d1591cc4771


# for local run, before pygraphc packaging
import sys
sys.path.insert(0, '../pygraphc/misc')
from LKE import *
sys.path.insert(0, '../pygraphc/clustering')
from ClusterUtility import *
from ClusterEvaluation import *

ip_address = '161.166.232.17'
standard_path = '/home/hudan/Git/labeled-authlog/dataset/' + ip_address
standard_file = standard_path + 'auth.log.anon.labeled'
analyzed_file = 'auth.log.anon'
prediction_file = 'lke-result-' + ip_address + '.txt'
OutputPath = './results'
para = Para(path=standard_path, logname=analyzed_file, save_path=OutputPath)

myparser = LKE(para)
time = myparser.main_process()
clusters = myparser.get_clusters()
original_logs = myparser.get_logs()

ClusterUtility.set_cluster_label_id(None, clusters, original_logs, prediction_file)
homogeneity_completeness_vmeasure = ClusterEvaluation.get_homogeneity_completeness_vmeasure(standard_file,
                                                                                prediction_file)

print homogeneity_completeness_vmeasure
print ('The running time of LKE is', time)

# for local run, before pygraphc packaging
import sys
sys.path.insert(0, '../pygraphc/misc')
from LKE import *
sys.path.insert(0, '../pygraphc/evaluation')
from ExternalEvaluation import *

ip_address = '161.166.232.17'
standard_path = '/home/hudan/Git/labeled-authlog/dataset/' + ip_address
standard_file = standard_path + 'auth.log.anon.labeled'
analyzed_file = 'auth.log.anon'
prediction_file = 'lke-result-' + ip_address + '.txt'
OutputPath = './results'
para = Para(path=standard_path, logname=analyzed_file, save_path=OutputPath)

myparser = LKE(para)
time = myparser.main_process()
clusters = myparser.get_clusters()
original_logs = myparser.logs

ExternalEvaluation.set_cluster_label_id(None, clusters, original_logs, prediction_file)
homogeneity_completeness_vmeasure = ExternalEvaluation.get_homogeneity_completeness_vmeasure(standard_file,
                                                                                prediction_file)

print homogeneity_completeness_vmeasure
print ('The running time of LKE is', time)

Change module path for cluster evaluation and edit how to get original logs


__VERSION__ = "0.0.3"
__AUTHOR__ = "GDS Developers"
__AUTHOR_EMAIL__ = ""

__VERSION__ = "0.0.4"
__AUTHOR__ = "GDS Developers"
__AUTHOR_EMAIL__ = ""

Bump version so as not to pull down bad logging


#! /usr/bin/env python

from subprocess import Popen, PIPE

def launch(cmd):
    """
    Fork the specified command, returning a tuple of (stdout, stderr)
    """
    return Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()

def get_stdout(cmd):
    """
    Fork the specified command, returning stdout
    """
    return launch(cmd)[0]

def get_stderr(cmd):
    """
    Fork the specified command, returning stderr
    """
    return launch(cmd)[1]

#! /usr/bin/env python

from subprocess import Popen, PIPE

def popen(cmd):
    """
    Fork the specified command, returning a tuple of (stdout, stderr)
    """
    return Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()

def get_stdout(cmd):
    """
    Fork the specified command, returning stdout
    """
    return popen(cmd)[0]

def get_stderr(cmd):
    """
    Fork the specified command, returning stderr
    """
    return popen(cmd)[1]

Switch to using popen as the function name to stick more to subprocess naming


# ACTION_CHECKBOX_NAME is unused, but should stay since its import from here
# has been referenced in documentation.
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
from django.contrib.admin.options import StackedInline, TabularInline
from django.contrib.admin.sites import AdminSite, site

def autodiscover():
    """
    Auto-discover INSTALLED_APPS admin.py modules and fail silently when
    not present. This forces an import on them to register any admin bits they
    may want.
    """

    import copy
    from django.conf import settings
    from django.utils.importlib import import_module
    from django.utils.module_loading import module_has_submodule

    for app in settings.INSTALLED_APPS:
        mod = import_module(app)
        # Attempt to import the app's admin module.
        try:
            before_import_registry = copy.copy(site._registry)
            import_module('%s.admin' % app)
        except:
            # Reset the model registry to the state before the last import as
            # this import will have to reoccur on the next request and this
            # could raise NotRegistered and AlreadyRegistered exceptions
            # (see #8245).
            site._registry = before_import_registry

            # Decide whether to bubble up this error. If the app just
            # doesn't have an admin module, we can ignore the error
            # attempting to import it, otherwise we want it to bubble up.
            if module_has_submodule(mod, 'admin'):
                raise

Revert the removal of an unused import (in [14175]) that was referenced in documentation. Thanks for noticing, clong.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14359 bcc190cf-cafb-0310-a4f2-bffc1f526a37

--HG--
extra : convert_revision : e026073455a73c9fe9a9f026b76ac783b2a12d23


from nodes import Node

class MultiVar(Node):
    char = "'"
    args = 0
    results = None
    contents = -1

    def __init__(self, node_1: Node.NodeSingle, node_2: Node.NodeSingle):
        self.node_1 = node_1
        self.node_2 = node_2
        self.args = max([node_1.args, node_2.args])

    def prepare(self, stack):
        if len(stack) == 0:
            self.add_arg(stack)

    @Node.is_func
    def apply(self, *stack):
        self.node_2.prepare(stack)
        rtn = self.node_2(stack[:self.node_2.args])
        self.node_1.prepare(stack)
        rtn.extend(self.node_1(stack[:self.node_1.args]))
        return rtn

from nodes import Node

class MultiVar(Node):
    char = "'"
    args = 0
    results = None
    contents = -1

    def __init__(self, node_1: Node.NodeSingle, node_2: Node.NodeSingle):
        self.node_1 = node_1
        self.node_2 = node_2

    def prepare(self, stack):
        self.node_1.prepare(stack)
        self.node_2.prepare(stack)
        self.args = max([self.node_1.args,self.node_2.args])

    @Node.is_func
    def apply(self, *stack):
        rtn = self.node_2(stack[:self.node_2.args])
        rtn.extend(self.node_1(stack[:self.node_1.args]))
        return rtn

Fix multivar for nodes with variable length stacks


from . import Measurement
import feature_extraction.util.cleanup as cleanup

class HaralickTexture(Measurement):
	def compute(self, image):
		return []

from . import Measurement
import feature_extraction.util.cleanup as cleanup
from skimage.morphology import binary_erosion, disk

class HaralickTexture(Measurement):
	default_options = {
		'clip_cell_borders': True,
		'erode_cell': False,
		'erode_cell_amount': False,
	}
	def __init__(self, options=None):
		super(HaralickTexture, self).__init__(options)

	def compute(self, image):
		# -- preprocessing
		if self.options.clip_cell_borders:
			# get the cell boundary mask
			mask = cleanup.cell_boundary_mask(image)

			# if we're told to, erode the mask with a disk by some amount
			if self.options.erode_cell:
				mask = binary_erosion(cleanup.cell_boundary_mask(), disk(self.options.erode_cell_amount))

			# mask the image
			image = image[mask]

		# -- haralick setup and run

		return []

Add cell-boundary preprocessing to HaralickTexture measurement


#!/bin/env python

import picamera
import redis
import time
import json
import os

def take_photo():
    print "%s Capture photo" % (time.strftime('%Y.%m.%d %H:%M:%S %Z'))
    camera = picamera.PiCamera()
    camera.vflip = True
    camera.resolution = (1280, 720)
    time.sleep(1)
    camera.capture('static/photo.jpg')
    camera.close()
    r.publish('photo', time.time())
    print "%s Capture done" % (time.strftime('%Y.%m.%d %H:%M:%S %Z'))

def get_config():
    with open(os.path.join(os.path.dirname(__file__), 'config.json')) as data_file:
        return json.load(data_file)

def main():
    config = get_config()

    r = redis.StrictRedis(host=config['host'], port=config['port'], db=config['db'])
    p = r.pubsub()
    p.subscribe('take-photo')

    while True:
        message = p.get_message()
        if message and message['type'] == 'message':
            take_photo()

        time.sleep(0.1)

if __name__ == '__main__':
    main()

#!/bin/env python

import picamera
import redis
import time
import json
import os

def take_photo():
    print "%s Capture photo" % (time.strftime('%Y.%m.%d %H:%M:%S %Z'))
    camera = picamera.PiCamera()
    camera.vflip = True
    camera.resolution = (1280, 720)
    time.sleep(1)
    camera.capture('static/photo.jpg')
    camera.close()
    print "%s Capture done" % (time.strftime('%Y.%m.%d %H:%M:%S %Z'))

def get_config():
    with open(os.path.join(os.path.dirname(__file__), 'config.json')) as data_file:
        return json.load(data_file)

def main():
    config = get_config()

    r = redis.StrictRedis(host=config['host'], port=config['port'], db=config['db'])
    p = r.pubsub()
    p.subscribe('take-photo')

    while True:
        message = p.get_message()
        if message and message['type'] == 'message':
            take_photo()
            r.publish('photo', time.time())

        time.sleep(0.1)

if __name__ == '__main__':
    main()

Fix publishing photo creation event

Fix publishing photo creation event


import sys, unittest
import bmc_test
import power_test
import xmlrunner

tests = []
tests.extend(bmc_test.tests)
#tests.extend(power_test.tests)

if __name__ == '__main__':
    for test in tests:
        test.system = sys.argv[1]
        suite = unittest.TestLoader().loadTestsFromTestCase(test)
        xmlrunner.XMLTestRunner(verbose = 1, output='test-reports').run(suite)

import sys, unittest, os
import bmc_test
import power_test
import xmlrunner

tests = []
tests.extend(bmc_test.tests)
#tests.extend(power_test.tests)

if __name__ == '__main__':
    for test in tests:
        test.system = sys.argv[1]
        suite = unittest.TestLoader().loadTestsFromTestCase(test)
        result = xmlrunner.XMLTestRunner(verbose = 1, output='test-reports').run(suite)
        if result.failures or result.errors:
            os.sys.exit(1)

Return a bad error code when a test fails