prefix stringlengths 0 918k | middle stringlengths 0 812k | suffix stringlengths 0 962k |
|---|---|---|
from time import strftime
import MySQLdb
api_name = raw_input('API Name: ')
api_url = raw_input('API URL: ')
crawl_frequency = raw_input('A | PI Crawl Frequency(in mins): ')
last_crawl = strftime("%H:%M:%S")
db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="dataweave")
curs | or = db.cursor()
cursor.execute('''INSERT INTO api_list (api_name, api_url, last_crawl, crawl_frequency) VALUES (%s, %s, %s, %s)''', (api_name, api_url, last_crawl, crawl_frequency))
db.commit()
print '\nAPI added!\n' |
from __future__ import unicode_literals
from django import forms
from django.forms.models import inlineformset_factory
from django.forms.widgets import ClearableFileInput
from ...product.models import (ProductImage, Product, ShirtVariant, BagVariant,
Shirt, Bag)
PRODUCT_CLASSES = {
'shirt': Shirt,
'bag': Bag}
class ProductClassForm(forms.Form):
cls_name = forms.ChoiceField(
choices=[(name, name.capitalize()) for name in PRODUCT_CLASSES.keys()])
cl | ass ProductForm(forms.Mode | lForm):
class Meta:
model = Product
fields = ['name', 'description', 'collection']
class ShirtForm(ProductForm):
class Meta:
model = Shirt
exclude = []
class BagForm(ProductForm):
class Meta:
model = Bag
exclude = []
class ImageInputWidget(ClearableFileInput):
url_markup_template = '<a href="{0}"><img src="{0}" width=50 /></a>'
formset_defaults = {
'extra': 1,
'min_num': 1,
'validate_min': True
}
ProductImageFormSet = inlineformset_factory(
Product, ProductImage, widgets={'image': ImageInputWidget},
exclude=[], **formset_defaults)
ShirtVariantFormset = inlineformset_factory(
Shirt, ShirtVariant, exclude=[], **formset_defaults)
BagVariantFormset = inlineformset_factory(
Bag, BagVariant, exclude=[], **formset_defaults)
def get_product_form(product):
if isinstance(product, Shirt):
return ShirtForm
elif isinstance(product, Bag):
return BagForm
else:
raise ValueError('Unknown product')
def get_product_cls_by_name(cls_name):
if not cls_name in PRODUCT_CLASSES:
raise ValueError('Unknown product class')
return PRODUCT_CLASSES[cls_name]
def get_variant_formset(product):
if isinstance(product, Shirt):
return ShirtVariantFormset
elif isinstance(product, Bag):
return BagVariantFormset
else:
raise ValueError('Unknown product')
|
import os.path
from pyneuroml.lems.LEMSSimulation import LEMSSimulation
import shutil
import os
from pyneuroml.pynml import read_neuroml2_file, get_next_hex_color, print_comment_v, print_comment
import random
def generate_lems_file_for_neuroml(sim_id,
neuroml_file,
target,
duration,
dt,
lems_file_name,
target_dir,
gen_plots_for_all_v = True,
plot_all_segments = False,
gen_plots_for_only = [], # List of populations
gen_plots_for_quantities = {}, # Dict with displays vs lists of quantity paths
gen_saves_for_all_v = True,
save_all_segments = False,
gen_saves_for_only = [], # List of populations
gen_saves_for_quantities = {}, # Dict with file names vs lists of quantity paths
copy_neuroml = True,
seed=None):
if seed:
random.seed(seed) # To ensure same LEMS file (e.g. colours of plots) are generated every time for the same input
file_name_full = '%s/%s'%(target_dir,lems_file_name)
print_comment_v('Creating LEMS file at: %s for NeuroML 2 file: %s'%(file_name_full,neuroml_file))
ls = LEMSSimulation(sim_id, duration, dt, target)
nml_doc = read_neuroml2_file(neuroml_file, include_includes=True, verbose=True)
quantities_saved = []
if not copy_neuroml:
rel_nml_file = os.path.relpath(os.path.abspath(neuroml_file), os.path.abspath(target_dir))
print_comment_v("Including existing NeuroML file (%s) as: %s"%(neuroml_file, rel_nml_file))
ls.include_neuroml2_file(rel_nml_file, include_included=True, relative_to_dir=os.path.abspath(target_dir))
else:
print_comment_v("Copying NeuroML file (%s) to: %s (%s)"%(neuroml_file, target_dir, os.path.abspath(target_dir)))
if os.path.abspath(os.path.dirname(neuroml_file))!=os.path.abspath(target_dir):
shutil.copy(neuroml_file, target_dir)
neuroml_file_name = os.path.basename(neuroml_file)
ls.include_neuroml2_file(neuroml_file_name, include_included=False)
for include in nml_doc.includes:
incl_curr = '%s/%s'%(os.path.dirname(neuroml_file),include.href)
print_comment_v(' - Including %s located at %s'%(include.href, incl_curr))
shutil.copy(incl_curr, target_dir)
ls.include_neuroml2_file(include.href, include_included=False)
sub_doc = read_neuroml2_file(incl_curr)
for include in sub_doc.includes:
incl_curr = '%s/%s'%(os.path.dirname(neuroml_file),include.href)
print_comment_v(' -- Including %s located at %s'%(include.href, incl_curr))
shutil.copy(incl_curr, target_dir)
ls.include_neuroml2_file(include.href, include_included=False)
if gen_plots_for_all_v or gen_saves_for_all_v or len(gen_plots_for_only)>0 or len(gen_saves_for_only)>0 :
for network in nml_doc.networks:
for population in network.populations:
quantity_template = "%s[%i]/v"
component = population.component
size = population.size
cell = None
segment_ids = []
if plot_all_segments:
for c in nml_doc.cells:
if c.id == component:
cell = c
for segment in cell.morphology.segments:
segment_ids.append(segment.id)
segment_ids.sort()
if population.type and population.type == 'populationList':
quantity_template = "%s/%i/"+component+"/v"
size = len(population.instances)
if gen_plots_for_all_v or population.id in gen_plots_for_only:
print_comment('Generating %i plots for %s in population %s'%(size, component, population.id))
disp0 = 'DispPop__%s'%population.id
ls.create_display(disp0, "Voltages of %s"%disp0, "-90", "50")
for i in range(size):
if plot_all_segments:
quantity_template_seg = "%s/%i/"+component+"/%i/v"
for segment_id in segment_ids:
quantity = quantity_template_seg%(population.id, i, segment_id)
ls.add_line_to_display(disp0, "v in seg %i %s"%(segment_id,safe_variable(quantity)), quantity, "1mV", get_next_hex_color())
else:
quantity = quantity_template%(population.id, i)
ls.add_line_to_display(disp0, "v %s"%safe_variable(quantity), quantity, "1mV", get_next_hex_color())
if gen_saves_for_all_v or population.id in gen_saves_for_only:
print_comment('Saving %i values of v for %s in population %s'%(size, component, population.id))
of0 = 'Volts_file__%s'%populati | on.id
ls.create_o | utput_file(of0, "%s.%s.v.dat"%(sim_id,population.id))
for i in range(size):
if save_all_segments:
quantity_template_seg = "%s/%i/"+component+"/%i/v"
for segment_id in segment_ids:
quantity = quantity_template_seg%(population.id, i, segment_id)
ls.add_column_to_output_file(of0, 'v_%s'%safe_variable(quantity), quantity)
quantities_saved.append(quantity)
else:
quantity = quantity_template%(population.id, i)
ls.add_column_to_output_file(of0, 'v_%s'%safe_variable(quantity), quantity)
quantities_saved.append(quantity)
for display in gen_plots_for_quantities.keys():
quantities = gen_plots_for_quantities[display]
ls.create_display(display, "Plots of %s"%display, "-90", "50")
for q in quantities:
ls.add_line_to_display(display, safe_variable(q), q, "1", get_next_hex_color())
for file_name in gen_saves_for_quantities.keys():
quantities = gen_saves_for_quantities[file_name]
ls.create_output_file(file_name, file_name)
for q in quantities:
ls.add_column_to_output_file(file_name, safe_variable(q), q)
ls.save_to_file(file_name=file_name_full)
return quantities_saved
# Mainly for NEURON etc.
def safe_variable(quantity):
return quantity.replace(' ','_').replace('[','_').replace(']','_').replace('/','_')
|
from unittest import TestCase
from django.core.management import call_command
from test_app.models import Place
class BatchGeocodeTestCase(TestCase):
def setUp(self):
self.place = Place()
def test_batch_geocode(self):
self.place.address = "14 Rue de Rivoli, 75004 Paris, France"
self.place.save()
call_command('batch_geocode')
| self.place.refresh_fro | m_db()
self.assertIsNotNone(self.place.locality)
|
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import Enum
from collections import namedtuple
class UIComponents:
# named tuple to hold two xPath values for each platform
Component = namedtuple('Component', ['iOS', 'Andr | oid'])
LABEL = Component(iOS='//XCUIElementTypeStaticText[{}]', Android='//android.widget.TextView[{}]')
BUTTON = Component(iOS='//XCUIElementTypeButton[{}]', A | ndroid='//android.widget.Button[{}]')
TEXTFIELD = Component(iOS='//XCUIElementTypeTextField[{}]', Android='//android.widget.EditText[{}]')
PWDFIELD = Component(iOS='//XCUIElementTypeSecureTextField[{}]', Android='//android.widget.EditText[{}]')
LIST = Component(iOS='//XCUIElementTypeTable/*[{}]', Android='//android.widget.ListView/*[{}]')
SWITCH = Component(iOS='//XCUIElementTypeSwitch[{}]', Android='TBD')
SLIDER = Component(iOS='//XCUIElementTypeSlider[{}]', Android='TBD')
ALERT = Component(iOS='//XCUIElementTypeAlert', Android='(//android.widget.LinearLayout | //android.widget.FrameLayout)[contains(@resource-id, \'id/parentPanel\')]')
PERMISSION_ALERT = Component(iOS='//XCUIElementTypeAlert',
Android='(//android.widget.LinearLayout)[contains(@resource-id, \'id/dialog_container\')]')
# For app compat v7 alert dialog
# //android.widget.FrameLayout[contains(@resource-id, 'id/action_bar_root')]
# For native alert dialog
# //android.widget.LinearLayout[contains(@resource-id, 'id/parentPanel')] |
import sys
from ctypes import create_string_buffer
from ._libsoc import (
BITS_8, BITS_16, BPW_ERROR,
MODE_0, MODE_1, MODE_2, MODE_3, MODE_ERROR, api
)
PY3 = sys.version_info >= (3, 0)
class SPI(object):
def __init__(self, spidev_device, chip_select, mode, speed, bpw):
if not isinstance(spidev_device, int):
raise TypeError('Invalid spi device id must be an "int"')
if not isinstance(chip_select, int):
raise TypeError('Invalid spi chip select must be an "int"')
if mode not in (MODE_0, MODE_1, MODE_2, MODE_3):
raise ValueError('Invalid mode: %d' % mode)
if not isinstance(speed, int):
raise TypeError('Invalid speed must be an "int"')
if bpw not in (BITS_8, BITS_16):
raise ValueError('Invalid bits per word: %d' % bpw)
self.device = spidev_device
self.chip = chip_select
self.mode = mode
self.speed = speed
self.bpw = bpw
self._spi = None
def __enter__(self):
self.open()
return self
def __exit__(self, type, value, traceback):
self.close()
def open(self):
assert self._spi is None
self._spi = api.libsoc_spi_init(self.device, self.chip)
if self._spi == 0:
raise IOError('Unable to open spi device(%d)' % self.device)
self.set_mode(self.mode)
if self.get_mode() != self.mode:
raise IOError('Set mode incorrectly')
self.set_speed(self.speed)
if self.get_speed() != self.speed:
raise IOError('Set speed incorrectly')
self.set_bits_per_word(self.bpw)
if self.get_bits_per_word() != self.bpw:
raise IOError('Set bits per word incorrectly')
def close(self):
if self._spi:
api.libsoc_spi_free(self._spi)
self._spi = None
def set_debug(enabled):
v = 0
if enabled:
v = 1
api.libsoc_set_debug(v)
def set_bits_per_word(self, bpw):
if bpw not in (BITS_8, BITS_16):
raise ValueError('Invalid bits per word: %d' % bpw)
self.bpw = bpw
api.libsoc_spi_set_bits_per_word(self._spi, self.bpw)
def get_bits_per_word(self):
b = api.libsoc_spi_get_bits_per_word(self._spi)
if b == BPW_ERROR:
raise IOError('bits per word not recognized')
return b
def set_mode(self, mode):
assert self._spi is not None
if mode not in (MODE_0, MODE_1, MODE_2, MODE_3):
raise ValueError('Invalid mode: %d' % mode)
self.mode = mode
api.libsoc_spi_set_mode(self._spi, self.mode)
def get_mode(self):
m = api.libsoc_spi_get_mode(self._spi)
if m == MODE_ERROR:
raise IOError('mode not recognized')
return m
def set_speed(self, speed):
if not isinstance(speed, int):
raise TypeError('Invalid speed must be an "int"')
self.speed = speed
api.libsoc_spi_set_speed(self._spi, self.speed)
def get_speed(self):
s = api.libsoc_spi_get_speed(self._spi)
if s == -1:
raise IOError('failed reading speed')
return s
def read(self, num_bytes):
assert num_bytes > 0
buff = create_string_buffer(num_bytes)
if api.libsoc_spi_read(self._spi, buff, num_bytes) == -1:
raise IOError('Error reading spi device')
return buff.r | aw
def write(self, byte_array):
assert len(byte_array) > 0
if PY3:
buff = bytes(byte_array)
else:
buff = ''.join(map(chr, byte_array) | )
api.libsoc_spi_write(self._spi, buff, len(buff))
def rw(self, num_bytes, byte_array):
assert num_bytes > 0
assert len(byte_array) > 0
rbuff = create_string_buffer(num_bytes)
if PY3:
wbuff = bytes(byte_array)
else:
wbuff = ''.join(map(chr, byte_array))
if api.libsoc_spi_rw(self._spi, wbuff, rbuff, num_bytes) != 0:
raise IOError('Error rw spi device')
return rbuff.raw
|
ss = models.PositiveSmallIntegerField(
validators=[
validators.MinValueValidator(6),
validators.MaxValueValidator(12),
],
verbose_name=_(u'class'),
)
school_year = models.IntegerField(
validators=[
validators.MinValueValidator(2005),
validators.MaxValueValidator(2015),
],
verbose_name=_(u'class update year'),
help_text=_(
u'This field value shows, at which year January 3 day '
u'student was in school_class.'
),
)
comment = models.TextField(
blank=True,
null=True,
verbose_name=_(u'comment'),
)
schools = models.ManyToManyField(
School,
through='StudyRelation',
)
parents = models.ManyToManyField(
Human,
through='ParentRelation',
related_name='children',
)
def current_school_class(self):
""" Returns current school class or 13 if finished.
"""
today = datetime.date.today()
school_class = self.school_class + today.year - self.school_year
if today.month >= 9:
school_class += 1
if school_class > 12:
return 13
else:
return school_class
current_school_class.short_description = _(u'current class')
def current_school(self):
""" Returns current school.
"""
study = StudyRelation.objects.filter(
student=self).order_by('entered')[0]
return study.school
current_school.short_description = _(u'current school')
def change_school(self, school, date=None):
""" Marks, that student from ``date`` study in ``school``.
.. note::
Automatically saves changes.
``date`` defaults to ``today()``. If student already studies in
some school, than marks, that he had finished it day before
``date``.
"""
if date is None:
date = datetime.date.today()
try:
old_study = StudyRelation.objects.filter(
student=self).order_by('entered')[0]
except IndexError:
pass
else:
if not old_study.finished:
old_study.finished = date - datetime.timedelta(1)
old_study.save()
study = StudyRelation()
study.student = self
study.school = school
study.entered = date
study.save()
class Meta(object):
verbose_name=_(u'student')
verbose_name_plural=_(u'students')
class StudyRelation(models.Model):
""" Relationship between student and school.
"""
student = models.ForeignKey(
Student,
verbose_name=_(u'student'),
)
school = models.ForeignKey(
School,
verbose_name=_(u'school'),
)
entered = models.DateField(
verbose_name=_(u'entered'),
)
finished = models.DateField(
blank=True,
null=True,
verbose_name=_(u'finished'),
)
class Meta(object):
ordering = [u'student', u'entered',]
verbose_name=_(u'study relation')
verbose_name_plural=_(u'study relations')
def __unicode__(self):
return u'{0.school} ({0.entered}; {0.finished})'.format(self)
# FIXME: Diploma should belong to academic, not student.
class Diploma(models.Model):
""" Information about the diploma that the student has received,
when he finished, if any.
"""
DIPLOMA_TYPE = (
(u'N', _(u'nothing')),
(u'P', _(u'certificate')),
(u'D', _(u'diploma')),
(u'DP', _(u'diploma with honour')),
)
student = models.OneToOneField(
Student,
verbose_name=_(u'student'),
)
tasks_solved = models.PositiveSmallIntegerField(
blank=True,
null=True,
verbose_name=_(u'how many tasks solved'),
)
hours = models.DecimalField(
blank=True,
null=True,
max_digits=6,
decimal_places=2,
verbose_name=_(u'hours'),
)
diploma_type = models.CharField(
max_length=3,
choices=DIPLOMA_TYPE,
verbose_name=_(u'type'),
)
number = models.PositiveSmallIntegerField(
verbose_name=_(u'number'),
)
class Meta(object):
verbose_name=_(u'diploma')
verbose_name_plural=_(u'diplomas')
class Alumni(models.Model):
""" Information about alumni.
"""
INTEREST_LEVEL = (
# Not tried to contact.
( 0, _(u'not tried to contact')),
# Tried to contact, no response.
(11, _(u'no response')),
# Tried to contact, responded.
(21, _(u'not interested')),
(22, _(u'friend')),
(23, _(u'helpmate')),
(24, _(u'regular helpmate')),
)
student = models.OneToOneField(
Student,
verbose_name=_(u'student'),
)
activity_fields = models.TextField(
blank=True,
null=True,
verbose_name=_(u'fields'),
help_text=_(
u'Alumni reported that he can help in these activity '
u'fields.'
),
)
interest_level = models.PositiveSmallIntegerField(
blank=True,
null=True,
choices=INTEREST_LEVEL,
verbose_name=_(u'interest level'),
)
abilities = models.TextField(
blank=True,
null=True,
verbose_name=_(u'abilities'),
help_text=_(u'Main abilities and interests.')
)
university = models.CharField(
max_length=128,
blank=True,
null=True,
verbose_name=_(u'university'),
help_text=_(u'Or work place.'),
)
study_field = models.CharField(
max_length=64,
blank=True,
null=True,
verbose_name=_(u'study field'),
help_text=_(u'Or employment field.'),
)
info_change_year = models.IntegerField(
blank=True,
null=True,
verbose_name=_(u'info change year'),
help_text=_(
u'Year when the information about studies '
u'will become invalid.'
),
)
notes = models.TextField(
blank=True,
null=True,
verbose_name=_(u'notes'),
)
information_received_timestamp = models.DateTimeField(
blank=True,
null=True,
verbose_name=_(u'information received timestamp'),
)
class Meta(object):
verbose_name=_(u'alumni')
verbose_nam | e_plural=_(u'alumnis')
def contactable(self):
""" If the alumni agreed to receive information.
"""
return self.interest_level >= 22;
class StudentMark(models.Model):
""" Mark student with some mark.
"""
student = models.ForeignKey(
Student,
verbose_name=_(u'student'),
)
start = models.DateField(
verbose_name=_(u'star | t'),
)
end = models.DateField(
blank=True,
null=True,
verbose_name=_(u'end'),
)
def __unicode__(self):
return unicode(self.student)
class Meta(object):
abstract = True
class SocialDisadvantageMark(StudentMark):
""" Mark student as socially disadvantaged.
"""
class Meta(object):
verbose_name=_(u'social disadvantage mark')
verbose_name_plural=_(u'social disadvantage marks')
class DisabilityMark(StudentMark):
""" Mark student as having disability.
"""
disability = models.CharField(
max_length=128,
|
s.images import get_image_dimensions
d = get_image_dimensions(self.file.file)
if d: t += "<br/>%d×%d" % (d[0], d[1])
except IOError, e:
t += "<br/>(%s)" % e.strerror
return t
file_type.admin_order_field = 'type'
file_type.short_description = _('file type')
file_type.allow_tags = True
def file_info(self):
"""
Method for showing the file name in admin.
Note: This also includes a hidden field that can be used to extract
the file name later on, this can be used to access the file name from
JS, like for example a TinyMCE connector shim.
"""
from os.path import basename
from feincms.utils import shorten_string
return u'<input type="hidden" class="medialibrary_file_path" name="_media_path_%d" value="%s" /> %s' % (
self.id,
self.file.name,
shorten_string(basename(self.file.name), max_length = 28),)
file_info.short_description = _('file info')
file_info.allow_tags = True
def copyright_text(self):
return '%s, (c) %s (%s)', (self.translation.caption, self.copyright, self.licence.code)
def determine_file_type(self, name):
for type_key, type_name, type_test in self.filetypes:
if type_test(name):
return type_key
return self.filetypes[-1][0]
def save(self, *args, **kwargs):
if not self.id and not self.created:
self.created = datetime.now()
self.type = self.determine_file_type(self.file.name)
if self.file:
try:
self.file_size = self.file.size
except (OSError, IOError, ValueError), e:
logging.error("Unable to read file size for %s: %s", self, e)
# Try to detect things that are not really images
if self.type == 'image':
try:
try:
image = Image.open(self.file)
except (OSError, IOError):
image = Image.open(self.file.path)
# Rotate image based on exif data.
if image:
try:
exif = image._getexif()
except (AttributeError, IOError):
exif = False
# PIL < 1.1.7 chokes on JPEGs with minimal EXIF data and
# throws a KeyError deep in its guts.
except KeyError:
exif = False
if exif:
orientation = exif.get(274)
rotation = 0
if orientation == 3:
rotation = 180
elif or | ientation == 6:
rotation = 270
elif orientation == 8:
rotation = 90
| if rotation:
image = image.rotate(rotation)
image.save(self.file.path)
except (OSError, IOError), e:
self.type = self.determine_file_type('***') # It's binary something
if getattr(self, '_original_file_path', None):
if self.file.path != self._original_file_path:
try:
os.unlink(self._original_file_path)
except:
pass
super(MediaFileBase, self).save(*args, **kwargs)
self.purge_translation_cache()
# ------------------------------------------------------------------------
MediaFileBase.register_filetypes(
# Should we be using imghdr.what instead of extension guessing?
('image', _('Image'), lambda f: re.compile(r'\.(bmp|jpe?g|jp2|jxr|gif|png|tiff?)$', re.IGNORECASE).search(f)),
('other', _('Binary'), lambda f: True), # Must be last
)
"""
('video', _('Video'), lambda f: re.compile(r'\.(mov|m[14]v|mp4|avi|mpe?g|qt|ogv|wmv)$', re.IGNORECASE).search(f)),
('audio', _('Audio'), lambda f: re.compile(r'\.(au|mp3|m4a|wma|oga|ram|wav)$', re.IGNORECASE).search(f)),
('pdf', _('PDF document'), lambda f: f.lower().endswith('.pdf')),
('swf', _('Flash'), lambda f: f.lower().endswith('.swf')),
('txt', _('Text'), lambda f: f.lower().endswith('.txt')),
('rtf', _('Rich Text'), lambda f: f.lower().endswith('.rtf')),
('zip', _('Zip archive'), lambda f: f.lower().endswith('.zip')),
('doc', _('Microsoft Word'), lambda f: re.compile(r'\.docx?$', re.IGNORECASE).search(f)),
('xls', _('Microsoft Excel'), lambda f: re.compile(r'\.xlsx?$', re.IGNORECASE).search(f)),
('ppt', _('Microsoft PowerPoint'), lambda f: re.compile(r'\.pptx?$', re.IGNORECASE).search(f)),
"""
# ------------------------------------------------------------------------
class MediaFile(MediaFileBase):
@classmethod
def register_extension(cls, register_fn):
register_fn(cls, MediaFileAdmin)
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
class MediaFileTranslation(Translation(MediaFile)):
"""
Translated media file caption and description.
"""
caption = models.CharField(_('caption'), max_length = 200)
description = models.TextField(_('description'), blank = True)
class Meta:
verbose_name = _('media file translation')
verbose_name_plural = _('media file translations')
def __unicode__(self):
return self.caption
#-------------------------------------------------------------------------
class MediaFileTranslationInline(admin.StackedInline):
model = MediaFileTranslation
max_num = len(django_settings.LANGUAGES)
def admin_thumbnail(obj):
if obj.type == 'image':
image = None
try:
image = feincms_thumbnail.thumbnail(obj.file.name, '100x60')
except:
pass
if image:
return mark_safe(u"""
<a href="%(url)s" target="_blank">
<img src="%(image)s" alt="" />
</a>""" % {
'url': obj.file.url,
'image': image, })
return ''
admin_thumbnail.short_description = _('Preview')
admin_thumbnail.allow_tags = True
#-------------------------------------------------------------------------
class MediaFileAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
inlines = [MediaFileTranslationInline]
list_display = ['__unicode__', admin_thumbnail, 'file_type', 'licence', 'copyright', 'file_info', 'formatted_file_size', 'formatted_created']
list_filter = ['type', 'categories', 'licence']
list_per_page = 25
search_fields = ['copyright', 'file', 'translations__caption']
filter_horizontal = ("categories",)
def get_urls(self):
from django.conf.urls.defaults import url, patterns
urls = super(MediaFileAdmin, self).get_urls()
my_urls = patterns('',
url(r'^mediafile-bulk-upload/$', self.admin_site.admin_view(MediaFileAdmin.bulk_upload), {}, name = 'mediafile_bulk_upload')
)
return my_urls + urls
def changelist_view(self, request, extra_context = None):
if extra_context is None:
extra_context = {}
extra_context['categories'] = Category.objects.all()
return super(MediaFileAdmin, self).changelist_view(request, extra_context = extra_context)
@staticmethod
# 1.2 @csrf_protect
@permission_required('medialibrary.add_mediafile')
def bulk_upload(request):
from django.core.urlresolvers import reverse
from django.utils.functional import lazy
def import_zipfile(request, category_id, data):
import zipfile
from os import path
category = None
if category_id:
category = Category.objects.get(pk = int(category_id))
try:
z = zipfile.ZipFile(data)
storage = MediaFile.fs
if not storage:
me |
import pymysql.cursors
from model.group import Group
from model.contact import Contact
class DbFixture():
def __init__(self, host, name, user, password):
self.host = host
self.name = name
self.user = user
self.password = password
self.connection = pymysql.connect(host=host, database=name, user=user, password=password, autocommit=True)
def get_group_list(self):
list =[]
cursor = self.connection.cursor()
try:
cursor.execute("select group_id, group_name, group_header, group_footer from group_list")
for row in cursor:
| (id, name, header, footer) = row
list.append(Group(id=str(id), name=name, header=header, footer=footer))
finally:
cursor.close()
return list
def get_contact_list(self):
list =[]
cursor = self.connecti | on.cursor()
try:
cursor.execute("select id, firstname, lastname from addressbook where deprecated='0000-00-00 00:00:00' ")
for row in cursor:
(id, firstname, lastname) = row
list.append(Contact(id=str(id), firstname=firstname, lastname=lastname))
finally:
cursor.close()
return list
def destroy(self):
self.connection.close()
|
bl_format_value.setFont(font)
self.lbl_format_value.setObjectName(_fromUtf8("lbl_format_value"))
self.layout_values.addWidget(self.lbl_format_value)
self.lbl_size_value = QtGui.QLabel(self.verticalLayoutWidget_2)
font = QtGui.QFont()
font.setPointSize(9)
self.lbl_size_value.setFont(font)
self.lbl_size_value.setObjectName(_fromUtf8("lbl_size_value"))
self.layout_values.addWidget(self.lbl_size_value)
self.lbl_max_length_value = QtGui.QLabel(self.verticalLayoutWidget_2)
font = QtGui.QFont()
font.setPointSize(9)
self.lbl_max_length_value.setFont(font)
self.lbl_max_length_value.setObjectName(_fromUtf8("lbl_max_length_value"))
self.layout_values.addWidget(self.lbl_max_length_value)
self.lbl_spacing_info = QtGui.QLabel(self.group_image)
self.lbl_spacing_info.setGeometry(QtCore.QRect(20, 180, 141, 71))
self.lbl_spacing_info.setWordWrap(True)
self.lbl_spacing_info.setObjectName(_fromUtf8("lbl_spacing_info"))
self.lbl_status = QtGui.QLabel(self.group_image)
self.lbl_status.setGeometry(QtCore.QRect(640, 160, 351, 121))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Consolas"))
font.setPointSize(9)
font.setBold(True)
font.setWeight(75)
self.lbl_status.setFont(font)
self.lbl_status.setFrameShape(QtGui.QFrame.Panel)
self.lbl_status.setFrameShadow(QtGui.QFrame.Sunken)
self.lbl_status.setLineWidth(2)
self.lbl_status.setScaledContents(False)
self.lbl_status.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_status.setWordWrap(True)
self.lbl_status.setIndent(-1)
self.lbl_status.setObjectName(_fromUtf8("lbl_status"))
self.group_message = QtGui.QGroupBox(self.centralwidget)
self.group_message.setGeometry(QtCore.QRect(10, 310, 1001, 261))
self.group_message.setObjectName(_fromUtf8("group_message"))
self.text_message = QtGui.QTextEdit(self.group_message)
self.text_message.setGeometry(QtCore.QRect(180, 20, 811, 191))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Consolas"))
font.setPointSize(9)
self.text_message.setFont(font)
self.text_message.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.text_message.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.text_message.setObjectName(_fromUtf8("text_message"))
self.btn_load_text_file = QtGui.QPushButton(self.group_message)
self.btn_load_text_file.setGeometry(QtCore.QRect(10, 22, 161, 31))
font = QtGui.QFont()
font.setPointSize(10)
self.btn_load_text_file.setFont(font)
self.btn_load_text | _file.setObjectName(_fromUtf8("btn_load_text_file"))
self.lbl_num_characters = QtGui.QLabel(self.group_message)
self.lbl_num_characters.setGeometry(QtCore.QRect(180, 220, 811, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Consolas"))
fon | t.setPointSize(10)
self.lbl_num_characters.setFont(font)
self.lbl_num_characters.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_num_characters.setObjectName(_fromUtf8("lbl_num_characters"))
self.lbl_message_info = QtGui.QLabel(self.group_message)
self.lbl_message_info.setGeometry(QtCore.QRect(10, 60, 151, 91))
self.lbl_message_info.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.lbl_message_info.setWordWrap(True)
self.lbl_message_info.setObjectName(_fromUtf8("lbl_message_info"))
self.lbl_allowed_symbols = QtGui.QLabel(self.group_message)
self.lbl_allowed_symbols.setGeometry(QtCore.QRect(20, 140, 151, 101))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Consolas"))
font.setPointSize(12)
self.lbl_allowed_symbols.setFont(font)
self.lbl_allowed_symbols.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_allowed_symbols.setWordWrap(True)
self.lbl_allowed_symbols.setObjectName(_fromUtf8("lbl_allowed_symbols"))
self.btn_process = QtGui.QPushButton(self.group_message)
self.btn_process.setGeometry(QtCore.QRect(830, 220, 161, 31))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.btn_process.setFont(font)
self.btn_process.setAcceptDrops(False)
self.btn_process.setAutoFillBackground(False)
self.btn_process.setAutoDefault(True)
self.btn_process.setDefault(True)
self.btn_process.setObjectName(_fromUtf8("btn_process"))
self.lbl_spacing_info_2 = QtGui.QLabel(self.centralwidget)
self.lbl_spacing_info_2.setGeometry(QtCore.QRect(890, 0, 131, 20))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(109, 109, 109))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(109, 109, 109))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
self.lbl_spacing_info_2.setPalette(palette)
font = QtGui.QFont()
font.setPointSize(7)
self.lbl_spacing_info_2.setFont(font)
self.lbl_spacing_info_2.setWordWrap(True)
self.lbl_spacing_info_2.setObjectName(_fromUtf8("lbl_spacing_info_2"))
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Nick\'s Image Steganography", None))
self.group_image.setTitle(_translate("MainWindow", "Image Settings", None))
self.lbl_filename.setText(_translate("MainWindow", "<no image selected>", None))
self.btn_load.setText(_translate("MainWindow", "Load Image", None))
self.lbl_spacing.setText(_translate("MainWindow", "Spacing:", None))
self.box_spacing.setToolTip(_translate("MainWindow", "Default: 32", None))
self.radio_decode.setText(_translate("MainWindow", "Decode Image", None))
self.radio_encode.setText(_translate("MainWindow", "Encode Message", None))
self.lbl_height.setText(_translate("MainWindow", "Height:", None))
self.lbl_width.setText(_translate("MainWindow", "Width:", None))
self.lbl_format.setText(_translate("MainWindow", "Format:", None))
self.lbl_size.setText(_translate("MainWindow", "Size:", None))
self.lbl_max_length.setText(_translate("MainWindow", "Max Message Length:", None))
self.lbl_height_value.setText(_translate("MainWindow", "0 px", None))
self.lbl_width_value.setText(_translate("MainWindow", "0 px", None))
self.lbl_format_value.setText(_translate("MainWindow", "NONE", None))
self.lbl_size_value.setText(_translate("MainWindow", "0 bytes", None))
self.lbl_max_length_value.setText(_translate("MainWindow", "0 characters", None))
self.lbl_spacing_info.setText(_translate("MainWindow", "This value selects how many pixels are skipped for every encoded pixel. Lower values will affect the image more.", None))
self.lbl_status.setText(_translate("MainWindow", "This mode allows you to select an image file and enter a message below. When you are finished, click Process.", None))
self.group_message.setTitle(_translate("MainWindow", "Message", None))
self.btn_load_text_file.setText(_translate("MainWindow", "Load Text File", None))
self.lbl_num_characters.setText(_translate("MainWindow", "0 / 0 characters", None))
self.lbl_message_info.setText(_translate("MainWindow", "Enter the message you would like to encode into the box. Whitespace characters will be converted into spaces. English letters, numbers, an |
given hash for this file.
List of supported hashes can be obtained from :mod:`hashlib` package.
This reads the entire file.
.. seealso:: :meth:`hashlib.hash.digest`
"""
return self._hash(hash_name).digest()
def read_hexhash(self, hash_name):
""" Calculate given hash for this file, returning hexdigest.
List of supported hashes can be obtained from :mod:`hashlib` package.
This reads the entire file.
.. seealso:: :meth:`hashlib.hash.hexdigest`
"""
return self._hash(hash_name).hexdigest()
# --- Methods for querying the filesystem.
# N.B. On some platforms, the os.path functions may be implemented in C
# (e.g. isdir on Windows, Python 3.2.2), and compiled functions don't get
# bound. Playing it safe and wrapping them all in method calls.
def isabs(self):
""" .. seealso:: :func:`os.path.isabs` """
return self.module.isabs(self)
def exists(self):
""" .. seealso:: :func:`os.path.exists` """
return self.module.exists(self)
def isdir(self):
""" .. seealso:: :func:`os.path.isdir` """
return self.module.isdir(self)
def isfile(self):
""" .. seealso:: :func:`os.path.isfile` """
return self.module.isfile(self)
def islink(self):
""" .. seealso:: :func:`os.path.islink` """
return self.module.islink(self)
def ismount(self):
""" .. seealso:: :func:`os.path.ismount` """
return self.module.ismount(self)
def samefile(self, other):
""" .. seealso:: :func:`os.path.samefile` """
return self.module.samefile(self, other)
def getatime(self):
""" .. seealso:: :attr:`atime`, :func:`os.path.getatime` """
return self.module.getatime(self)
atime = property(
getatime, None, None,
""" Last access time of the file.
.. seealso:: :meth:`getatime`, :func:`os.path.getatime`
""")
def getmtime(self):
""" .. seealso:: :attr:`mtime`, :func:`os.path.getmtime` """
return self.module.getmtime(self)
mtime = property(
getmtime, None, None,
""" Last-modified time of the file.
.. seealso:: :meth:`getmtime`, :func:`os.path.getmtime`
""")
def getctime(self):
""" .. seealso:: :attr:`ctime`, :func:`os.path.getctime` """
return self.module.getctime(self)
ctime = property(
getctime, None, None,
""" Creation time of the file.
.. seealso:: :meth:`getctime`, :func:`os.path.getctime`
""")
def getsize(self):
""" .. seealso:: :attr:`size`, :func:`os.path.getsize` """
return self.module.getsize(self)
size = property(
getsize, None, None,
""" Size of the file, in bytes.
.. seealso:: :meth:`getsize`, :func:`os.path.getsize`
""")
if hasattr(os, 'access'):
def access(self, mode):
""" Return true if current user has access to this path.
mode - One of the constants :data:`os.F_OK`, :data:`os.R_OK`,
:data:`os.W_OK`, :data:`os.X_OK`
.. seealso:: :func:`os.access`
"""
return os.access(self, mode)
def stat(self):
""" Perform a ``stat()`` system call on this path.
.. seealso:: :meth:`lstat`, :func:`os.stat`
"""
return os.stat(self)
def lstat(self):
""" Like :meth:`stat`, but do not follow symbolic links.
.. seealso:: :meth:`stat`, :func:`os.lstat`
"""
return os.lstat(self)
def __get_owner_windows(self):
r"""
Return the name of the owner of this file or directory. Follow
symbolic links.
Return a name of the form ``ur'DOMAIN\User Name'``; may be a group.
.. seealso:: :attr:`owner`
"""
desc = win32security.GetFileSecurity(
self, win32security.OWNER_SECURITY_INFORMATION)
sid = desc.GetS | ecurityDescriptorOwner()
account, domain, typecode = win32security.LookupAccountSid(None, sid)
return domain + u('\\') + account
def __get_owner_unix(self):
"""
Return the name of the owner of this file or directory. Follow
symbolic links.
.. seealso:: :attr:`owner`
"""
st = self.stat()
return pwd.getpwuid(st.st_uid).pw_name
def __get_owner_not_implemented(self):
| raise NotImplementedError("Ownership not available on this platform.")
if 'win32security' in globals():
get_owner = __get_owner_windows
elif 'pwd' in globals():
get_owner = __get_owner_unix
else:
get_owner = __get_owner_not_implemented
owner = property(
get_owner, None, None,
""" Name of the owner of this file or directory.
.. seealso:: :meth:`get_owner`""")
if hasattr(os, 'statvfs'):
def statvfs(self):
""" Perform a ``statvfs()`` system call on this path.
.. seealso:: :func:`os.statvfs`
"""
return os.statvfs(self)
if hasattr(os, 'pathconf'):
def pathconf(self, name):
""" .. seealso:: :func:`os.pathconf` """
return os.pathconf(self, name)
#
# --- Modifying operations on files and directories
def utime(self, times):
""" Set the access and modified times of this file.
.. seealso:: :func:`os.utime`
"""
os.utime(self, times)
return self
def chmod(self, mode):
""" .. seealso:: :func:`os.chmod` """
os.chmod(self, mode)
return self
if hasattr(os, 'chown'):
def chown(self, uid=-1, gid=-1):
""" .. seealso:: :func:`os.chown` """
os.chown(self, uid, gid)
return self
def rename(self, new):
""" .. seealso:: :func:`os.rename` """
os.rename(self, new)
return self._next_class(new)
def renames(self, new):
""" .. seealso:: :func:`os.renames` """
os.renames(self, new)
return self._next_class(new)
#
# --- Create/delete operations on directories
def mkdir(self, mode=o777):
""" .. seealso:: :func:`os.mkdir` """
os.mkdir(self, mode)
return self
def mkdir_p(self, mode=o777):
""" Like :meth:`mkdir`, but does not raise an exception if the
directory already exists. """
try:
self.mkdir(mode)
except OSError:
_, e, _ = sys.exc_info()
if e.errno != errno.EEXIST:
raise
return self
def makedirs(self, mode=o777):
""" .. seealso:: :func:`os.makedirs` """
os.makedirs(self, mode)
return self
def makedirs_p(self, mode=o777):
""" Like :meth:`makedirs`, but does not raise an exception if the
directory already exists. """
try:
self.makedirs(mode)
except OSError:
_, e, _ = sys.exc_info()
if e.errno != errno.EEXIST:
raise
return self
def rmdir(self):
""" .. seealso:: :func:`os.rmdir` """
os.rmdir(self)
return self
def rmdir_p(self):
""" Like :meth:`rmdir`, but does not raise an exception if the
directory is not empty or does not exist. """
try:
self.rmdir()
except OSError:
_, e, _ = sys.exc_info()
if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
raise
return self
def removedirs(self):
""" .. seealso:: :func:`os.removedirs` """
os.removedirs(self)
return self
def removedirs_p(self):
""" Like :meth:`removedirs`, but does not raise an exception if the
directory is not empty or does not exist. """
try:
self.removedirs()
except OSError:
_, e, _ = sys.exc_info()
if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
raise
return self
# --- Modifying operations on files
def touch(self):
""" Set the access/mo |
"""
$Id: Opcode.py,v 1.6.2.1 2011/03/16 20:06:39 customdesigned Exp $
This file is part of the pydns project.
Homepage: http://pydns.sourceforge.net
This code is | covered by the standard Python License. See LICENSE for details.
Opcode values in message header. RFC 1035, 1996, 2136.
"""
QUERY = 0
IQUERY = 1
STATUS = 2
NOTIFY = 4
UPDATE = 5
# C | onstruct reverse mapping dictionary
_names = dir()
opcodemap = {}
for _name in _names:
if _name[0] != '_': opcodemap[eval(_name)] = _name
def opcodestr(opcode):
if opcodemap.has_key(opcode): return opcodemap[opcode]
else: return `opcode`
#
# $Log: Opcode.py,v $
# Revision 1.6.2.1 2011/03/16 20:06:39 customdesigned
# Refer to explicit LICENSE file.
#
# Revision 1.6 2002/04/23 10:51:43 anthonybaxter
# Added UPDATE, NOTIFY.
#
# Revision 1.5 2002/03/19 12:41:33 anthonybaxter
# tabnannied and reindented everything. 4 space indent, no tabs.
# yay.
#
# Revision 1.4 2002/03/19 12:26:13 anthonybaxter
# death to leading tabs.
#
# Revision 1.3 2001/08/09 09:08:55 anthonybaxter
# added identifying header to top of each file
#
# Revision 1.2 2001/07/19 06:57:07 anthony
# cvs keywords added
#
#
|
import pickle
import redis
from pod_manager.settings import REDIS_HOST, REDIS_PORT, REDIS_DB
__all__ = [
'get_client',
'cache_object',
'g | et_object'
]
def get_client():
client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
return client
def cache_object(client, key, obj, ttl=60):
pipe = client.pipeline()
data = pickle.dumps(obj)
pipe.set(key, data)
if ttl:
pipe.expire(key, ttl)
pipe.execute()
def get_object(client, key):
data = client.get(key)
if not data:
return None
obj = pickle.l | oads(data)
return obj
|
import numpy as np
arr = np.arange(10)
arr
arr[5]
arr[5:8]
arr[5:8] = 12
arr
arr_slice = arr[5:8]
arr_slice
arr_slice[1] = 12345
arr
arr_slice[:] = 64
arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
arr2d[2]
arr2d[0, 2]
arr2d[0][2]
arr3d = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
old_vals = arr3d[0].copy()
arr3d[0] = 42
arr3d[1, 0]
arr[1:6]
arr2d | [:2]
arr2d[:2, 1: | ]
arr2d[2, :1]
arr2d[:, :1]
arr2d[:, :1].shape
arr2d[:2, 1:] = 0
arr2d
|
import sys
sys.p | ath.append('..')
from helpers import render_frames
from graphs.ForwardRendering import ForwardRendering as g
from falcor import *
m.addGraph(g)
m.loadScene('Cerberus/Standard/Cerberus.pyscene')
# default
render_frames(m, 'defau | lt', frames=[1,16,64])
exit()
|
# Codon Usage probability for each scpecie'
USAGE_FREQ = {'E.coli':{'GGG': 0.15,'GGA': 0.11,'GGT': 0.34,'GGC': 0.4,\
'GAG': 0.31,'GAA': 0.69,'GAT': 0.63,'GAC': 0.37,\
'GTG': 0.37,'GTA': 0.15,'GTT': 0.26,'GTC': 0.22,\
'GCG': 0.36,'GCA': 0.21,'GCT': 0.16,'GCC': 0.27,\
'AGG': 0.02,'AGA': 0.04,'CGG': 0.1,'CGA': 0.06,\
'CGT': 0.38,'CGC': 0.4,'AAG': 0.23,'AAA': 0.77,\
'AAT': 0.45,'AAC': 0.55,'ATG': 1.0,'ATA': 0.07,\
'ATT': 0.51,'ATC': 0.42,'ACG': 0.27,'ACA': 0.13,\
'ACT': 0.17,'ACC': 0.44,'TGG': 1.0,'TGT': 0.45,\
'TGC': 0.55,'TAG': 0.07,'TAA': 0.64,'TGA': 0.29,\
'TAT': 0.57,'TAC': 0.43,'TTT': 0.57,'TTC': 0.43,\
'AGT': 0.15,'AGC': 0.28,'TCG': 0.15,'TCA': 0.12,\
'TCT': 0.15,'TCC': 0.15,'CAG': 0.65,'CAA': 0.35,\
'CAT': 0.57,'CAC': 0.43,'TTG': 0.13,'TTA': 0.13,\
'CTG': 0.5,'CTA': 0.04,'CTT': 0.1,'CTC': 0.1,\
'CCG': 0.52,'CCA': 0.19,'CCT': 0.16,'CCC': 0.12},\
'human':{'CTT': 0.13, 'ACC': 0.36, 'ACA': 0.28,\
'AAA': 0.42, 'ATC': 0.48, 'AAC': 0.54, 'ATA': 0.16,\
'AGG': 0.2, 'CCT': 0.28, 'ACT': 0.24, 'AGC': 0.24,\
'AAG': 0.58, 'AGA': 0.2, 'CAT': 0.41, 'AAT': 0.46,\
'ATT': 0.36, 'CTG': 0.41, 'CTA': 0.07, 'CTC': 0.2,\
'CAC': 0.59, 'ACG': 0.12, 'CAA': 0.25, 'AGT': 0.15,\
'CCA': 0.27, 'CCG': 0.11, 'CCC': 0.33, 'TAT': 0.43,\
'GGT': 0.16, 'TGT': 0.45, 'CGA': 0.11, 'CAG': 0.75,\
'TCT': 0.18, 'GAT': 0.46, 'CGG': 0.21, 'TTT': 0.45,\
'TGC': 0.55, 'GGG': 0.25, 'TAG': 0.2, 'GGA': 0.25,\
'TGG': 1.0, 'GGC': 0.34, 'TAC': 0.57, 'TTC': 0. | 55,\
'TCG': 0.06, 'TTA': 0.07, 'TTG': 0.13, 'CGT': 0.08,\
'GAA': 0.42, 'TAA': 0.28, 'GCA': 0.23, 'GTA': 0.11,\
| 'GCC': 0.4, 'GTC': 0.24, 'GCG': 0.11, 'GTG': 0.47,\
'GAG': 0.58, 'GTT': 0.18, 'GCT': 0.26, 'TGA': 0.52,\
'GAC': 0.54, 'TCC': 0.22, 'TCA': 0.15, 'ATG': 1.0,\
'CGC': 0.19}
}
# Aminoacid to codon translation table
A2C_DICT = {'I' : [ u'ATT',u'ATC',u'ATA' ],
'L' : [ u'CTT', u'CTC', u'CTA', u'CTG', u'TTA', u'TTG' ],
'V' : [ u'GTT', u'GTC', u'GTA', u'GTG' ],
'F' : [ u'TTT', u'TTC' ],
'M' : [ u'ATG' ],
'C' : [ u'TGT', u'TGC' ],
'A' : [ u'GCT',u'GCC', u'GCA',u'GCG' ],
'G' : [ u'GGT', u'GGC',u'GGA', u'GGG' ],
'P' : [ u'CCT', u'CCC', u'CCA', u'CCG' ],
'T' : [ u'ACT',u'ACC', u'ACA', u'ACG' ],
'S' : [ u'TCT', u'TCC', u'TCA', u'TCG', u'AGT', u'AGC' ],
'Y' : [ u'TAT', u'TAC' ],
'W' : [ u'TGG' ],
'Q' : [ u'CAA', u'CAG' ],
'N' : [ u'AAT', u'AAC' ],
'H' : [ u'CAT' ,u'CAC' ],
'E' : [ u'GAA', u'GAG' ],
'D' : [ u'GAT', u'GAC' ],
'K' : [ u'AAA', u'AAG' ],
'R' : [ u'CGT', u'CGC' ,u'CGA', u'CGG', u'AGA', u'AGG' ],
'*' : [ u'TAA', u'TAG' ,u'TGA' ]}
# Aminoacid to codon translation table
A2C_NNS_DICT = {'I' : [u'ATC' ],
'L' : [ u'CTC', u'CTG', u'TTG' ],
'V' : [ u'GTC', u'GTG' ],
'F' : [ u'TTC' ],
'M' : [ u'ATG' ],
'C' : [ u'TGC' ],
'A' : [ u'GCC', u'GCG' ],
'G' : [ u'GGC', u'GGG' ],
'P' : [ u'CCC', u'CCG' ],
'T' : [ u'ACC', u'ACG' ],
'S' : [ u'TCC', u'TCG', u'AGC' ],
'Y' : [ u'TAC' ],
'W' : [ u'TGG' ],
'Q' : [ u'CAG' ],
'N' : [ u'AAC' ],
'H' : [ u'CAC' ],
'E' : [ u'GAG' ],
'D' : [ u'GAC' ],
'K' : [ u'AAG' ],
'R' : [ u'CGC' , u'CGG', u'AGG' ],
'*' : [ u'TAG' ]}
# codon to Aminoacid translation table
C2A_DICT = {u'ATT':'I', u'ATC':'I', u'ATA':'I',
u'CTT':'L', u'CTC':'L', u'CTA':'L', u'CTG':'L', u'TTA':'L', u'TTG':'L',
u'GTT':'V', u'GTC':'V', u'GTA':'V', u'GTG' :'V',
u'TTT':'F', u'TTC':'F',
u'ATG':'M',
u'TGT':'C', u'TGC':'C',
u'GCT':'A', u'GCC':'A', u'GCA':'A', u'GCG':'A',
u'GGT':'G', u'GGC':'G', u'GGA':'G', u'GGG':'G',
u'CCT':'P', u'CCC':'P', u'CCA':'P', u'CCG':'P',
u'ACT':'T', u'ACC':'T', u'ACA':'T', u'ACG':'T',
u'TCT':'S', u'TCC':'S', u'TCA':'S', u'TCG':'S', u'AGT':'S', u'AGC':'S',
u'TAT':'Y', u'TAC':'Y',
u'TGG':'W',
u'CAA':'Q', u'CAG':'Q',
u'AAT':'N', u'AAC':'N',
u'CAT':'H', u'CAC':'H',
u'GAA':'E', u'GAG':'E',
u'GAT':'D', u'GAC':'D',
u'AAA':'K', u'AAG':'K',
u'CGT':'R', u'CGC':'R', u'CGA':'R', u'CGG':'R', u'AGA':'R', u'AGG':'R',
u'TAA':'*', u'TAG':'*', u'TGA':'*'}
# Stop codons dict
STOP_DICT = {u'TAA': '*', u'TAG': '*', u'TGA': '*'}
STOP_CODONS = [u'TAA', u'TAG', u'TGA']
|
used to insert / create / modify instructions
This class will have to support all the other class creating it.
"""
def __init__(self, current_module = None, context=None):
self.__module = current_module
self.__insertion_point = None
self.__insertion_point_idx = 0
self.__orphaned_instructions = []
self.__context = context
self.__current_bb = None
@property
def module(self):
return self.__module
@module.setter
def module(self, mod):
self.__module = mod
@property
def context(self):
return self.__context
@context.setter
def context(self, ctx):
self.__context = ctx
def get_current_bb(self):
assert self.__current_bb is not None
return self.__current_bb
def insert_after(self, ip):
if isinstance(ip, BasicBlock):
self.__insertion_point = ip
self.__insertion_point_idx = 0
| self.__current_bb = ip
elif isinstance(ip, Instruction):
self.__insertion_point = ip
self.__insertion_point_idx = ip.parent.find_instruction_idx(ip)
if self.__insertion_point_idx is None:
raise InvalidInstructionException("Count not find instruction in its parent basic block")
else:
self.__ins | ertion_point_idx += 1
else:
raise InvalidTypeException("Expected either Basic Block or Instruction")
def insert_before(self, ip):
if isinstance(ip, BasicBlock):
self.__insertion_point = ip
self.__insertion_point_idx = -1
self.__current_bb = ip
elif isinstance(ip, Instruction):
self.__insertion_point = ip
self.__insertion_point_idx = ip.parent.find_instruction_idx(ip)
if self.__insertion_point_idx == None:
raise InvalidInstructionException("Count not find instruction in its parent basic block")
elif self.__insertion_point_idx == 0:
self.__insertion_point_idx = 0
else:
self.__insertion_point_idx -= 1
else:
raise InvalidTypeException("Expected either Basic Block or Instruction")
def __add_instruction(self, inst):
if self.__insertion_point_idx == -1:
# This is an orphaned instruction
self.__orphaned_instructions.append(inst)
elif isinstance(self.__insertion_point, BasicBlock):
self.__insertion_point.instructions.append(inst)
self.__insertion_point = inst
elif isinstance(self.__insertion_point, Instruction):
bb = self.__insertion_point.parent
bb.instructions.insert(self.__insertion_point_idx + 1, inst)
self.__insertion_point_idx += 1
self.__insertion_point = inst
else:
raise Exception("Could not add instruction")
def const_fold_binary_op(self, lhs, rhs, op):
return None
# if isinstance(lhs, Number) and isinstance(rhs, Number):
# lhs = lhs.number
# rhs = rhs.number
# result = BINARY_OPERATORS[op](lhs, rhs)
# return Number(result)
# else:
# return None
def create_function(self, name, args):
f = Function(name, args)
self.__module.functions[name] = f
return f
def set_entry_point(self, function):
self.__module.entry_point = function
def create_global(self, name, initializer):
g = Global(name, initializer)
self.__module.add_global(g)
def create_basic_block(self, name, parent):
bb = BasicBlock(name, parent)
return bb
def create_return(self, value = None, name=None):
ret_inst = ReturnInstruction(value)
self.__add_instruction(ret_inst)
def create_branch(self, bb, name=None):
if not isinstance(bb, BasicBlock):
raise InvalidTypeException("Expected a Basic Block")
branch_inst = BranchInstruction(bb, self.__current_bb, name)
self.__add_instruction(branch_inst)
return branch_inst
def create_cond_branch(self, cmp_inst, value, bb_true, bb_false, name=None):
cond_branch = ConditionalBranchInstruction(cmp_inst, value, bb_true, bb_false, self.__current_bb, name)
self.__add_instruction(cond_branch)
return cond_branch
def create_call(self, func, args, name=None):
call_inst = CallInstruction(func, args, self.__current_bb, name)
self.__add_instruction(call_inst)
return call_inst
def create_add(self, lhs, rhs, name=None):
folded_inst = self.const_fold_binary_op(lhs, rhs, '+')
if folded_inst is not None:
return folded_inst
add_inst = AddInstruction(lhs, rhs, self.__current_bb, name)
self.__add_instruction(add_inst)
return add_inst
def create_sub(self, lhs, rhs, name=None):
folded_inst = self.const_fold_binary_op(lhs, rhs, '-')
if folded_inst is not None:
return folded_inst
sub_inst = SubInstruction(lhs, rhs, self.__current_bb, name)
self.__add_instruction(sub_inst)
return sub_inst
def create_mul(self, lhs, rhs, name=None):
folded_inst = self.const_fold_binary_op(lhs, rhs, '*')
if folded_inst is not None:
return folded_inst
mul_inst = MulInstruction(lhs, rhs, self.__current_bb, name)
self.__add_instruction(mul_inst)
return mul_inst
def create_div(self, lhs, rhs, name=None):
folded_inst = self.const_fold_binary_op(lhs, rhs, '/')
if folded_inst is not None:
return folded_inst
div_inst = DivInstruction(lhs, rhs, self.__current_bb, name)
self.__add_instruction(div_inst)
return div_inst
def create_icmp(self, lhs, rhs, comparator, name=None):
icmp_inst = ICmpInstruction(CompareTypes.SLE, lhs, rhs, self.__current_bb, name)
self.__add_instruction(icmp_inst)
return icmp_inst
def create_select(self, cond, val_true, val_false, name=None):
select_inst = SelectInstruction(cond, val_true, val_false, self.__current_bb, name)
self.__add_instruction(select_inst)
return select_inst
def create_alloca(self, numEls=None, name=None):
alloca_inst = AllocaInstruction(numEls, self.__current_bb, name)
self.__add_instruction(alloca_inst)
return alloca_inst
def create_load(self, alloca):
load_inst = LoadInstruction(alloca, parent=self.__current_bb)
self.__add_instruction(load_inst)
return load_inst
def create_store(self, alloca, value):
store_inst = StoreInstruction(alloca, value, parent=self.__current_bb)
self.__add_instruction(store_inst)
return store_inst
def create_shl(self, op1, op2, name=None):
folded_inst = self.const_fold_binary_op(op1, op2, '<<')
if folded_inst is not None:
return folded_inst
shl_inst = ShiftLeftInstruction(op1, op2, self.__current_bb, name)
self.__add_instruction(shl_inst)
return shl_inst
def create_lshr(self, op1, op2, name=None):
folded_inst = self.const_fold_binary_op(op1, op2, '>>')
if folded_inst is not None:
return folded_inst
lshr_inst = LogicalShiftRightInstruction(op1, op2, self.__current_bb, name)
self.__add_instruction(lshr_inst)
return lshr_inst
def create_ashr(self, op1, op2, name=None):
ashr_inst = ArithmeticShiftRightInstruction(op1, op2, self.__current_bb, name)
self.__add_instruction(ashr_inst)
return ashr_inst
def create_and(self, op1, op2, name=None):
folded_inst = self.const_fold_binary_op(op1, op2, '&')
if folded_inst is not None:
return folded_inst
and_inst = AndInstruction(op1, op2, self.__current_bb, name)
self.__add_instruction(and_inst)
return and_inst
def create_or(self, op1, op2, name=None):
folded_inst = self.const_fold_binary_op(op1, op2, '|')
if folded_inst is not |
ate_proxy(self, proxy, proxy_auth):
if proxy and not proxy.scheme == 'http':
raise ValueError("Only http proxies are supported")
if proxy_auth and not isinstance(proxy_auth, helpers.BasicAuth):
raise ValueError("proxy_auth must be None or BasicAuth() tuple")
self.proxy = proxy
self.proxy_auth = proxy_auth
def keep_alive(self):
if self.version < HttpVersion10:
# keep alive not supported at all
return False
if self.version == HttpVersion10:
if self.headers.get(hdrs.CONNECTION) == 'keep-alive':
return True
else: # no headers means we close for Http 1.0
return False
elif self.headers.get(hdrs.CONNECTION) == 'close':
return False
return True
@asyncio.coroutine
def write_bytes(self, writer, conn):
"""Support coroutines that yields bytes objects."""
# 100 response
if self._continue is not None:
yield from writer.drain()
yield from self._continue
try:
if isinstance(self.body, payload.Payload):
yield from self.body.write(writer)
else:
if isinstance(self.body, (bytes, bytearray)):
self.body = (self.body,)
for chunk in self.body:
writer.write(chunk)
yield from writer.write_eof()
except OSError as exc:
new_exc = aiohttp.ClientOSError(
exc.errno,
'Can not write request body for %s' % self.url)
new_exc.__context__ = exc
new_exc.__cause__ = exc
conn.protocol.set_exception(new_exc)
except Exception as exc:
conn.protocol.set_exception(exc)
finally:
self._writer = None
def send(self, conn):
# Specify request target:
# - CONNECT request must send authority form URI
# - not CONNECT proxy must send absolute form URI
# - most common is origin form URI
if self.method == hdrs.METH_CONNECT:
path = '{}:{}'.format(self.url.raw_host, self.url.port)
elif self.proxy and not self.ssl:
path = str(self.url)
else:
path = self.url.raw_path
if self.url.raw_query_string:
path += '?' + self.url.raw_query_string
writer = PayloadWriter(conn.writer, self.loop)
if self.compress:
writer.enable_compression(self.compress)
if self.chunked is not None:
writer.enable_chunking()
# set default content-type
if (self.method in self.POST_METHODS and
hdrs.CONTENT_TYPE not in self.skip_auto_headers and
hdrs.CONTENT_TYPE not in self.headers):
self.headers[hdrs.CONTENT_TYPE] = 'application/octet-stream'
# set the connection header
connection = self.headers.get(hdrs.CONNECTION)
if not connection:
if self.keep_alive():
if self.version == HttpVersion10:
connection = 'keep-alive'
else:
if self.version == HttpVersion11:
connection = 'close'
if connection is not None:
self.headers[hdrs.CONNECTION] = connection
# status + headers
status_line = '{0} {1} HTTP/{2[0]}.{2[1]}\r\n'.format(
self.method, path, self.version)
writer.write_headers(status_line, self.headers)
self._writer = helpers.ensure_future(
self.write_bytes(writer, conn), loop=self.loop)
self.response = self.response_class(
self.method, self.original_url,
writer=self._writer, con | tinue100=self._continue, timer=self._timer)
self.response._post_init(self.loop)
return self.response
@asyncio.coroutine
def close(self):
if self._writer is not None:
try:
yield from self._writer
finally:
self._ | writer = None
def terminate(self):
if self._writer is not None:
if not self.loop.is_closed():
self._writer.cancel()
self._writer = None
class ClientResponse(HeadersMixin):
# from the Status-Line of the response
version = None # HTTP-Version
status = None # Status-Code
reason = None # Reason-Phrase
content = None # Payload stream
headers = None # Response headers, CIMultiDictProxy
raw_headers = None # Response raw headers, a sequence of pairs
_connection = None # current connection
flow_control_class = FlowControlStreamReader # reader flow control
_reader = None # input stream
_source_traceback = None
# setted up by ClientRequest after ClientResponse object creation
# post-init stage allows to not change ctor signature
_loop = None
_closed = True # to allow __del__ for non-initialized properly response
def __init__(self, method, url, *,
writer=None, continue100=None, timer=None):
assert isinstance(url, URL)
self.method = method
self.headers = None
self.cookies = SimpleCookie()
self._url = url
self._content = None
self._writer = writer
self._continue = continue100
self._closed = True
self._history = ()
self._timer = timer if timer is not None else TimerNoop()
@property
def url(self):
return self._url
@property
def url_obj(self):
warnings.warn(
"Deprecated, use .url #1654", DeprecationWarning, stacklevel=2)
return self._url
@property
def host(self):
return self._url.host
@property
def _headers(self):
return self.headers
def _post_init(self, loop):
self._loop = loop
if loop.get_debug():
self._source_traceback = traceback.extract_stack(sys._getframe(1))
def __del__(self, _warnings=warnings):
if self._loop is None:
return # not started
if self._closed:
return
if self._connection is not None:
self._connection.release()
self._cleanup_writer()
# warn
if __debug__:
if self._loop.get_debug():
_warnings.warn("Unclosed response {!r}".format(self),
ResourceWarning)
context = {'client_response': self,
'message': 'Unclosed response'}
if self._source_traceback:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
def __repr__(self):
out = io.StringIO()
ascii_encodable_url = str(self.url)
if self.reason:
ascii_encodable_reason = self.reason.encode('ascii',
'backslashreplace') \
.decode('ascii')
else:
ascii_encodable_reason = self.reason
print('<ClientResponse({}) [{} {}]>'.format(
ascii_encodable_url, self.status, ascii_encodable_reason),
file=out)
print(self.headers, file=out)
return out.getvalue()
@property
def connection(self):
return self._connection
@property
def history(self):
"""A sequence of of responses, if redirects occurred."""
return self._history
@asyncio.coroutine
def start(self, connection, read_until_eof=False):
"""Start response processing."""
self._closed = False
self._protocol = connection.protocol
self._connection = connection
connection.protocol.set_response_params(
timer=self._timer,
skip_payload=self.method.lower() == 'head',
skip_status_codes=(204, 304),
read_until_eof=read_until_eof)
with self._timer:
while True:
# read response
(message, pay |
"""
This script can be used to ssh to a cloud server started by GNS3. It copies
the ssh keys for a server to a temp file on disk and starts ssh using the
keys.
Right now it only connects to the first cloud server listed in the config
file.
"""
import getopt
import os
import sys
from PyQt4 import QtCore, QtGui
SCRIPT_NAME = os.path.basename(__file__)
def parse_cmd_line(argv):
"""
Parse command line arguments
argv: Passed in sys.argv
"""
usage = """
USAGE: %s [-l] [-s <server_num>]
If no options are supplied a connection to server 1 will be opened.
Options:
-h, --help Display this menu :)
-l, --list List instances that are tracked
-s, --server-num Connect to this server number (1-indexed)
""" % (SCRIPT_NAME)
short_args = "hls:"
long_args = ("help", "list", "server-num=")
try:
opts, extra_opts = getopt.getopt(argv[1:], short_args, long_args)
except getopt.GetoptError as e:
print("Unrecognized command line option or missing required argument: %s" % (e))
print(usage)
sys.exit(2)
cmd_line_option_list = {'action': 'ssh', 'server': '1'}
for opt, val in opts:
if opt in ("-h", "--help"):
print(usage)
sys.exit(0)
elif opt in ("-l", "--list"):
cmd_line_option_list['action'] = 'list'
elif opt in ("-s", "--server-num"):
cmd_line_option_list['server'] = val
return cmd_line_option_list
def setup():
if sys.platform.startswith('win') or sys.platform.startswith('darwin'):
QtCore.QSettings.setDefaultFormat(QtCore.QSettings.IniFormat)
app = QtGui.QApplication([])
app.setOrganizationName("GNS3")
app.setOrganizationDomain("gns3.net")
app.setApplicationName("GNS3")
if not os.path.isfile(QtCore.QSettings().fileName()):
print('Config file {} not found! Aborting...'.format(QtCore.QSettings().fileName()))
sys.exit(1)
print('Config file: {}'.format(QtCore.QSettings().fileName()))
def read_cloud_settings():
settings = QtCore.QSettings()
settings.beginGroup("CloudInstances")
instances = []
# Load the instances
size = settings.beginReadArray("cloud_instance")
for index in range(0, size):
settings.setArrayIndex(index)
name = settings.value('name')
host = settings.value('host')
private_key = settings.value('private_key')
public_key = settings.value('public_key')
uid = settings.value('id')
instances.append((name, host, private_key, public_key, uid))
if len(instances) == 0:
raise Exception("Could not find any servers")
return instances
def main():
options = parse_cmd | _line(sys.argv)
setup()
instances = read_cloud_settings()
if options['action'] == 'ssh':
name, host, private_key, public_key, uid = instances[int(options['server']) - 1]
print('Instance name: {}'.format(name))
print('Host ip: {}'.format(host))
public_key_path = '/tmp/id_rsa.pub'
open(pu | blic_key_path, 'w').write(public_key)
private_key_path = '/tmp/id_rsa'
open(private_key_path, 'w').write(private_key)
cmd = 'chmod 0600 {}'.format(private_key_path)
os.system(cmd)
print('Per-instance ssh keys written to {}'.format(private_key_path))
cmd = 'ssh -i /tmp/id_rsa root@{}'.format(host)
print(cmd)
os.system(cmd)
elif options['action'] == 'list':
print('ID Name IP UID')
for idx, info in enumerate(instances):
name, host, private_key, public_key, uid = info
print('{:2d} {} {} {}'.format(idx + 1, name, host, uid))
return 0
if __name__ == "__main__":
sys.exit(main())
|
MILESTONE: {
'type': 'string',
'label': 'Gitlab Milestone',
},
URL: {
'type': 'string',
'label': 'Gitlab URL',
},
REPO: {
'type': 'string',
'label': 'Gitlab Repo Slug',
},
TYPE: {
'type': 'string',
'label': 'Gitlab Type',
},
NUMBER: {
'type': 'numeric',
'label': 'Gitlab Issue/MR #',
},
STATE: {
'type': 'string',
'label': 'Gitlab Issue/MR State',
},
UPVOTES: {
'type': 'numeric',
'label': 'Gitlab Upvotes',
},
DOWNVOTES: {
'type': 'numeric',
'label': 'Gitlab Downvotes',
},
}
UNIQUE_KEY = (REPO, TYPE, NUMBER,)
def _normalize_label_to_tag(self, label):
return re.sub(r'[^a-zA-Z0-9]', '_', label)
def to_taskwarrior(self):
if self.extra['type'] == 'merge_request':
priority = 'H'
milestone = self.record['milestone']
created = self.record['created_at']
updated = self.record['updated_at']
state = self.record['state']
upvotes = self.record['upvotes']
downvotes = self.record['downvotes']
else:
priority = self.origin['default_priority']
milestone = self.record['milestone']
created = self.record['created_at']
updated = self.record['updated_at']
state = self.record['state']
upvotes = 0
downvotes = 0
if milestone:
milestone = milestone['title']
if created:
created = self.parse_date(created)
if updated:
up | dated = self.parse_date(updated)
return {
'project': self.extra['project'],
'priority': priority,
'annotations': self.extra.get('annotations', []),
'tags': self.get_tags(),
self.URL: self.extra['issue_url'],
self.REPO: self.extra['project'],
self.TYPE: self.extra['type'],
| self.TITLE: self.record['title'],
self.DESCRIPTION: self.record['description'],
self.MILESTONE: milestone,
self.NUMBER: self.record['iid'],
self.CREATED_AT: created,
self.UPDATED_AT: updated,
self.STATE: state,
self.UPVOTES: upvotes,
self.DOWNVOTES: downvotes,
}
def get_tags(self):
tags = []
if not self.origin['import_labels_as_tags']:
return tags
context = self.record.copy()
label_template = Template(self.origin['label_template'])
for label in self.record.get('labels', []):
context.update({
'label': self._normalize_label_to_tag(label)
})
tags.append(
label_template.render(context)
)
return tags
def get_default_description(self):
return self.build_default_description(
title=self.record['title'],
url=self.get_processed_url(self.extra['issue_url']),
number=self.record['iid'],
cls=self.extra['type'],
)
class GitlabService(IssueService):
ISSUE_CLASS = GitlabIssue
CONFIG_PREFIX = 'gitlab'
def __init__(self, *args, **kw):
super(GitlabService, self).__init__(*args, **kw)
host = self.config_get_default(
'host', default='gitlab.com', to_type=six.text_type)
self.login = self.config_get('login')
token = self.config_get('token')
if not token or token.startswith('@oracle:'):
token = get_service_password(
self.get_keyring_service(self.config, self.target),
self.login, oracle=password,
interactive=self.config.interactive
)
self.auth = (host, token)
self.exclude_repos = []
if self.config_get_default('exclude_repos', None):
self.exclude_repos = [
item.strip() for item in
self.config_get('exclude_repos').strip().split(',')
]
self.include_repos = []
if self.config_get_default('include_repos', None):
self.include_repos = [
item.strip() for item in
self.config_get('include_repos').strip().split(',')
]
self.import_labels_as_tags = self.config_get_default(
'import_labels_as_tags', default=False, to_type=asbool
)
self.label_template = self.config_get_default(
'label_template', default='{{label}}', to_type=six.text_type
)
self.filter_merge_requests = self.config_get_default(
'filter_merge_requests', default=False, to_type=asbool
)
@classmethod
def get_keyring_service(cls, config, section):
login = config.get(section, cls._get_key('login'))
return "gitlab://%s@%s" % (login, host)
def get_service_metadata(self):
return {
'import_labels_as_tags': self.import_labels_as_tags,
'label_template': self.label_template,
}
def filter_repos(self, repo):
if self.exclude_repos:
if repo['path_with_namespace'] in self.exclude_repos:
return False
if self.include_repos:
if repo['path_with_namespace'] in self.include_repos:
return True
else:
return False
return True
def _get_notes(self, rid, issue_type, issueid):
tmpl = 'https://{host}/api/v3/projects/%d/%s/%d/notes' % (rid, issue_type, issueid)
return self._fetch_paged(tmpl)
def annotations(self, repo, url, issue_type, issue, issue_obj):
notes = self._get_notes(repo['id'], issue_type, issue['id'])
return self.build_annotations(
((
n['author']['username'],
n['body']
) for n in notes),
issue_obj.get_processed_url(url)
)
def _fetch(self, tmpl, **kwargs):
url = tmpl.format(host=self.auth[0])
headers = {'PRIVATE-TOKEN': self.auth[1]}
response = requests.get(url, headers=headers, **kwargs)
if response.status_code != 200:
raise IOError(
"Non-200 status code %r; %r; %r" %(
response.status_code, url, response.json))
if callable(response.json):
return response.json()
else:
return response.json
def _fetch_paged(self, tmpl):
params = {
'page': 1,
'per_page': 100,
}
full = []
while True:
items = self._fetch(tmpl, params=params)
full += items
if len(items) < params['per_page']:
break
params['page'] += 1
return full
def get_repo_issues(self, rid):
tmpl = 'https://{host}/api/v3/projects/%d/issues' % rid
issues = {}
for issue in self._fetch_paged(tmpl):
issues[issue['id']] = (rid, issue)
return issues
def get_repo_merge_requests(self, rid):
tmpl = 'https://{host}/api/v3/projects/%d/merge_requests' % rid
issues = {}
for issue in self._fetch_paged(tmpl):
issues[issue['id']] = (rid, issue)
return issues
def issues(self):
tmpl = 'https://{host}/api/v3/projects'
all_repos = self._fetch_paged(tmpl)
repos = filter(self.filter_repos, all_repos)
repo_map = {}
issues = {}
for repo in repos:
rid = repo['id']
repo_map[rid] = repo
issues.update(
self.get_repo_issues(rid)
)
log.name(self.target).debug(" Found {0} issues.", len(issues))
issues = filter(self.include, issues.values())
log.name(self.target).debug(" Pruned down to {0} issues.", len(issues))
for rid, issue in issues:
repo = repo_map[rid]
issue[ |
import warnings
from pyzabbix import ZabbixMetric, ZabbixSender
warnings.warn("Module '{name}' was deprecated, | use 'pyzabbix' instead."
"".format(name=__name__), DeprecationWarning)
| |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.core.validators
class Migration(migrations.Migration):
dependencies = [
('taskmanager', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Project',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=100, help_text='Enter the project name')),
('color', models.CharField(verbose_name='c | olor', validators=[django.core.validators.RegexValidator('(^#[0-9a-fA-F]{3}$)|(^#[0-9a-fA-F]{6}$)')], default='#fff', | max_length=7, help_text='Enter the hex color code, like #ccc or #cccccc')),
('user', models.ForeignKey(verbose_name='user', related_name='profjects', to='taskmanager.Profile')),
],
options={
'ordering': ('user', 'name'),
'verbose_name': 'Project',
'verbose_name_plural': 'Projects',
},
),
migrations.AlterUniqueTogether(
name='project',
unique_together=set([('user', 'name')]),
),
]
|
# -*- coding: utf-8 -*-
import hashlib
import json
import locale
import re
import trac.wiki.formatter
from trac.mimeview.api import Context
from time import strftime, localtime
from code_comments import db
from trac.util import Markup
from trac.web.href import Href
from trac.test import Mock, MockPerm
def md5_hexdigest(s):
return hashlib.md5(s).hexdigest()
VERSION = 1
class Comment(object):
columns = [column.name for column in db.schema['code_comments'].columns]
required = 'text', 'author'
_email_map = None
def __init__(self, req, env, data):
if isinstance(data, dict):
self.__dict__ = data
else:
self.__dict__ = dict(zip(self.columns, data))
self.env = env
self.req = req
if self._empty('version'):
self.version = VERSION
if self._empty('path'):
self.path = ''
self.html = format_to_html(self.req, self.env, self.text)
email = self.email_map().get(self.author, 'baba@baba.net')
self.email_md5 = md5_hexdigest(email)
attachment_info = self.attachment_info()
self.is_comment_to_attachment = 'attachment' == self.type
self.attachment_ticket = attachment_info['ticket']
self.attachment_filename = attachment_info['filename']
self.is_comment_to_changeset = 'changeset' == self.type
self.is_comment_to_file = 'browser' == self.type
def _empty(self, column_name):
return not hasattr(self, column_name) or not getattr(self, column_name)
def email_map(self):
if Comment._email_map is None:
Comment._email_map = {}
for username, name, email in self.env.get_known_users():
if email:
Comment._email_map[username] = email
return Comment._email_map
def validate(self):
missing = [
column_name
for column_name in self.required if self._empty(column_name)
]
if missing:
raise ValueError("Comment column(s) missing: %s"
% ', '.join(missing))
def href(self):
if self.is_comment_to_file:
href = self.req.href.browser(self.path, rev=self.revision,
codecomment=self.id)
elif self.is_comment_to_changeset:
href = self.req.href.changeset(self.revision, codecomment=self.id)
elif self.is_comment_to_attachment:
href = self.req.href('/attachment/ticket/%d/%s'
| % (self.attachment_ticket,
self.attachment_filename),
codecomment=self.id)
if self.line and not self.is_comment_to_changeset:
href += '#L' + str(self.line)
return href
def link_text(self):
if self.is_comment_to_changeset:
return self.changeset_link_text() |
if self.is_comment_to_attachment:
return self.attachment_link_text()
# except the two special cases of changesets (revision-only)
# and attachments (path-only), we must always have them both
assert self.path and self.revision
link_text = self.path + '@' + str(self.revision)
if self.line:
link_text += '#L' + str(self.line)
return link_text
def changeset_link_text(self):
if 0 != self.line:
return 'Changeset @%s#L%d (in %s)' % (self.revision, self.line,
self.path)
else:
return 'Changeset @%s' % self.revision
def attachment_link_text(self):
return '#%s: %s' % (self.attachment_ticket, self.attachment_filename)
def trac_link(self):
if self.is_comment_to_attachment:
return '[%s %s]' % (self.req.href())
return 'source:' + self.link_text()
def attachment_info(self):
info = {'ticket': None, 'filename': None}
if not self.path.startswith('attachment'):
return info
match = re.match(r'attachment:/ticket/(\d+)/(.*)', self.path)
if not match:
return info
info['ticket'] = int(match.group(1))
info['filename'] = match.group(2)
return info
def path_link_tag(self):
return Markup('<a href="%s">%s</a>' % (self.href(), self.link_text()))
def formatted_date(self):
encoding = locale.getlocale()[1] if locale.getlocale()[1] else 'utf-8'
return strftime('%d %b %Y, %H:%M',
localtime(self.time)).decode(encoding)
def get_ticket_relations(self):
query = """
SELECT ticket FROM ticket_custom
WHERE name = 'code_comment_relation' AND
(VALUE LIKE '%(comment_id)d' OR
VALUE LIKE '%(comment_id)d,%%' OR
VALUE LIKE '%%,%(comment_id)d' OR
VALUE LIKE '%%,%(comment_id)d,%%')
""" % {'comment_id': self.id}
return set([int(row[0]) for row in self.env.db_query(query)])
def get_ticket_links(self):
relations = self.get_ticket_relations()
links = ['[[ticket:%s]]' % relation for relation in relations]
return format_to_html(self.req, self.env, ', '.join(links))
def delete(self):
self.env.db_transaction("""
DELETE FROM code_comments WHERE id=%s
""", (self.id,))
class CommentJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Comment):
for_json = dict([
(name, getattr(o, name))
for name in o.__dict__
if isinstance(getattr(o, name), (basestring, int, list, dict))
])
for_json['formatted_date'] = o.formatted_date()
for_json['permalink'] = o.href()
return for_json
else:
return json.JSONEncoder.default(self, o)
def format_to_html(req, env, text):
req = Mock(href=Href('/'), abs_href=Href('http://www.example.com/'),
authname='anonymous', perm=MockPerm(), args={})
context = Context.from_request(req)
return trac.wiki.formatter.format_to_html(env, context, text)
|
#!/usr/bin/env python
# encoding: utf-8
from fabric.api import run, env
from cfg import aliyun2_cfg
fr | om helper import update_sys
env.hosts = ['root@{host}'.format(host=aliyun2_cfg['host'])]
env.password = aliyun2_cfg['root_pass']
def restart():
# run('supervisorctl restart drr1')
# run('supervisorctl restart drr2')
run('supervisorctl restart yunsuan1')
run('supervisorctl restart yunsuan2')
run('su | pervisorctl restart gislab')
|
"""Package initialization file for pynoddy"""
import os.path
import sys
import subprocess
# save this module path for relative paths
package_directory = os.path.dirname(os.path.abspath(__file__))
# paths to noddy & topology executables
# noddyPath = os.path.join(package_directory,'../noddy/noddy')
# topologyPath = os.path.join(package_directory,'../topology/topology')
# noddyPath = os.path.join(package_directory, 'noddy/noddy')
# topologyPath = os.path.join(package_directory, 'topology/topology')
# global variables
ensure_discrete_volumes = True # if True, spatially separated but otherwise
# identical volumes are given separate codes.
null_volume_threshold = 20 # volumes smaller than this are ignored
# completely (as they represent pixelation artefacts).
#
# NOTE: check for noddy installation should be performed with unittests!
#
#
# # ensure correct noddy & topology builds are present
# if not os.path.exists(noddyPath) and not os.path.exists(noddyPath + ".exe"):
# print("Error: could not find a compiled version of noddy at %s. \
# Please ensure the source has been compiled (using GCC and compile.bat \
# (windows) or compile.sh (unix))." % noddyPath)
# if not os.path.exists(topologyPath) and not os.path.exists(topologyPath + ".exe"):
# print("Warning: could not find a compiled version of topology at %s. \
# Please ensure the source has been compiled (using GCC and compile.bat\
# (windows) or compile.sh (unix))." % topologyPath)
# Some helper functions are defined directly here:
# Idea to check for program path,
# taken from: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def compute_model(history, output_name, **kwds):
"""Call Noddy and compute the history file
**Arguments**:
- *history* = string : filename of history file
- *output_name* = string : basename for output files
**Optional Keywords**:
- *sim_type* = 'BLOCK', 'GEOPHYSICS', 'SURFACES', 'BLOCK_GEOPHYS',
'TOPOLOGY', 'BLOCK_SURFACES', 'ALL':
type of Noddy simulation (default: 'BLOCK')
- *program_name* = string : name of program
(default: noddy.exe or noddy, both checked)
- *verbose* = bool: verbose mode, print out information for debugging (default = False)
- *noddy_path* = path: location of Noddy executable (default: checks environment variable)
**Returns**:
-Returns any text outputted by the noddy executable.
"""
sim_type = kwds.get("sim_type", 'BLOCK')
# actively select noddy executable
if "noddy_path" in kwds:
noddy_path = kwds['noddy_path']
else:
np1 = which("noddy")
np2 = which("noddy.exe")
if np1 is not None:
noddy_path = np1
elif np2 is not None:
noddy_path = np2
else:
raise OSError("""
Unable to find noddy executable. Make sure it's accessible either
through your PATH environment variable or its being passed as
keyword argument 'noddy_path' into 'pynoddy.compute_model()'.
""")
if "verbose" in kwds and kwds['verbose']:
out = "Running noddy executable at %s(.exe)\n" % noddy_path
else:
out = ""
# check if Python > 3.5: use subprocess.run():
if sys.version_info[0] == 3 and sys.version_info[1] > 4:
# noddy_path = 'noddy'
subprocess.run([noddy_path, history, output_name, sim_type],
shell=False, stdout=subprocess.PIPE)
else:
try: # try running .exe file (windows only)
out += subprocess.Popen([noddy_path + ".exe", history, output_name, sim_type],
shell=False, stderr=subprocess.PIPE,
stdout=subprocess.PIPE).stdout.read()
subprocess.Popen.communicate()
except OSError: # obviously not running windows - try just the binary
# out += subprocess.Popen([noddy_path, history, output_name, sim_type],
# shell=False, stderr=subprocess.PIPE,
# stdout=subprocess.PIPE).stdout.read()
p1 = subprocess.Popen([noddy_path, history, output_name, sim_type],
shell=False, stdout=subprocess.PIPE)
subprocess.Popen.wait(p1)
# out += open(p1.stdout).readlines()
# Thought: Is there any reason compute_topology should not be called here if sim_type == "TOPOLOGY"???
# It could simplify things a lot....
return out
def compute_topology(rootname, **kwds):
"""Call the topology executable to compute a models topology.
**Arguments**:
- *rootname* = string : rootname of the noddy model to calculate topology for
**Optional Keywords**:
- *ensure_discrete_volumes* = True if topological units are broken down into
separate, spatially continuous volumes. Otherwise
some topological units may represent two separate
rock volumes (eg. if a folded unit has been truncated
by an unconformity). Default is True, though this is
a global variable (pynoddy.ensure_discrete_volumes)
so it can be changed during runtime.
- *null_volume_threshold* = The sma | llest non-null volume. volumes smaller than this are
ignored by the topology algorithm (as they represent pixelation artefacts).
The default is 20 voxels, though thi | s is a global variable and can be changed
with pynoddy.null_volume_threshold.
- *topology_path* = path: location of executable for topology calculation
**Returns**
-Returns any text outputted by the topology executable, including errors.
"""
dvol = kwds.get('ensure_discrete_volumes', ensure_discrete_volumes)
nvt = kwds.get('null_volume_threshold', null_volume_threshold)
# actively select noddy executable
if "topology_path" in kwds:
topology_path = kwds['topology_path']
else:
tp1 = which("topology")
tp2 = which("topology.exe")
if tp1 is not None:
topology_path = tp1
elif tp2 is not None:
topology_path = tp2
else:
raise OSError
# convert to string
if dvol:
dvol = "1"
else:
dvol = "0"
out = "Running topology executable at %s(.exe)\n" % topology_path
try: # try running .exe file (windows only)
out = subprocess.Popen([topology_path + ".exe", rootname, dvol, str(nvt)],
shell=False, stderr=subprocess.PIPE,
stdout=subprocess.PIPE).stdout.read()
except OSError: # obviously not running windows - try just the binary
out = subprocess.Popen([topology_path, rootname, dvol, str(nvt)],
shell=False, stderr=subprocess.PIPE,
stdout=subprocess.PIPE).stdout.read()
return out
|
e proper distances"""
# These distances where obtained by gmx distance so they are in nm
ref_id = 13937
results = np.array([0.0, 0.270, 0.285, 0.096, 0.096, 0.015, 0.278, 0.268, 0.179, 0.259, 0.290,
0.270]) * 10
results_grid = run_grid_search(universe, ref_id).get_pair_distances()
assert_allclose(np.sort(results), np.sort(results_grid), atol=1e-2)
@pytest.mark.parametrize('box, results',
((None, [3, 13, 24]),
(np.array([10., 10., 10., 90., 90., 90.]), [3, 13, 24, 39, 67]),
(np.array([10., 10., 10., 60., 75., 90.]), [3, 13, 24, 39, 60, 79])))
def test_nsgrid_search(box, results):
np.random.seed(90003)
points = (np.random.uniform(low=0, high=1.0,
size=(100, 3))*(10.)).astype(np.float32)
cutoff = 2.0
query = np.array | ([1., 1., 1.], dtype=np.float32).reshape((1, 3))
if box is None:
pseud | obox = np.zeros(6, dtype=np.float32)
all_coords = np.concatenate([points, query])
lmax = all_coords.max(axis=0)
lmin = all_coords.min(axis=0)
pseudobox[:3] = 1.1*(lmax - lmin)
pseudobox[3:] = 90.
shiftpoints, shiftquery = points.copy(), query.copy()
shiftpoints -= lmin
shiftquery -= lmin
searcher = nsgrid.FastNS(cutoff, shiftpoints, box=pseudobox, pbc=False)
searchresults = searcher.search(shiftquery)
else:
searcher = nsgrid.FastNS(cutoff, points, box)
searchresults = searcher.search(query)
indices = searchresults.get_pairs()[:, 1]
assert_equal(np.sort(indices), results)
@pytest.mark.parametrize('box, result',
((None, 21),
(np.array([0., 0., 0., 90., 90., 90.]), 21),
(np.array([10., 10., 10., 90., 90., 90.]), 26),
(np.array([10., 10., 10., 60., 75., 90.]), 33)))
def test_nsgrid_selfsearch(box, result):
np.random.seed(90003)
points = (np.random.uniform(low=0, high=1.0,
size=(100, 3))*(10.)).astype(np.float32)
cutoff = 1.0
if box is None or np.allclose(box[:3], 0):
# create a pseudobox
# define the max range
# and supply the pseudobox
# along with only one set of coordinates
pseudobox = np.zeros(6, dtype=np.float32)
lmax = points.max(axis=0)
lmin = points.min(axis=0)
pseudobox[:3] = 1.1*(lmax - lmin)
pseudobox[3:] = 90.
shiftref = points.copy()
shiftref -= lmin
searcher = nsgrid.FastNS(cutoff, shiftref, box=pseudobox, pbc=False)
searchresults = searcher.self_search()
else:
searcher = nsgrid.FastNS(cutoff, points, box=box)
searchresults = searcher.self_search()
pairs = searchresults.get_pairs()
assert_equal(len(pairs), result)
def test_nsgrid_probe_close_to_box_boundary():
# FastNS.search used to segfault with this box, cutoff and reference
# coordinate prior to PR #2136, so we ensure that this remains fixed.
# See Issue #2132 for further information.
ref = np.array([[55.783722, 44.190044, -54.16671]], dtype=np.float32)
box = np.array([53.785854, 43.951054, 57.17597, 90., 90., 90.], dtype=np.float32)
cutoff = 3.0
# search within a configuration where we know the expected outcome:
conf = np.ones((1, 3), dtype=np.float32)
searcher = nsgrid.FastNS(cutoff, conf, box)
results = searcher.search(ref)
# check if results are as expected:
expected_pairs = np.zeros((1, 2), dtype=np.int64)
expected_dists = np.array([2.3689647], dtype=np.float64)
assert_equal(results.get_pairs(), expected_pairs)
assert_allclose(results.get_pair_distances(), expected_dists, rtol=1.e-6)
def test_zero_max_dist():
# see issue #2656
# searching with max_dist = 0.0 shouldn't cause segfault (and infinite subboxes)
ref = np.array([1.0, 1.0, 1.0], dtype=np.float32)
conf = np.array([2.0, 1.0, 1.0], dtype=np.float32)
box = np.array([10., 10., 10., 90., 90., 90.], dtype=np.float32)
res = mda.lib.distances._nsgrid_capped(ref, conf, box=box, max_cutoff=0.0)
@pytest.fixture()
def u_pbc_triclinic():
u = mda.Universe(PDB)
u.dimensions = [10, 10, 10, 60, 60, 60]
return u
def test_around_res(u_pbc_triclinic):
# sanity check for issue 2656, shouldn't segfault (obviously)
ag = u_pbc_triclinic.select_atoms('around 0.0 resid 3')
assert len(ag) == 0
def test_around_overlapping():
# check that around 0.0 catches when atoms *are* superimposed
u = mda.Universe.empty(60, trajectory=True)
xyz = np.zeros((60, 3))
x = np.tile(np.arange(12), (5,))+np.repeat(np.arange(5)*100, 12)
# x is 5 images of 12 atoms
xyz[:, 0] = x # y and z are 0
u.load_new(xyz)
u.dimensions = [100, 100, 100, 60, 60, 60]
# Technically true but not what we're testing:
# dist = mda.lib.distances.distance_array(u.atoms[:12].positions,
# u.atoms[12:].positions,
# box=u.dimensions)
# assert np.count_nonzero(np.any(dist <= 0.0, axis=0)) == 48
assert u.select_atoms('around 0.0 index 0:11').n_atoms == 48
def test_issue_2229_part1():
# reproducing first case in GH issue 2229
u = mda.Universe.empty(2, trajectory=True)
u.dimensions = [57.45585, 50.0000, 50.0000, 90, 90, 90]
u.atoms[0].position = [0, 0, 0]
u.atoms[1].position = [55.00, 0, 0]
g = mda.lib.nsgrid.FastNS(3.0, u.atoms[[0]].positions, box=u.dimensions)
assert len(g.search(u.atoms[[1]].positions).get_pairs()) == 1
g = mda.lib.nsgrid.FastNS(3.0, u.atoms[[1]].positions, box=u.dimensions)
assert len(g.search(u.atoms[[0]].positions).get_pairs()) == 1
def test_issue_2229_part2():
u = mda.Universe.empty(2, trajectory=True)
u.dimensions = [45.0000, 55.0000, 109.8375, 90, 90, 90]
u.atoms[0].position = [0, 0, 29.29]
u.atoms[1].position = [0, 0, 28.23]
g = mda.lib.nsgrid.FastNS(3.0, u.atoms[[0]].positions, box=u.dimensions, pbc=False)
assert len(g.search(u.atoms[[1]].positions).get_pairs()) == 1
g = mda.lib.nsgrid.FastNS(3.0, u.atoms[[1]].positions, box=u.dimensions)
assert len(g.search(u.atoms[[0]].positions).get_pairs()) == 1
def test_issue_2919():
# regression test reported in issue 2919
# other methods will also give 1115 or 2479 results
u = mda.Universe(PDB_xvf)
ag = u.select_atoms('index 0')
u.trajectory.ts = center_in_box(ag)(u.trajectory.ts)
box = u.dimensions
reference = u.select_atoms('protein')
configuration = u.select_atoms('not protein')
for cutoff, expected in [(2.8, 1115), (3.2, 2497)]:
pairs, distances = mda.lib.distances.capped_distance(
reference.positions,
configuration.positions,
max_cutoff=cutoff,
box=box,
method='nsgrid',
return_distances=True,
)
assert len(pairs) == expected
def test_issue_2345():
# another example of NSGrid being wrong
# this is a 111 FCC slab
# coordination numbers for atoms should be either 9 or 12, 50 of each
u = mda.Universe(SURFACE_PDB, SURFACE_TRR)
g = mda.lib.nsgrid.FastNS(2.9, u.atoms.positions, box=u.dimensions)
cn = defaultdict(list)
idx = g.self_search().get_pairs()
# count number of contacts for each atom
for (i, j) in idx:
cn[i].append(j)
cn[j].append(i)
c = Counter(len(v) for v in cn.values())
assert c == {9: 50, 12: 50}
def test_issue_2670():
# Tests that NSGrid no longer crashes when using small box sizes
u = mda.Universe(PDB)
u.dimensions = [1e-3, 1e-3, 1e-3, 90, 90, 90]
# PDB files only have a coordinate precision of 1.0e-3, so we need to scale
# the coordinates for this test to make any sense:
u.atoms.positions = u.atoms.positions * 1.0e-3
ag1 = u.select_atoms('resid 2 3')
# should return nothing as nothing except resid 3 is within 0.0 or resid 3
assert len(ag1.select_atoms('around 0.0 resid 3')) == 0
# force atom 0 |
"""
Creates an MySql in Azure.
"""
import settings
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.rdbms import mysql
from msrestazure.azure_exceptions import CloudError
from common.methods import is_version_newer, set_progress
from common.mixins import get_global_id_chars
from infrastructure.models import CustomField, Environment
cb_version = settings.VERSION_INFO["VERSION"]
CB_VERSION_93_PLUS = is_version_newer(cb_version, "9.2.2")
def _get_client(handler):
"""
Get the client using newer methods from the CloudBolt main repo if this CB is running
a version greater than 9.2.2. These internal methods implicitly take care of much of the other
features in CloudBolt such as proxy and ssl verification.
Otherwise, manually instantiate clients without support for those other CloudBolt settings.
"""
set_progress("Connecting to Azure...")
if CB_VERSION_93_PLUS:
from resourcehandlers.azure_arm.azure_wrapper import configure_arm_client
wrapper = handler.get_api_wrapper()
mysql_client = configure_arm_client(wrapper, mysql.MySQLManagementClient)
else:
# TODO: Remove once versions <= 9.2.2 are no longer supported.
credentials = ServicePrincipalCredentials(
client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id
)
mysql_client = mysql.MySQLManagementClient(credentials, handler.serviceaccount)
set_progress("Connection to Azure established")
return mysql_client
def generate_options_for_env_id(server=None, **kwargs):
envs = Environment.objects.filter(
resource_handler__resource_technology__name="Azure"
)
options = [(env.id, env.name) for env in envs]
return options
def generate_options_for_resource_group(control_value=None, **kwargs):
"""Dynamically generate options for resource group form field based on the user's selection for Environment.
This method requires the user to set the resource_group parameter as dependent on environment.
"""
if control_value is None:
return []
env = Environment.objects.get(id=control_value)
if CB_VERSION_93_PLUS:
# Get the Resource Groups as defined on the Environment. The Resource Group is a
# CustomField that is only updated on the Env when the user syncs this field on the
# Environment specific parameters.
resource_groups = env.custom_field_options.filter(
field__name="resource_group_arm"
)
return [rg.str_value for rg in resource_groups]
else:
rh = env.resource_handler.cast()
groups = rh.armresourcegroup_set.all()
return [g.name for g in groups]
def create_custom_fields_as_needed():
CustomField.objects.get_or_create(
name="azure_rh_id",
type="STR",
defaults={
"label": "Azure RH ID",
"description": "Used by the Azure blueprints",
"show_as_attribute": True,
},
)
CustomField.objects.get_or_create(
name="azure_database_name",
type="STR",
defaults={
"label": "Azure Database Name",
"description": "Used by the Azure blueprints",
"show_as_attribute": True,
},
)
CustomField.objects.get_or_create(
name="azure_server_name",
type="STR",
defaults={
"label": "Azure Server Name",
"description": "Used by the Azure blueprints",
"show_as_attribute": True,
},
| )
CustomField.objects.get_or_create(
name="azure_location",
type="STR",
defaults={
"label": "Azure Location",
"description": "Us | ed by the Azure blueprints",
"show_as_attribute": True,
},
)
CustomField.objects.get_or_create(
name="resource_group_name",
type="STR",
defaults={
"label": "Azure Resource Group",
"description": "Used by the Azure blueprints",
"show_as_attribute": True,
},
)
def run(job, **kwargs):
resource = kwargs.get("resource")
create_custom_fields_as_needed()
env_id = "{{ env_id }}"
env = Environment.objects.get(id=env_id)
rh = env.resource_handler.cast()
location = env.node_location
set_progress("Location: %s" % location)
resource_group = "{{ resource_group }}"
database_name = "{{ database_name }}"
server_name = f"{database_name}-mysql-{get_global_id_chars()}"
server_username = "{{ server_username }}"
server_password = "{{ server_password }}"
resource.name = "Azure MySql - " + database_name
resource.azure_server_name = server_name
resource.azure_database_name = database_name
resource.resource_group_name = resource_group
resource.azure_location = location
resource.azure_rh_id = rh.id
resource.save()
client = _get_client(rh)
set_progress('Checking if server "%s" already exists...' % server_name)
try:
server = client.servers.get(resource_group, server_name)
except CloudError as e:
set_progress("Azure Clouderror: {}".format(e))
else:
# No ResourceNotFound exception; server already exists
return (
"FAILURE",
"Database server already exists",
"DB server instance %s exists already" % server_name,
)
set_progress('Creating server "%s"...' % server_name)
params = {
"location": location,
"version": "12.0",
"administrator_login": server_username,
"administrator_login_password": server_password,
"properties": {
"create_mode": "Default",
"administrator_login": server_username,
"administrator_login_password": server_password,
},
}
async_server_create = client.servers.create(resource_group, server_name, params,)
async_server_create.result()
set_progress(
'Creating database "%s" on server "%s"...' % (database_name, server_name)
)
async_db_create = client.databases.create_or_update(
resource_group, server_name, database_name, {"location": location}
)
database = async_db_create.result() # Wait for completion and return created object
assert database.name == database_name
db = client.databases.get(resource_group, server_name, database_name)
assert db.name == database_name
set_progress('Database "%s" has been created.' % database_name) |
'''Test cases for QImage'''
import unittest
import py3kcompat as py3k
from PySide.QtGui import *
from helper import UsesQApplication, adjust_filename
xpm = [
"27 22 206 2",
" c None",
". c #FEFEFE",
"+ c #FFFFFF",
"@ c #F9F9F9",
"# c #ECECEC",
"$ c #D5D5D5",
"% c #A0A0A0",
"& c #767676",
"* c #525252",
"= c #484848",
"- c #4E4E4E",
"; c #555555",
"> c #545454",
", c #5A5A5A",
"' c #4B4B4B",
") c #4A4A4A",
"! c #4F4F4F",
"~ c #585858",
"{ c #515151",
"] c #4C4C4C",
"^ c #B1B1B1",
"/ c #FCFCFC",
"( c #FDFDFD",
"_ c #C1C1C1",
": c #848484",
"< c #616161",
"[ c #5E5E5E",
"} c #CECECE",
"| c #E2E2E2",
"1 c #E4E4E4",
"2 c #DFDFDF",
"3 c #D2D2D2",
"4 c #D8D8D8",
"5 c #D4D4D4",
"6 c #E6E6E6",
"7 c #F1F1F1",
"8 c #838383",
"9 c #8E8E8E",
"0 c #8F8F8F",
"a c #CBCBCB",
"b c #CCCCCC",
"c c #E9E9E9",
"d c #F2F2F2",
"e c #EDEDED",
"f c #B5B5B5",
"g c #A6A6A6",
"h c #ABABAB",
"i c #BBBBBB",
"j c #B0B0B0",
"k c #EAEAEA",
"l c #6C6C6C",
"m c #BCBCBC",
"n c #F5F5F5",
"o c #FAFAFA",
"p c #B6B6B6",
"q c #F3F3F3",
"r c #CFCFCF",
"s c #FBFBFB",
"t c #CDCDCD",
"u c #DDDDDD",
"v c #999999",
"w c #F0F0F0",
"x c #2B2B2B",
"y c #C3C3C3",
"z c #A4A4A4",
"A c #D7D7D7",
"B c #E7E7E7",
"C c #6E6E6E",
"D c #9D9D9D",
"E c #BABABA",
"F c #AEAEAE",
"G c #898989",
"H c #646464",
"I c #BDBDBD",
"J c #CACACA",
"K c #2A2A2A",
"L c #212121",
"M c #B7B7B7",
"N c #F4F4F4",
"O c #737373",
"P c #828282",
"Q c #4D4D4D",
"R c #000000",
"S c #151515",
"T c #B2B2B2",
"U c #D6D6D6",
"V c #D3D3D3",
"W c #2F2F2F",
"X c #636363",
"Y c #A1A1A1",
"Z c #BFBFBF",
"` c #E0E0E0",
" . c #6A6A6A",
".. c #050505",
"+. c #A3A3A3",
"@. c #202020",
"#. c #5F5F5F",
"$. c #B9B9B9",
"%. c #C7C7C7",
"&. c #D0D0D0",
"*. c #3E3E3E",
"=. c #666666",
"-. c #DBDBDB",
";. c #424242",
">. c #C2C2C2",
",. c #1A1A1A",
"'. c #2C2C2C",
"). c #F6F6F6",
"!. c #AAAAAA",
"~. c #DCDCDC",
"{. c #2D2D2D",
"]. c #2E2E2E",
"^. c #A7A7A7",
"/. c #656565",
"(. c #333333",
"_. c #464646",
":. c #C4C4C4",
"<. c #B8B8B8",
"[. c #292929",
"}. c #979797",
"|. c #EFEFEF",
"1. c #909090",
"2. c #8A8A8A",
"3. c #575757",
"4. c #676767",
"5. c #C5C5C5",
"6. c #7A7A7A",
"7. c #797979",
"8. c #989898",
"9. c #EEEEEE",
"0. c #707070",
"a. c #C8C8C8",
"b. c #111111",
"c. c #AFAFAF",
"d. c #474747",
"e. c #565656",
"f. c #E3E3E3",
"g. c #494949",
"h. c #5B5B5B",
"i. c #222222",
"j. c #353535",
"k. c #D9D9D9",
"l. c #0A0A0A",
"m. c #858585",
"n. c #E5E5E5",
"o. c #0E0E0E",
"p. c #9A9A9A",
"q. c #6F6F6F",
"r. c #868686",
"s. c #060606",
"t. c #1E1E1E",
"u. c #E8E8E8",
"v. c #A5A5A5",
"w. c #0D0D0D",
"x. c #030303",
"y. c #272727",
"z. c #131313",
"A. c #1F1F1F",
"B. c #757575",
"C. c #F7F7F7",
"D. c #414141",
"E. c #080808",
"F. c #6B6B6B",
"G. c #313131",
"H. c #C0C0C0",
"I. c #C9C9C9",
"J. c #0B0B0B",
"K. c #232323",
"L. c #434343",
"M. c #3D3D3D",
"N. c #282828",
"O. c #7C7C7C",
"P. c #252525",
"Q. c #3A3A3A",
"R. c #F8F8F8",
"S. c #1B1B1B",
"T. c #949494",
"U. c #3B3B3B",
"V. c #242424",
"W. c #38383 | 8",
"X. c #6D6D6D",
"Y. c #818181",
"Z. c #939393",
"`. c #9E9E9E",
" + c #929292",
".+ c #7D7D7D",
"++ c #ADADAD",
"@+ c #DADADA",
"#+ c #919191",
"$+ c #E1E1E1",
"%+ c #BEBEBE",
"&+ c #ACACAC" | ,
"*+ c #9C9C9C",
"=+ c #B3B3B3",
"-+ c #808080",
";+ c #A8A8A8",
">+ c #393939",
",+ c #747474",
"'+ c #7F7F7F",
")+ c #D1D1D1",
"!+ c #606060",
"~+ c #5C5C5C",
"{+ c #686868",
"]+ c #7E7E7E",
"^+ c #787878",
"/+ c #595959",
". . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / . . + + ",
". ( + _ : < [ & } | 1 2 $ 3 4 5 3 6 7 + + 8 9 + . + . ",
". + 0 9 a ( 3 a b c d e c f g h i g j $ k + l m + . + ",
"+ 2 8 n o p | ( q r s . # t + + + u ^ v e w + x + + + ",
"+ y z . @ A k B 7 n + ( s | p 8 C D 2 E 4 + + F G + . ",
"# H I $ J G K L - M N . 2 O P Q R R S T U s s V W j + ",
"X Y Z @ o ` _ g ...+.( 4 @.#.m G $.%.7 &.X *.=.-.;.&.",
"Q >.C ,.'.} e + ).!.k + . + + . ~.{.> ].x f 7 ^./.k (.",
"_.:.4 @ <.[.}.|.1.2.+ + + >.} 4 B + ( @ _ 3.4.5.6.r 7.",
"3.8.9.~ 0.+ a.Q b.+ + c.d.#.=.$ |.b #.e.z ^ ; ^. .f.g.",
"-.h.+ i.S M + # p j.% n 9.5.k.H l.m.V ^.n.o.M + M p.q.",
"7 r.N s.1.R t.<.|.| u.v.~ w.x.E + s y.z.A.B.C.+ 5 D.q ",
").p.2 E.0.9 F.%.O {._ @.+ + i { [ i.G.H.P I.+ s q.} + ",
").p.6 J.R b.K.L.M.A.! b.g.K [.R M k + N.I + + >.O.+ . ",
").8.9.N.P...R R R R E.t.W n.+ Q.R.6 @.| + . + S.+ + . ",
"n }.w T.U.B.<.i.@ Y + + U.+ c u V.= B B 7 u.W.c + . + ",
"N T.# + }.X.Y.,.8.F.8 Z.[.`. +.+}.4 ++@+O.< ~.+ ( . + ",
"d #+1 + _ ~.u.$+b $.y @+| $+%+I.&+k.h W +.9.+ ( . + . ",
"w 0 |.*+. >.<.=+++++p a.p -+;+5.k.>+,+@ + . . + . + + ",
"q '+9.R.^ I.t b %.I.)+4 $+n.I.,+ .|.+ . . . + . + + + ",
". p !+( + + + + + + E 0. .-+8.f.+ + . . + + . + + + + ",
". ( A ~+{+]+^+l > /+D f.c q . + . . + + . + + + + + + "
]
class QImageTest(UsesQApplication):
'''Test case for calling setPixel with float as argument'''
def testQImageStringBuffer(self):
'''Test if the QImage signatures receiving string buffers exist.'''
img0 = QImage(adjust_filename('sample.png', __file__))
# btw let's test the bits() method
img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format())
self.assertEqual(img0, img1)
img2 = QImage(img0.bits(), img0.width(), img0.height(), img0.bytesPerLine(), img0.format())
self.assertEqual(img0, img2)
## test scanLine method
data1 = img0.scanLine(0)
data2 = img1.scanLine(0)
self.assertEqual(data1, data2)
# PySide python 3.x does not support slice yet
if not py3k.IS_PY3K:
buff = py3k.buffer(img0.bits()[:img0.bytesPerLine()])
self.assertEqual(data1, buff)
self.assertEqual(data2, buff)
def testEmptyBuffer(self):
img = QImage(py3k.buffer(''), 100, 100, QImage.Format_ARGB32)
def testEmptyStringAsBuffer(self):
img = QImage(py3k.b(''), 100, 100, QImage.Format_ARGB32)
def testXpmConstructor(self):
label = QLabel()
img = QImage(xpm)
self.assertFalse(img.isNull())
self.assertEqual(img.width(), 27)
self.assertEqual(img.height(), 22)
if __name__ == '__main__':
unittest.main()
|
SECRET_KEY = 'not-anymore'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = T | rue
USE_L10N = True
USE_TZ = False
DATABASES = {
'default | ': {
'ENGINE': 'django.db.backends.sqlite3',
}
}
INSTALLED_APPS = [
'reverse_unique',
'reverse_unique_tests',
]
|
# -*- coding: utf-8 -*-
"""
pygments.styles.manni
~~~~~~~~~~~~~~~~~~~~~
A colorful style, inspired by the terminal highlighting style.
This is a port of the style used in the `php port`_ of pygments
by Manni. The style is called 'default' there.
:copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace
class ManniStyle(Style):
"""
A colorful style, inspired by the terminal highlighting style.
"""
background_color = '#f0f3f3'
styles = {
Whitespace: '#bbbbbb',
Comment: 'italic #0099FF',
Comment.Preproc: 'noitalic #009999',
Comment.Special: 'bold',
Keyword: 'bold #006699',
Keyword.Pseudo: 'nobold',
Keyword.Type: '#007788',
Operator: '#555555',
Operator.Word: 'bold #000000',
Name.Builtin: '#336666',
Name.Function: '#CC00FF',
Name.Class: 'bold #00AA88',
| Name.Namespace: 'bold #00CCFF',
Name.Exception: 'bold #CC0000',
Name.Variable: '#003333',
Name.Constant: '#336600',
Name.Label: '#9999FF',
Name.Entity: 'bold #999999',
Name.Attribute: '#330099',
| Name.Tag: 'bold #330099',
Name.Decorator: '#9999FF',
String: '#CC3300',
String.Doc: 'italic',
String.Interpol: '#AA0000',
String.Escape: 'bold #CC3300',
String.Regex: '#33AAAA',
String.Symbol: '#FFCC33',
String.Other: '#CC3300',
Number: '#FF6600',
Generic.Heading: 'bold #003300',
Generic.Subheading: 'bold #003300',
Generic.Deleted: 'border:#CC0000 bg:#FFCCCC',
Generic.Inserted: 'border:#00CC00 bg:#CCFFCC',
Generic.Error: '#FF0000',
Generic.Emph: 'italic',
Generic.Strong: 'bold',
Generic.Prompt: 'bold #000099',
Generic.Output: '#AAAAAA',
Generic.Traceback: '#99CC66',
Error: 'bg:#FFAAAA #AA0000'
}
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.serialization import Model
class ApplicationGatewayWebApplicationFirewallConfiguration(Model):
"""Application gateway web application firewall configuration.
All required parameters must be populated in order to send to Azure.
:param enabled: Required. Whether the web application firewall is enabled
or not.
:type enabled: bool
:param firewall_mode: Required. Web application firewall mode. Possible
values include: 'Detection', 'Prevention'
:type firewall_mode: str or
~azure.mgmt.network.v2017_11_01.models.ApplicationGatewayFirewallMode
:param rule_set_type: Required. The type of the web application firewall
rule set. Possible values are: 'OWASP'.
:type rule_set_type: str
:param rule_set_version: Required. The version of the rule set type.
:type rule_set_version: str
:param disabled_rule_groups: The disabled rule groups.
:type disabled_rule_groups:
list[~azure.mgmt.network.v2017_11_01.models.ApplicationGatewayFirewallDisabledRuleGroup]
"""
_validation = {
'enabled': {'required': True},
'firewall_mode': {'required': True},
'rule_set_type': {'required': True},
'rule_set_version': {'required': True},
}
_attribute_map = {
'enabled': {'key': 'enabled', 'type': 'bool'},
'firewall_mode': {'key': 'firewallMode', 'type': 'str'},
'rule_set_type': {'key': 'ruleSetType', 'type': 'str'},
'rule_set_version': {'key': 'ruleSetVersion', 'type': 'str'},
'disabled_rule_groups': {'key': 'disabledRuleGroups', 'type': '[ApplicationGatewayFirewallDisabledRuleGroup]'},
}
def __init__(self, **kwargs):
super(ApplicationGatewayWebApplicationFirewallConfiguration, self).__init__(**kwargs)
self.enabled = kwargs.get('enabled', None)
self.firewall_mode = kwargs.get('firewall_mode', None)
| self.rule_set_type = kwargs.get('rule_set_type', None)
self.rule_set_version = kwargs.get('rule_set_version', None)
self.dis | abled_rule_groups = kwargs.get('disabled_rule_groups', None)
|
rting_abstract_count+1)
self.assertEqual(new_abstract.title, 'Silly Walks of the Neanderthals')
self.assertEqual(new_abstract.year, 2015)
starting_author_count = Author.objects.count()
new_author = Author.objects.create(abstract=new_abstract, author_rank=1, first_name="Bob",
last_name="Reed", institution="University of Texas at Austin",
department="Anthropology", country="United States of America",
email_address="denne.reed@gmail.com")
self.assertEqual(Author.objects.count(), starting_author_count+1)
self.assertEqual(new_author.last_name, 'Reed')
self.assertEqual(new_author.abstract, new_abstract)
self.assertEqual(new_author.full_name(), "Bob Reed")
self.assertEqual(new_author.author_rank, 1)
author2 = Author.objects.create(abstract=new_abstract, author_rank=2, first_name='Denné',
last_name='Jéhnson', institution="University of Texas at Austin",
department="Anthropology", country="United States of America",
email_address="denne.reed@gmail.com")
self.assertEqual(Author.objects.count(), starting_author_count+2)
self.assertEqual(author2.last_name, 'Jéhnson')
self.assertEqual(author2.abstract, new_abstract)
self.assertEqual(author2.full_name(), 'Denné Jéhnson')
self.assertEqual(author2.author_rank, 2)
class AbstractMethodTests(TestCase):
def setUp(self):
san_francisco = Meeting.objects.create(year=2015, title='San Francisco 2015',
location='San Francisco, CA', associated_with='SAA')
# create an abstract for the meeting
new_abstract = Abstract.objects.create(meeting_id=san_francisco.id, contact_email='denne.reed@gmail.com',
presentation_type='Paper',
title='Silly Walks of the Neanderthals',
abstract_text="""<p>Silly walks in Neanderthals.</p> """,
year=2015)
Author.objects.create(abstract=new_abstract, author_rank=1, first_name="Bob",
last_name="Reed", institution="University of Texas at Austin",
department="Anthropology", country="United States of America",
email_address="denne.reed@gmail.com")
Author.objects.create(abstract=new_abstract, author_rank=2, first_name='Denné',
last_name='Jéhnson', institution="University of Texas at Austin",
department="Anthropology", country="United States of America",
email_address="denne.reed@gmail.com")
abstract2 = Abstract.objects.create(meeting_id=san_francisco.id, contact_email='denne.reed@gmail.com',
presentation_type='Poster',
title='∂13 C isotopic values in zombies indicate a C4 diet',
abstract_text="""<p>Yummy plants, ugggh</p> """,
year=2015)
Author.objects.create(abstract=abstract2, author_rank=1, first_name="Archer",
last_name="Flexnick", institution="University of Transylvania",
department="Anthropology", country="Romania",
email_address="Archer.Flexnick@gmail.com")
Author.objects.create(abstract=abstract2, author_rank=2, first_name="Felix",
last_name="Quustz", institution="University of Transylvania",
department="Anthropology", country="Romania",
email_address="Felix.Q@gmail.com")
Author.objects.create(abstract=abstract2, author_rank=3, first_name="Adam",
last_name="Ackworth", institution="University of Transylvania",
department="Anthropology", country="Romania",
email_address="AdamAck@gmail.com")
def test_lead_author_last_name_method(self):
abstract = Abstract.objects.get(title='Silly Walks of the Neanderthals')
self.assertEqual(abstract.lead_author_last_name(), "Reed") # Last name of lead author should be "Reed"
def test_pretty_title(self):
abstract = Abstract.objects.get(title='Silly Walks of the Neanderthals')
self.assertEqual(abstract.pretty_title(), 'Silly Walks of the Neanderthals')
abstract = Abstract.objects.get(title='∂13 C isotopic values in zombies indicate a C4 diet')
self.assertEqual(abstract.pretty_title(), u'\u220213 C isotopic values in zombies indicate a C4 diet')
class AbstractViewTests(TestCase):
def setUp(self):
# Create basic fiber tree
starting_page_count = Page.objects.count()
mainmenu = Page.objects.create(title='mainmenu')
meetings_page = Page.objects.create(title='meetings', parent=mainmenu, url='meetings', template_name='')
# Create abstract fiber page
abstract_submission_page = Page.objects.create(title='abstract submission',
parent=meetings_page, url='abstract')
Page.objects.create(title='Create Abstract', parent=abstract_submission_page, url='add')
self.assertEqual(Page.objects.count(), starting_page_count+4) # test 4 pages saved
# Create 3 meetings with associated fiber pages
calgary = Meeting.objects.create(year=2014, title='Calgary 2014',
location='Calgary, AB', associated_with='AAPA')
calgary.create_fiber_page()
san_francisco = Meeting.objects.create(year=2015, title='San Francisco 2015',
location='San Francisco, CA', associated_with='SAA')
san_francisco.create_fiber_page()
atlanta = Meeting.objects.create(year=2016, title='Atlanta 2016',
location='Atlanta, GA', associated_with='AAPA')
| atlanta.create_fiber_page()
self.assertEqual(Page.objects.count(), starting_page_count+7) # test 6 pages saved
# Create an abstract with two authors
self.assertEqual(Meeting.objects.count(), 3)
self.assertEqual(Abstract.objects.count(), 0)
san_franc | isco = Meeting.objects.get(year=2015)
self.assertEqual(san_francisco.location, 'San Francisco, CA')
new_abstract = Abstract.objects.create(meeting_id=24, contact_email='denne.reed@gmail.com', presentation_type='Paper',
title='Silly Walks of the Neanderthals',
abstract_text="""<p> Test abstract text about silly walks in Neanderthals.</p> """,
year=2015) # create a new abstract for the san francisco meeting
Author.objects.create(abstract=new_abstract, author_rank=1, first_name="Denne",
last_name="Reed", institution="University of Texas at Austin",
department="Anthropology", country="United States of America",
email_address="denne.reed@gmail.com")
Author.objects.create(abstract=new_abstract, author_rank=2, first_name="Bob",
last_name="Frankle", institution="University of Michigan",
department="Anthropology", country="United States of America",
email_address="bob.frankle@gmail.com")
def test_create_abstract_view_with_get_method(self):
"""A get request should load a blank version of the form"""
response = self.client.get(reverse('meetings:create_abstract'))
self.assertEqual(response.status_code, 200) # Re |
rfile.first_byte_timestamp = 42
r = read_request_head(rfile)
assert r.method == "GET"
assert r.headers["Content-Length"] == "4"
assert r.content is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
assert rfile.read() == b"skip"
def test_read_response():
req = treq()
rfile = BytesIO(b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody")
r = read_response(rfile, req)
assert r.status_code == 418
assert r.content == b"body"
assert r.timestamp_end
def test_read_response_head():
rfile = BytesIO(
b"HTTP/1.1 418 I'm a teapot\r\n"
b"Content-Length: 4\r\n"
b"\r\n"
b"skip"
)
rfile.reset_timestamps = Mock()
rfile.first_byte_timestamp = 42
r = read_response_head(rfile)
assert r.status_code == 418
assert r.headers["Content-Length"] == "4"
assert r.content is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
assert rfile.read() == b"skip"
class TestReadBody(object):
def test_chunked(self):
rfile = BytesIO(b"3\r\nfoo\r\n0\r\n\r\nbar")
body = b"".join(read_body(rfile, None))
assert body == b"foo"
assert rfile.read() == b"bar"
def test_known_size(self):
rfile = BytesIO(b"foobar")
body = b"".join(read_body(rfile, 3))
assert body == b"foo"
assert rfile.read() == b"bar"
def test_known_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
b"".join(read_body(rfile, 3, 2))
def test_known_size_too_short(self):
rfile = BytesIO(b"foo")
with raises(HttpException):
b"".join(read_body(rfile, 6))
def test_unknown_size(self):
rfile = BytesIO(b"foobar")
body = b"".join(read_body(rfile, -1))
assert body == b"foobar"
def test_unknown_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
b"".join(read_body(rfile, -1, 3))
def test_max_chunk_size(self):
rfile = BytesIO(b"123456")
assert list(read_body(rfile, -1, max_chunk_size=None)) == [b"123456"]
rfile = BytesIO(b"123456")
assert list(read_body(rfile, -1, max_chunk_size=1)) == [b"1", b"2", b"3", b"4", b"5", b"6"]
def test_connection_close():
headers = Headers()
assert connection_close(b"HTTP/1.0", headers)
assert not connection_close(b"HTTP/1.1", headers)
headers["connection"] = "keep-alive"
assert not connection_close(b"HTTP/1.1", headers)
headers["connection"] = "close"
assert connection_close(b"HTTP/1.1", headers)
headers["connection"] = "foobar"
assert connection_close(b"HTTP/1.0", headers)
assert not connection_close(b"HTTP/1.1", headers)
def test_expected_http_body_size():
# Expect: 100-continue
assert expected_http_body_size(
treq(headers=Headers(expect="100-continue", content_length="42"))
) == 0
# http://tools.ietf.org/html/rfc7230#section-3.3
assert expected_http_body_size(
treq(method=b"HEAD"),
tresp(headers=Headers(content_length="42"))
) == 0
assert expected_http_body_size(
treq(method=b"CONNECT"),
tresp()
) == 0
for code in (100, 204, 304):
assert expected_http_body_size(
treq(),
tresp(status_code=code)
) == 0
# chunked
assert expected_http_body_size(
treq(headers=Headers(transfer_encoding="chunked")),
) is None
# explicit length
for val in (b"foo", b"-7"):
with raises(HttpSyntaxException):
expected_http_body_size(
treq(headers=Headers(content_length=val))
)
assert expected_http_body_size(
treq(headers=Headers(content_length="42"))
) == 42
# no length
assert expected_http_body_size(
treq(headers=Headers())
) == 0
assert expected_http_body_size(
treq(headers=Headers()), tresp(headers=Headers())
) == -1
def test_get_first_line():
rfile = BytesIO(b"foo\r\nbar")
assert _get_first_line(rfile) == b"foo"
rfile = BytesIO(b"\r\nfoo\r\nbar")
assert _get_first_line(rfile) == b"foo"
with raises(HttpReadDisconnect):
rfile = BytesIO(b"")
_get_first_line(rfile)
with raises(HttpReadDisconnect):
rfile = Mock()
rfile.readline.side_effect = TcpDisconnect
_get_first_line(rfile)
def test_read_request_line():
def t(b):
return _read_request_line(BytesIO(b))
assert (t(b"GET / HTTP/1.1") ==
("relative", b"GET", None, None, None, b"/", b"HTTP/1.1"))
assert (t(b"OPTIONS * HTTP/1.1") ==
("relative", b"OPTIONS", None, None, None, b"*", b"HTTP/1.1"))
assert (t(b"CONNECT foo:42 HTTP/1.1") ==
("authority", b"CONNECT", None, b"foo", 42, None, b"HTTP/1.1"))
assert (t(b"GET http://foo:42/bar HTTP/1.1") ==
("absolute", b"GET", b"http", b"foo", 42, b"/bar", b"HTTP/1.1"))
with raises(HttpSyntaxException):
t(b"GET / WTF/1.1")
with raises(HttpSyntaxException):
t(b"this is not http")
with raises(HttpReadDisconnect):
t(b"")
def test_parse_authority_form():
assert _parse_authority_form(b"foo:42") == (b"foo", 42)
with raises(HttpSyntaxException):
_parse_authority_form(b"foo")
with raises(HttpSyntaxException):
_parse_authority_form(b"foo:bar")
with raises(HttpSyntaxException):
_parse_authority_form(b"foo:99999999")
with raises(HttpSyntaxException):
_parse_authority_form(b"f\x00oo:80")
def test_read_response_line():
def t(b):
return _read_response_line(BytesIO(b))
assert t(b"HTTP/1.1 200 OK") == (b"HTTP/1.1", 200, b"OK")
assert t(b"HTTP/1.1 200") == (b"HTTP/1.1", 200, b"")
# https://github.com/mitmproxy/mitmproxy/issues/784
assert t(b"HTTP/1.1 200 Non-Autoris\xc3\xa9") == (b"HTTP/1.1", 200, b"Non-Autoris\xc3\xa9")
with raises(HttpSyntaxException):
assert t(b"HTTP/1.1")
with raises(HttpSyntaxException):
t(b"HTTP/1.1 OK OK")
with raises(HttpSyntaxException):
t(b"WTF/1.1 200 OK")
with raises(HttpReadDisconnect):
t(b"")
def test_check_http_version():
_check_http_version(b"HTTP/0.9")
_check_http_version(b"HTTP/1.0")
_check_http_version(b"HTTP/1.1")
_check_http_version(b"HTTP/2.0")
with raises(HttpSyntaxException):
_check_http_version(b"WTF/1.0")
with raises(HttpSyntaxException):
_check_http_version(b"HTTP/1.10")
with raises(HttpSyntaxException):
_check_http_version(b"HTTP/1.b")
class TestReadHeaders(object):
@staticmethod
def _read(data):
return _read_headers(BytesIO(data))
def test_read_simple(self):
data = (
b"Header: one\r\n"
b"Header2: two\r\n"
b"\r\n"
)
headers = self._read(data)
assert headers.fields == [[b"Header", b"one"], [b"Header2", b"two"]]
def test_read_multi(self):
data = (
b"Header: one\r\n"
b"Header: two\r\n"
b"\r\n"
)
h | eaders = self._read(data)
assert headers.fields == [[b"Header", b"one"], [b"Header", b"two"]]
def test_read_continued(self):
data = (
b"Header: one\r | \n"
b"\ttwo\r\n"
b"Header2: three\r\n"
b"\r\n"
)
headers = self._read(data)
assert headers.fields == [[b"Header", b"one\r\n two"], [b"Header2", b"three"]]
def test_read_continued_err(self):
data = b"\tfoo: bar\r\n"
with raises(HttpSyntaxException):
self._read(data)
def test_read_err(self):
data = b"foo"
with raises(HttpSyntaxException):
self._read(data)
def test_read_empty_name(self):
data = b":foo"
with raises(HttpSyntaxException):
self._read(data)
def test_read_empty_value(self):
data = b"bar:"
headers = self._read(data)
assert headers.fields == [[b"bar", b""]]
def test_read_chunked():
req = treq(conten |
"""
Set the configuration variables for fabric recipes.
"""
from fabric.api import env
from fabric.colors import yellow
import os
env.warn_only = True
try:
import ConfigParser as cp
except ImportError:
import configpars | er as cp # Python 3.0
config = {}
_config = cp.SafeConfigParser()
if not os.path.isfile("fabric-recipes.conf"):
print yellow("warning: No config file specified")
_config.read("fabric-recipes.conf")
for section in _config.sections():
opt = _config.items(section)
if section == "global":
env.update(opt)
| elif section == "roledefs":
opt = [(k, v.split(",")) for k, v in opt]
env['roledefs'].update(opt)
else:
config[section] = dict(opt) |
f_progress_50p)
snap_ref_progress_99p = snap_ref_progress.copy()
snap_ref_progress_99p['progress'] = '99%'
snap_ref_progress_99p['status'] = 'error'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_99p)
mox.ReplayAll()
self.assertRaisesAndMessageMatches(
exception.GlusterfsException,
'Nova returned "error" status while creating snapshot.',
drv.create_snapshot,
snap_ref)
mox.VerifyAll()
def test_delete_snapshot_online_1(self):
"""Delete the newest snapshot, with only one snap present."""
(mox, drv) = self._mox, self._driver
volume = self._simple_volume()
volume['status'] = 'in-use'
ctxt = context.RequestContext('fake_user', 'fake_project')
snap_ref = {'name': 'test snap to delete (online)',
'volume_id': self.VOLUME_UUID,
'volume': volume,
'id': self.SNAP_UUID,
'context': ctxt}
hashed = drv._get_hash_str(self.TEST_EXPORT1)
volume_file = 'volume-%s' % self.VOLUME_UUID
volume_dir = os.path.join(self.TEST_MNT_POINT_BASE, hashed)
volume_path = '%s/%s/%s' % (self.TEST_MNT_POINT_BASE,
hashed,
volume_file)
info_path = '%s.info' % volume_path
snap_path = '%s.%s' % (volume_path, self.SNAP_UUID)
snap_file = '%s.%s' % (volume_file, self.SNAP_UUID)
mox.StubOutWithMock(drv, '_execute')
mox.StubOutWithMock(drv, '_nova')
# Stub out the busy wait.
self.stub_out_not_replaying(time, 'sleep')
mox.StubOutWithMock(drv, '_read_info_file')
mox.StubOutWithMock(drv, '_write_info_file')
mox.StubOutWithMock(db, 'snapshot_get')
mox.StubOutWithMock(image_utils, 'qemu_img_info')
mox.StubOutWithMock(drv, '_ensure_share_writable')
snap_info = {'active': snap_file,
self.SNAP_UUID: snap_file}
drv._ensure_share_writable(volume_dir)
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
qemu_img_info_output = """image: %s
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 173K
backing file: %s
""" % (snap_file, volume_file)
img_info = imageutils.QemuImgInfo(qemu_img_info_output)
vol_qemu_img_info_output = """image: %s
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 173K
""" % volume_file
volume_img_info = imageutils.QemuImgInfo(vol_qemu_img_info_output)
image_utils.qemu_img_info(snap_path).AndReturn(img_info)
image_utils.qemu_img_info(volume_path).AndReturn(volume_img_info)
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
delete_info = {
'type': 'qcow2',
'merge_target_file': None,
'file_to_merge': None,
'volume_id': self.VOLUME_UUID
}
drv._nova.delete_volume_snapshot(ctxt, self.SNAP_UUID, delete_info)
drv._read_info_file(info_path).AndReturn(snap_info)
drv._read_info_file(info_path).AndReturn(snap_info)
snap_ref_progress = snap_ref.copy()
snap_ref_progress['status'] = 'deleting'
snap_ref_progress_0p = snap_ref_progress.copy()
snap_ref_progress_0p['progress'] = '0%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_0p)
snap_ref_progress_50p = snap_ref_progress.copy()
snap_ref_progress_50p['progress'] = '50%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_50p)
snap_ref_progress_90p = snap_ref_progress.copy()
snap_ref_progress_90p['progress'] = '90%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_90p)
drv._write_info_file(info_path, snap_info)
drv._execute('rm', '-f', volume_path, run_as_root=True)
mox.ReplayAll()
drv.delete_snapshot(snap_ref)
mox.VerifyAll()
def test_delete_snapshot_online_2(self):
"""Delete the middle of 3 snapshots."""
(mox, drv) = self._mox, self._driver
volume = self._simple_volume()
volume['status'] = 'in-use'
ctxt = context.RequestContext('fake_user', 'fake_project')
snap_ref = {'name': 'test snap to delete (online)',
'volume_id': self.VOLUME_UUID,
'volume': volume,
'id': self.SNAP_UUID,
'context': ctxt}
hashed = drv._get_hash_str(self.TEST_EXPORT1)
volume_file = 'volume-%s' % self.VOLUME_UUID
volume_dir = os.path.join(self.TEST_MNT_POINT_BASE, hashed)
volume_path = '%s/%s/%s' % (self.TEST_MNT_POINT_BASE,
hashed,
volume_file)
info_path = '%s.info' % volume_path
snap_path = '%s.%s' % (volume_path, self.SNAP_UUID)
snap_file = '%s.%s' % (volume_file, self.SNAP_UUID)
snap_file_2 = '%s.%s' % (volume_file, self.SNAP_UUID_2)
mox.StubOutWithMock(drv, '_execute')
mox.StubOutWithMock(drv, | '_nova')
# Stub out the busy wait.
self.stub_out_not_replaying(time, 'sleep')
mox.StubOutWithMock(drv, '_read_info_file')
mox.StubOutWithMock(drv, '_write_info_file')
mox.StubOutWithMock(db, 'snapshot_get')
mox.StubOutWithMock(image_utils, 'qemu_img_info')
mox.StubOutWithMoc | k(drv, '_ensure_share_writable')
snap_info = {'active': snap_file_2,
self.SNAP_UUID: snap_file,
self.SNAP_UUID_2: snap_file_2}
drv._ensure_share_writable(volume_dir)
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
qemu_img_info_output = """image: %s
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 173K
backing file: %s
""" % (snap_file, volume_file)
img_info = imageutils.QemuImgInfo(qemu_img_info_output)
vol_qemu_img_info_output = """image: %s
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 173K
""" % volume_file
volume_img_info = imageutils.QemuImgInfo(vol_qemu_img_info_output)
image_utils.qemu_img_info(snap_path).AndReturn(img_info)
image_utils.qemu_img_info(volume_path).AndReturn(volume_img_info)
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
delete_info = {'type': 'qcow2',
'merge_target_file': volume_file,
'file_to_merge': snap_file,
'volume_id': self.VOLUME_UUID}
drv._nova.delete_volume_snapshot(ctxt, self.SNAP_UUID, delete_info)
drv._read_info_file(info_path).AndReturn(snap_info)
drv._read_info_file(info_path).AndReturn(snap_info)
snap_ref_progress = snap_ref.copy()
snap_ref_progress['status'] = 'deleting'
snap_ref_progress_0p = snap_ref_progress.copy()
snap_ref_progress_0p['progress'] = '0%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_0p)
snap_ref_progress_50p = snap_ref_progress.copy()
snap_ref_progress_50p['progress'] = '50%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_50p)
snap_ref_progress_90p = snap_ref_progress.copy()
snap_ref_progress_90p['progress'] = '90%'
db.snapshot_get(ctxt, self.SNAP_UUID).AndReturn(snap_ref_progress_90p)
drv._write_info_file(info_path, snap_info)
drv._execute('rm', '-f', snap_path, run_as_root=True)
mox.ReplayAll()
drv.delete_snapshot(snap_ref)
mox.VerifyAll()
def test_delete_snapshot_online_novafailure(self):
"""Delete the newest snapshot."""
(mox, drv) = self._mox, self._driver
|
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-09 02:15
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_task_inbox'),
]
operations = [
migrations.AddField(
model_name='task',
nam | e='due_date',
| field=models.DateField(null=True),
),
]
|
#!/usr/bin/env python
"""
N x N x N Rubik's Cube
"""
| __author__ = "Edwin J. Son <edwin.son@ligo.org>"
__version__ = "0.0.1a"
__date__ = "May 27 2017"
from cub | e import cube
|
k=mask_inv)
output_imgs["pseudo_on_white"]["img"] = cv2.add(cplant1, img_back3)
if filename:
for key in output_imgs:
if output_imgs[key]["img"] is not None:
fig_name_pseudo = str(filename[0:-4]) + '_' + str(channel) + '_pseudo_on_' + \
output_imgs[key]["background"] + '.jpg'
path = os.path.dirname(filename)
print_image(output_imgs[key]["img"], fig_name_pseudo)
analysis_images.append(['IMAGE', 'pseudo', fig_name_pseudo])
else:
path = "."
if debug is not None:
if debug == 'print':
for key in output_imgs:
if output_imgs[key]["img"] is not None:
print_image(output_imgs[key]["img"], (str(device) + "_" + output_imgs[key]["background"] +
'_pseudocolor.jpg'))
fig_name = 'VIS_pseudocolor_colorbar_' + str(channel) + '_channel.svg'
if not os.path.isfile(os.path.join(path, fig_name)):
plot_colorbar(path, fig_name, bins)
elif debug == 'plot':
for key in output_imgs:
if output_imgs[key]["img"] is not None:
plot_image(output_imgs[key]["img"])
return analysis_images
def analyze_color(img, imgname, mask, bins, device, debug=None, hist_plot_type=None, pseudo_channel='v',
pseudo_bkg='img', resolution=300, filename=False):
"""Analyze the color properties of an image object
Inputs:
img = image
imgname = name of input image
mask = mask made from selected contours
device = device number. Used to count steps in the pipeline
debug = None, print, or plot. Print = save to file, Plot = print to screen.
hist_plot_type = 'None', 'all', 'rgb','lab' or 'hsv'
color_slice_type = 'None', 'rgb', 'hsv' or 'lab'
pseudo_channel = 'None', 'l', 'm' (green-magenta), 'y' (blue-yellow), h','s', or 'v', creates pseduocolored image
based on the specified channel
pseudo_bkg = 'img' => channel image, 'white' => white background image, 'both' => both img and white options
filename = False or image name. If defined print image
Returns:
device = device number
hist_header = color histogram data table headers
hist_data = color histogram data table values
analysis_images = list of output images
:param img: numpy array
:param imgname: str
:param mask: numpy array
:param bins: int
:param device: int
:param debug: str
:param hist_plot_type: str
:param pseudo_channel: str
:param pseudo_bkg: str
:param resolution: int
:param filename: str
:return device: int
:return hist_header: list
:return hist_data: list
:return analysis_images: list
"""
device += 1
masked = cv2.bitwise_and(img, img, mask=mask)
b, g, r = cv2.split(masked)
lab = cv2.cvtColor(masked, cv2.COLOR_BGR2LAB)
l, m, y = cv2.split(lab)
hsv = cv2.cvtColor(masked, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
# Color channel dictionary
norm_channels = {"b": b / (256 / bins),
"g": g / (256 / bins),
"r": r / (256 / bins),
"l": l / (256 / bins),
"m": m / (256 / bins),
"y": y / (256 / bins),
"h": h / (256 / bins),
"s": s / (256 / bins),
"v": v / (256 / bins)
}
# Histogram plot types
hist_types = {"all": ("b", "g", "r", "l", "m", "y", "h", "s", "v"),
"rgb": ("b", "g", "r"),
"lab": ("l", "m", "y"),
"hsv": ("h", "s", "v")}
# If the user-input pseudo_channel is not None and is not found in the list of accepted channels, exit
if pseudo_channel is not None and pseudo_channel not in norm_channels:
fatal_error("Pseudocolor channel was " + str(pseudo_channel) +
', but can only be one of the following: None, "l", "m", "y", "h", "s" or "v"!')
# If the user-input pseudocolored image background is not in the accepted input list, exit
if pseudo_bkg not in ["white", "img", "both"]:
fatal_error("The pseudocolored image background was " + str(pseudo_bkg) +
', but can only be one of the following: "white", "img", or "both"!')
# If the user-input histogram color-channel plot type is not in the list of accepted channels, exit
if hist_plot_type is not None and hist_plot_type not in hist_types:
fatal_error("The histogram plot type was " + str(hist_plot_type) +
', but can only be one of the following: None, "all", "rgb", "lab", or "hsv"!')
histograms = {
"b": {"label": "blue", "graph_color": "blue",
"hist": cv2.calcHist([norm_channels["b"]], [0], mask, [bins], [0, (bins - 1)])},
"g": {"label": "green", "graph_color": "forestgreen",
| "hist": cv2.calcHist([norm_channels["g"]], [0], mask, [bins], [0, (bins - 1)])},
"r": {"label": "red", "graph_color": "red",
"hist": cv2.calcHist([norm_channels["r"]], [0], mask, [bins], [0, (bins - 1)])},
"l": {"label": "lightness", "graph_color": "dimgray",
"hist": cv2.calcHist([norm_channels["l"]], [0], mask | , [bins], [0, (bins - 1)])},
"m": {"label": "green-magenta", "graph_color": "magenta",
"hist": cv2.calcHist([norm_channels["m"]], [0], mask, [bins], [0, (bins - 1)])},
"y": {"label": "blue-yellow", "graph_color": "yellow",
"hist": cv2.calcHist([norm_channels["y"]], [0], mask, [bins], [0, (bins - 1)])},
"h": {"label": "hue", "graph_color": "blueviolet",
"hist": cv2.calcHist([norm_channels["h"]], [0], mask, [bins], [0, (bins - 1)])},
"s": {"label": "saturation", "graph_color": "cyan",
"hist": cv2.calcHist([norm_channels["s"]], [0], mask, [bins], [0, (bins - 1)])},
"v": {"label": "value", "graph_color": "orange",
"hist": cv2.calcHist([norm_channels["v"]], [0], mask, [bins], [0, (bins - 1)])}
}
hist_data_b = [l[0] for l in histograms["b"]["hist"]]
hist_data_g = [l[0] for l in histograms["g"]["hist"]]
hist_data_r = [l[0] for l in histograms["r"]["hist"]]
hist_data_l = [l[0] for l in histograms["l"]["hist"]]
hist_data_m = [l[0] for l in histograms["m"]["hist"]]
hist_data_y = [l[0] for l in histograms["y"]["hist"]]
hist_data_h = [l[0] for l in histograms["h"]["hist"]]
hist_data_s = [l[0] for l in histograms["s"]["hist"]]
hist_data_v = [l[0] for l in histograms["v"]["hist"]]
binval = np.arange(0, bins)
bin_values = [l for l in binval]
# Store Color Histogram Data
hist_header = [
'HEADER_HISTOGRAM',
'bin-number',
'bin-values',
'blue',
'green',
'red',
'lightness',
'green-magenta',
'blue-yellow',
'hue',
'saturation',
'value'
]
hist_data = [
'HISTOGRAM_DATA',
bins,
bin_values,
hist_data_b,
hist_data_g,
hist_data_r,
hist_data_l,
hist_data_m,
hist_data_y,
hist_data_h,
hist_data_s,
hist_data_v
]
analysis_images = []
if pseudo_channel is not None:
analysis_images = _pseudocolored_image(device, norm_channels[pseudo_channel], bins, img, mask, pseudo_bkg,
pseudo_channel, filename, resolution, analysis_images, debug)
if hist_plot_type is not None and filename:
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
# Create Histogram Plot
for channel in hist_types[hist_plot_type]:
plt.plot(histograms[channel]["hist"], color=histograms[channel]["graph_color"],
label=histograms[channel]["label"])
|
from flask import render_template, flash, request, redirect, url_for
from flask_login import login_required
from kernel import agileCalendar
from kernel.DataBoard import Data
from kernel.NM_Aggregates import WorkBacklog, DevBacklog, RiskBacklog
from kconfig import coordinationBookByName
from . import coordination
__author__ = 'Manuel Escriche'
@coordination.route("/")
@coordination.route("/overview")
@login_required
def overview():
return redirect(url_for('coordination.delivery'))
@coordination.route("/success-stories")
@login_required
def success_stories():
cmp = coordinationBookByName['SuccessStories']
backlog = RiskBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/success_stories.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@ | coordination.route("/friendliness")
@login_required
def friendliness():
cmp = coordinationBookByName['Friendliness']
backlog = RiskBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordinatio | n/friendliness.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/qualityassurance")
@login_required
def qualityassurance():
cmp = coordinationBookByName['QualityAssurance']
backlog = RiskBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/quality_assurance.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/issues")
@login_required
def issues():
cmp = coordinationBookByName['Issues']
backlog = RiskBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/issues.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/risks")
@login_required
def risks():
cmp = coordinationBookByName['Risks']
backlog = RiskBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/risks.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/delivery")
@login_required
def delivery():
cmp = coordinationBookByName['Deliverables']
backlog = WorkBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/delivery.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/docs")
@login_required
def docs():
cmp = coordinationBookByName['Documentation']
backlog = WorkBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/docs.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/agile")
@login_required
def agile():
cmp = coordinationBookByName['Agile']
backlog = WorkBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/agile.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
@coordination.route("/scrum-master")
@login_required
def scrumtools():
cmp = coordinationBookByName['SMTools']
backlog = DevBacklog(*Data.getGlobalComponent(cmp.key))
if backlog.source == 'store':
flash('Data from local storage obtained at {}'.format(backlog.timestamp))
sortedby = request.args.get('sortedby') if request.args.get('sortedby') else 'timeSlot'
return render_template('coordination/scrum_tools.html',
comp=cmp,
reporter=backlog,
sortedby=sortedby,
calendar=agileCalendar)
|
from pandac.PandaModules import *
from direct.showbase.PythonUtil import reduceAngle
from otp.movement import Impulse
import math
class PetChase(Impulse.Impulse):
def __init__(self, target = None, minDist = None, moveAngle = None):
Impulse.Impulse.__init__(self)
self.target = target
if minDist is None:
minDist = 5.0
self.minDist = minDist
if moveAngle is None:
moveAngle = 20.0
self.moveAngle = moveAngle
self.lookAtNode = NodePath('lookatNode')
self.lookAtNode.hide()
self.vel = None
self.rotVel = None
return
def setTarget(self, target):
self.target = target
def destroy(self):
self.lookAtNode.removeNode()
del self.lookAtNode
del self.target
del self.vel
del self.rotVel
def _setMover(self, mover):
Impulse.Impulse._setMover(self, mover)
self.lookAtNode.reparentTo(self.nodePath)
self.vel = self.VecType(0)
self.rotVel = self.VecType(0)
def _process(self, dt):
Impulse.Impulse._process(self, dt)
me = self.nodePath
target = self.target
targetPos = target.getPos(me)
x = targetPos[0]
y = targetPos[1]
distance = math.sqrt(x * x + y * y)
self.lookAtNode.lookAt(target)
relH = reduceAngle(self.lookAtNode.getH(me))
epsilon = 0.005
rotSpeed = self.mover.getRotSpeed()
if relH < -epsilon:
vH = -rotSpeed
| elif relH > epsilon:
vH = rotSpeed
else:
vH = 0
if abs(vH * dt) > abs(relH):
vH = relH / dt
if distance > self.minDist and abs(relH) < self.moveAngle:
vForward = self.mover.getFwdSpeed()
else:
vForward = 0
distanceLeft = distance - self.minDist
if distance > self.minDist and vForward * dt > distanceLeft:
| vForward = distanceLeft / dt
if vForward:
self.vel.setY(vForward)
self.mover.addShove(self.vel)
if vH:
self.rotVel.setX(vH)
self.mover.addRotShove(self.rotVel)
def setMinDist(self, minDist):
self.minDist = minDist
|
#!/usr/bin/env python
# coding: utf-8
# Copyright 2013 The Font Bakery Authors. 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.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License
import argparse
import os
import os.path
from bakery_cli.fixers import FamilyAndStyleNameFixer
description = 'Fixes TTF NAME table naming values to work with Windows GDI'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('ttf_font', nargs='+',
help='Font in OpenType (TTF/OTF) | format')
parser.add_argument('--autofix', action='store_true', help='Apply autofix')
args = parser.parse_args()
for path in args.ttf_font:
if not os.path.exists(path):
continue
FamilyAndStyleNameFixer(None, | path).apply()
|
"""event_enroll
Revision ID: 425be68ff414
Revises: 3be6a175f769
Create Date: 2013-10-28 11:22:00.036581
"""
#
# # SAUCE - System for AUtomated Code Evaluation
# # Copyright (C) 2013 Moritz Schlarb
# #
# # This program is free software: you can redistribute it and/or modify
# # it under the terms of the GNU Affero Gene | ral Public License as published by
# # the Free Software Foundation, either version 3 of the License, or
# # any later version.
# #
# # This program is distributed in the hope that it will be useful,
# # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# # GNU Affero General Public License for more details.
# #
# # You should have received a copy of the GNU Affero General Public License
# # along with this progra | m. If not, see <http://www.gnu.org/licenses/>.
#
# revision identifiers, used by Alembic.
revision = '425be68ff414'
down_revision = '3be6a175f769'
from alembic import op
#from alembic.operations import Operations as op
import sqlalchemy as sa
event_enroll = sa.Enum('event', 'lesson', 'lesson_team', 'team', 'team_new', name='event_enroll')
def upgrade():
event_enroll.create(op.get_bind(), checkfirst=False)
op.add_column('events', sa.Column('enroll', event_enroll, nullable=True))
def downgrade():
event_enroll.drop(op.get_bind(), checkfirst=False)
op.drop_column('events', 'enroll')
|
il[i].ComputeScale()
self.detail[i].CreateHistogram()
def InitializeHistoFrequency(self,ihisto):
import numpy
# New collection of labels
newlabels=[]
# Loop over datasets
for histo in self.detail:
# Loop over the label
for label in histo[ihisto].labels:
# Add in the collection
if label not in newlabels:
newlabels.append(label)
# Sorting labels (alphabetical order)
newlabels = sorted(newlabels)
# Loop over datasets
for histo in self.detail:
# New array for data
array_positive=[]
array_negative=[]
# Loop over the new labels
for newlabel in newlabels:
# Loop over the old labels
found = False
value_positive = 0
value_negative = 0
for i in range(len(histo[ihisto].labels)):
if newlabel==histo[ihisto].labels[i]:
value_positive = histo[ihisto].positive.array[i]
value_negative = histo[ihisto].negative.array[i]
found = True
break
# Fill
if found:
array_positive.append(value_positive)
array_negative.append(value_negative)
else:
array_positive.append(0.)
array_negative.append(0.)
# save result
histo[ihisto].positive.array = numpy.array(array_positive)
histo[ihisto].negative.array = numpy.array(array_negative)
histo[ihisto].labels = numpy.array(newlabels)
@staticmethod
def NiceTitle(text):
newtext=text
for i,j in PlotFlow.diconicetitle.iteritems():
newtext = newtext.replace(i,j)
return newtext
def DrawAll(self,mode,output_path):
# Reset Configuration
RootConfig.Init()
# Loop on each histo type
irelhisto=0
for iabshisto in range(0,len(self.main.selection)):
if self.main.selection[iabshisto].__class__.__name__!="Histogram":
continue
self.color=1
histos=[]
scales=[]
for iset in range(0,len(self.detail)):
# Appending histo
histos.append(self.detail[iset][irelhisto].myhisto)
if mode==2:
scales.append(self.detail[iset][irelhisto].scale)
else:
scales.append(1)
# Draw
self.Draw(histos,scales,self.main.selection[iabshisto],irelhisto,mode,output_path,preview=False)
irelhisto+=1
def Draw(self,histos,scales,ref,irelhisto,mode,output_path,preview=False):
from ROOT import TH1
from ROOT import TH1F
from ROOT import THStack
from ROOT import TLegend
from ROOT import TCanvas
from ROOT import TASImage
from ROOT import TAttImage
from ROOT import TPad
# Creating a canvas
PlotFlow.counter=PlotFlow.counter+1
canvas = TCanvas("tempo"+str(PlotFlow.counter),"")
# Loop over datasets and histos
for ind in range(0,len(histos)):
# Scaling
histos[ind].Scale(scales[ind])
# Stacking or superimposing histos ?
stackmode = False
if ref.stack==StackingMethodType.STACK or \
( ref.stack==StackingMethodType.AUTO and \
self.main.stack==StackingMethodType.STACK ):
stackmode=True
# Setting AUTO settings
if len(histos)==1:
histos[0].SetLineColor(9)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
elif len(histos)==2:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
elif len(histos)==3:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
histos[2].SetFillColor(8)
histos[2].SetFillStyle(3006)
elif len(histos)==4:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
histos[3].SetLineColor(4)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
histos[2].SetFillColor(8)
histos[2].SetFillStyle(3006)
histos[3].SetFillColor(4)
histos[3].SetFillStyle(3007)
elif len(histos)==5:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
histos[3].SetLineColor(4)
histos[4].SetLineColor(6)
if stackmode:
histos[0].SetFillColor(9)
| histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
histos[2].SetFillColor(8)
histos[2].SetFillStyle(3006)
histos[3].SetFillColor | (4)
histos[3].SetFillStyle(3007)
histos[4].SetFillColor(6)
histos[4].SetFillStyle(3013)
elif len(histos)==6:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
histos[3].SetLineColor(4)
histos[4].SetLineColor(6)
histos[5].SetLineColor(2)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
histos[2].SetFillColor(8)
histos[2].SetFillStyle(3006)
histos[3].SetFillColor(4)
histos[3].SetFillStyle(3007)
histos[4].SetFillColor(6)
histos[4].SetFillStyle(3013)
histos[5].SetFillColor(2)
histos[5].SetFillStyle(3017)
elif len(histos)==7:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
histos[3].SetLineColor(4)
histos[4].SetLineColor(6)
histos[5].SetLineColor(2)
histos[6].SetLineColor(7)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[1].SetFillStyle(3005)
histos[2].SetFillColor(8)
histos[2].SetFillStyle(3006)
histos[3].SetFillColor(4)
histos[3].SetFillStyle(3007)
histos[4].SetFillColor(6)
histos[4].SetFillStyle(3013)
histos[5].SetFillColor(2)
histos[5].SetFillStyle(3017)
histos[6].SetFillColor(7)
histos[6].SetFillStyle(3022)
elif len(histos)==8:
histos[0].SetLineColor(9)
histos[1].SetLineColor(46)
histos[2].SetLineColor(8)
histos[3].SetLineColor(4)
histos[4].SetLineColor(6)
histos[5].SetLineColor(2)
histos[6].SetLineColor(7)
histos[7].SetLineColor(3)
if stackmode:
histos[0].SetFillColor(9)
histos[0].SetFillStyle(3004)
histos[1].SetFillColor(46)
histos[ |
#
# Virtuozzo containers hauler module
#
import os
import shlex
import p_haul_cgroup
import util
import fs_haul_shared
import fs_haul_subtree
name = "vz"
vz_dir = "/vz"
vzpriv_dir = "%s/private" % vz_dir
vzroot_dir = "%s/root" % vz_dir
vz_conf_dir = "/etc/vz/conf/"
vz_pidfiles = "/var/lib/vzctl/vepid/"
cg_image_name = "ovzcg.img"
class p_haul_type:
def __init__(self, ctid):
self._ctid = ctid
#
# This list would contain (v_in, v_out, v_br) tuples where
# v_in is the name of veth device in CT
# v_out is its peer on the host
# v_bridge is the bridge to which thie veth is attached
#
self._veths = []
self._cfg = ""
def __load_ct_config(self, path):
print "Loading config file from %s" % path
with open(os.path.join(path, self.__ct_config())) as ifd:
self._cfg = ifd.read()
#
# Parse and keep veth pairs, later we will
# equip restore request with this data and
# will use it while (un)locking the network
#
config = parse_vz_config(self._cfg)
if "NETIF" in config:
v_in, v_out, v_bridge = None, None, None
for parm in config["NETIF"].split(","):
pa = parm.split("=")
if pa[0] == "ifname":
v_in = pa[1]
elif pa[0] == "host_ifname":
v_out = pa[1]
elif pa[0] == "bridge":
v_bridge = pa[1]
if v_in and v_out:
print "\tCollect %s -> %s (%s) veth" % (v_in, v_out, v_bridge)
self._veths.append(util.net_dev(v_in, v_out, v_bridge))
def __apply_cg_config(self):
print "Applying CT configs"
# FIXME -- implement
pass
def init_src(self):
self._fs_mounted = True
self._bridged = True
self.__load_ct_config(vz_conf_dir)
def init_dst(self):
self._fs_mounted = False
self._bridged = False
def set_options(self, opts):
pass
def root_task_pid(self):
# Expect first line of tasks file contain root pid of CT
path = "/sys/fs/cgroup/memory/{0}/tasks".format(self._ctid)
with open(path) as tasks:
pid = tasks.readline()
return int(pid)
def __ct_priv(self):
return "%s/%s" % (vzpriv_dir, self._ctid)
def __ct_root(self):
return "%s/%s" % (vzroot_dir, self._ctid)
def __ct_config(self):
return "%s.conf" % self._ctid
#
# Meta-images for OVZ -- container config and info about CGroups
#
def get_meta_images(self, path):
cg_img = os.path.join(path, cg_image_name)
p_haul_cgroup.dump_hier(self.root_task_pid(), cg_img)
cfg_name = self.__ct_config()
return [ (os.path.join(vz_conf_dir, cfg_name), cfg_name), \
(cg_img, cg_image_name) ]
def put_meta_images(self, path):
print "Putting config file into %s" % vz_conf_dir
self.__load_ct_config(path)
with open(os.path.join(vz_conf_dir, self.__ct_config()), "w") as ofd:
ofd.write(self._cfg)
# Keep this name, we'll need one in prepare_ct()
self.cg_img = os.path.join(path, cg_image_name)
#
# Create cgroup hierarchy and put root task into it
# Hierarchy is unlimited, we will apply config limitations
# in ->restored->__apply_cg_config later
#
def prepare_ct(self, pid):
p_haul_cgroup.restore_hier(pid, self.cg_img)
def __umount_root(self):
print "Umounting CT root"
os.system("umount %s" % self.__ct_root())
self._fs_mounted = False
def mount(self):
nroot = self.__ct_root()
print "Mounting CT root to %s" % nroot
if not os.access(nroot, os.F_OK):
os.makedirs(nroot)
os.system("mount --bind %s %s" % (self.__ct_priv(), nroot))
self._fs_mounted = True
return nroot
def umount(self):
if self._fs_mounted:
self.__umount_root()
def get_fs(self):
rootfs = util.path_to_fs(self.__ct_priv())
if not rootfs:
print "CT is on unknown FS"
return None
print "CT is on %s" % rootfs
if rootfs == "nfs":
return fs_haul_shared.p_haul_fs()
if rootfs == "ext3" or rootfs == "ext4":
return fs_haul_subtree.p_haul_fs(self.__ct_priv())
print "Unknown CT FS"
return None
def restored(self, pid):
print "Writing pidfile"
pidfile = open(os.path.join(vz_pidfiles, self._ctid), 'w')
pidfile.write("%d" % pid)
pidfile.close()
self.__apply_cg_config()
def net_lock(self):
for veth in self._veths:
util.ifdown(veth.pair)
def net_unlock(self):
for veth in self._veths:
util.ifup(veth.pair)
if veth.link and not self._bridged:
util.bridge_add(veth.pair, veth.link)
def can_migrate_tcp(self):
return True
def veths(self):
#
# Caller wants to see list of tuples with [0] being name
# in CT and [1] being name on host. Just return existing
# tuples, the [2] with bridge name wouldn't hurt
#
return self._ve | ths
def parse_vz_config(body) | :
""" Parse shell-like virtuozzo config file"""
config_values = dict()
for token in shlex.split(body, comments=True):
name, sep, value = token.partition("=")
config_values[name] = value
return config_values
|
import nose
def test_nose_working():
| """
Test that the nose runner is working.
"""
a | ssert True
|
import pytest
from mockito import mock
from app.hook_details.hook_details import HookDetails
pytestmark = pytest.mark.asyncio
@pytest.mark.usefixtures('unstub')
class TestHookDetails:
async def test__hook_details__is_pure_interface(self):
with pytest.raises(NotImplementedError):
f"{HookDetails()}"
with pytest.raises(NotImplementedError):
HookDetails().get_allowed_parameters()
with pytest.raises(NotImplementedError):
HookDetails().get_query()
with pytest.raises(NotImplementedError):
HookDetails().get_ref()
with pytest.raises(NotImplementedError):
HookDetails().setup_final_para | m_values(mock())
with pytest.raises(NotImplementedError):
await HookDetails().should_trigger(mock(), mock())
with pytest.raises(NotImplement | edError):
HookDetails().get_event_type()
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import json
import xml.etree.ElementTree as ET
import urllib2
import werkzeug.utils
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.controllers.main import Website
class Website(Website):
@http.route(['/<path:seo_url>'], type='http', auth="public", website=True)
def path_page(self, seo_url, **kwargs):
"""Handle SEO urls for ir.ui.views.
ToDo: Add additional check for field seo_url_parent. Otherwise it is
possible to use invalid url structures. For example: if you have two
pages 'study-1' and 'study-2' with the same seo_url_level and different
seo_url_parent you can use '/ecommerce/study-1/how-to-do-it-right' and
'/ecommerce/study-2/how-to-do-it-right' to call the page
'how-to-do-it-right'.
"""
env = request.env(context=request.context)
seo_url_parts = [s.encode('utf8') for s in seo_url.split('/')
if s != '']
views = env['ir.ui.view'].search([('seo_url', 'in', seo_url_parts)],
order='seo_url_level ASC')
page = 'website.404'
if len(seo_url_parts) == len(views):
seo_url_check = [v.seo_url.encode('utf8') for v in views]
current_view = views[-1]
if (seo_url_parts == seo_url_check
and (current_view.seo_url_level + 1) == len(views)):
page = current_view.xml_id
if page == 'website.404':
try:
url = self.look_for_redirect_url(seo_url, **kwargs)
if url:
return request.redirect(url, code=301)
assert url is not None
except Exception, e:
return request.registry['ir.http']._handle_exception(e, 404)
if page == 'website.404' and request.website.is_publisher():
page = 'website.page_404'
return request.render(page, {})
def look_for_redirect_url(self, seo_url, **kwargs):
env = request.env(context=request.context)
if not seo_url.startswith('/'):
seo_url = '/' + seo_url
lang = env.context.get('lang', False)
if not lang:
lang = request.website.default_lang_code
lang = env['res.lang'].get_code_from_alias(lang)
domain = [('url', '=', seo_url), ('lang', '=', lang)]
data = env['website.seo.redirect'].search(domain)
if data:
model, rid = data[0].resource.split(',')
resource = env[model].browse(int(rid))
return resource.get_seo_path()[0]
@http.route()
def page(self, page, **opt):
try:
view = request.website.get_template(page)
if view.seo_url:
return request.redirect(view.get_seo_path()[0], code=301)
except:
pass
return super(Website, self).page(page, **opt)
@http.route(['/website/seo_suggest'], type='json', auth='user', website=True)
def seo_suggest(self, keywords=None, lang=None):
url = "http://google.com/complete/search"
try:
params = {
'ie': 'utf8',
'oe': 'utf8',
'output' | : 'toolbar',
'q': keywords,
| }
if lang:
language = lang.split("_")
params.update({
'hl': language[0],
'gl': language[1] if len(language) > 1 else ''
})
req = urllib2.Request("%s?%s" % (url, werkzeug.url_encode(params)))
request = urllib2.urlopen(req)
except (urllib2.HTTPError, urllib2.URLError):
# TODO: shouldn't this return {} ?
return []
xmlroot = ET.fromstring(request.read())
return [sugg[0].attrib['data'] for sugg in xmlroot if len(sugg) and sugg[0].attrib['data']]
|
from . import util_CMB
import healpy as hp
import numpy as np
import os
import glob
def generate_covariances(m1, inst):
"""
Create a weight map using the smaller eigenvalue of the polarization matrix
The resulting covariances are saved on the disk.
Parameters
----------
* m1: object, contain the observations
* inst: object, contain the input parameters from the ini file
"""
nside = m1.mapinfo.nside
obspix = m1.mapinfo.obspix
Pw = util_CMB.partial2full(
util_CMB.qu_weight_mineig(
m1.cc,
m1.cs,
m1.ss,
epsilon=inst.epsilon,
verbose=inst.verbose),
obspix,
nside)
Iw = util_CMB.partial2full(m1.w, obspix, nside)
path = os.path.join(
inst.outpath_masks,
'IQU_nside%d_%s_weights_freq%s.fits' % (
nside, inst.out_name, inst.frequency))
util_CMB.write_map(
path,
[Iw, Pw, Pw],
fits_IDL=False,
coord='C',
column_names=['I', 'P', 'P'],
column_units=['1/uK2_CMB', '1/uK2_CMB', '1/uK2_CMB'],
partial=True,
extra_header=[
('name', 'SO weight maps'),
('sigma_p', m1.sigma_p, 'uK.arcmin')])
def inverse_noise_weighted_coaddition(
m1,
inst,
folder_of_covs=None,
list_of_covs=None,
temp_only=False,
save_on_disk=True):
"""
Combine covariances into one single one.
Particularly useful to mimick post-component separation analysis.
Parameters
----------
* inst: object, contain the input parameters from the ini file
* folder_of_covs: string, folder on disk containing the covariances
that you want to combine. The code assumes that the files contain
either 1 or 3 fields.
* list_of_covs: list of 1D or 3D arrays, the covariances that you want
to combine. The code assumes that each element of the list
has 1 (temp only) or 3 fields (temp + polarisation).
Output:
----------
* cov_combined: 1D or 3D array, contain the combined covariance(s).
"""
assert (folder_of_covs is None or list_of_covs is None), 'Either you give \
a folder where covariance maps are stored, \
or you give a list of covariance maps, but not both!'
if temp_only:
fields = 0
else:
fields = [0, 1, 2]
if folder_of_covs is not None:
fns = glob.glob(os.path.join(folder_of_covs, '*.fits'))
for pos, fn in enumerate(fns):
cov_tmp = hp.read_map(fn, fields)
if pos == 0:
cov_combined = cov_tmp
continue
cov_combined += cov_tmp
#### TEST
# m1.w = cov_combined[m1.mapinfo.obspix]
# from . import noise
# center = util_CMB.load_center(m1.mapinfo.source)
# noise.compute_noiselevel(
# m1=m1,
# pixel_size=hp.nside2resol(m1.mapinfo.nside) * 180. / np.pi * 60,
# center=center,
# plot=inst.plot)
#### END TEST
elif list_of_covs is not None:
cov_combined = np.sum(list_of_covs, axis=0)
if save_on_disk is True:
path = os.path.join(
inst.outpath_masks,
'IQU_nside%d_%s_weights_freq_combined.fits' % (
inst.nside_out, inst.out_name))
| util_CMB.write_map(
path,
cov_combined,
fits_IDL=False,
coord='C',
column_names=['I | ', 'P', 'P'],
column_units=['1/uK2_CMB', '1/uK2_CMB', '1/uK2_CMB'],
partial=True,
extra_header=[
('name', 'SO combined weight maps')])
return cov_combined
|
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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/l | icenses/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. Se | e the License for the
# specific language governing permissions and limitations
# under the License.
"""
Example DAG demonstrating a workflow with nested branching. The join tasks are created with
``none_failed_or_skipped`` trigger rule such that they are skipped whenever their corresponding
``BranchPythonOperator`` are skipped.
"""
from airflow.models import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import BranchPythonOperator
from airflow.utils.dates import days_ago
with DAG(dag_id="example_nested_branch_dag", start_date=days_ago(2), schedule_interval="@daily") as dag:
branch_1 = BranchPythonOperator(task_id="branch_1", python_callable=lambda: "true_1")
join_1 = DummyOperator(task_id="join_1", trigger_rule="none_failed_or_skipped")
true_1 = DummyOperator(task_id="true_1")
false_1 = DummyOperator(task_id="false_1")
branch_2 = BranchPythonOperator(task_id="branch_2", python_callable=lambda: "true_2")
join_2 = DummyOperator(task_id="join_2", trigger_rule="none_failed_or_skipped")
true_2 = DummyOperator(task_id="true_2")
false_2 = DummyOperator(task_id="false_2")
false_3 = DummyOperator(task_id="false_3")
branch_1 >> true_1 >> join_1
branch_1 >> false_1 >> branch_2 >> [true_2, false_2] >> join_2 >> false_3 >> join_1
|
import typing
from datetime import date, timedelta
def daterange( | start_date: date, end_date: date) -> typing.Iterator[date]:
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(days=n | )
|
ects.append(j)
idlDet[x].rects = validDetRects
def main():
parser = OptionParser(usage="usage: %prog [options] <groundTruthIdl> <detectionIdl>")
parser.add_option("-o", "--outFile",
action="store", type="string", dest="outFile")
parser.add_option("-a", "--analysisFiles",
action="store", type="string", dest="analysisFile")
parser.add_option("-s", "--minScore",
action="store", type="float", dest="minScore")
parser.add_option("-w", "--minWidth",
action="store", type="int", dest="minWidth", default=0)
parser.add_option("-u", "--minHeight",
action="store", type="int", dest="minHeight",default=0)
parser.add_option("--maxWidth", action="store", type="float", dest="maxWidth", default=float('inf'))
parser.add_option("--maxHeight", action="store", type="float", dest="maxHeight", default=float('inf'))
parser.add_option("-r", "--fixAspectRatio",
action="store", type="float", dest="aspectRatio")
parser.add_option("-p", "--Pascal-Style", action="store_true", dest="pascalStyle")
parser.add_option("-l", "--Leibe-Seemann-Matching-Style", action="store_true", dest="leibeStyle")
parser.add_option("--minCover", action="store", type="float", dest="minCover", default=0.5)
parser.add_option("--maxDistance", action="store", type="float", dest="maxDistance", default=0.5)
parser.add_option("--minOverlap", action="store", type="float", dest="minOverlap", default=0.5)
parser.add_option("--clipToImageWidth", action="store", type="float", dest="clipWidth", default= None)
parser.add_option("--clipToImageHeight", action="store", type="float", dest="clipHeight", default= None)
parser.add_option("-d", "--dropFirst", action="store_true", dest="dropFirst")
#parser.add_option("-c", "--class", action="store", type="int", dest="classID", default=-1)
parser.add_option("-c", "--class", action="store", type="int", dest="classID", default = None)
parser.add_option("-i", "--ignore", action="store", type="string", dest="ignoreFile")
parser.add_option("--ignoreOverlap", action="store", type="float", dest="ignoreOverlap", default = 0.9)
(options, args) = parser.parse_args()
if (len(args) < 2):
print "Please specify annotation and detection as arguments!"
parser.print_help()
sys.exit(1)
annoFile = args[0]
# First figure out the minimum height and width we are dealing with
minWidth = options.minWidth
minHeight = options.minHeight
maxWidth = options.maxWidth
maxHeight = options.maxHeight
print "Minimum width: %d height: %d" % (minWidth, minHeight)
# Load files
annoIDL = parse(annoFile)
detIDL = []
for dets in args[1:]:
detIDL += parse(dets)
if options.ignoreFile != None:
ignoreIDL = parse(options.ignoreFile)
else:
ignoreIDL = copy.deepcopy(annoIDL)
for anno in ignoreIDL:
anno.rects = []
if(options.classID is not None):
for anno in annoIDL:
anno.rects = [rect for rect in anno.rects if (rect.classID == options.classID or rect.classID == -1)]
for anno in detIDL:
anno.rects = [rect for rect in anno.rects if (rect.classID == options.classID or rect.classID == -1)]
for anno in ignoreIDL:
anno.rects = [rect for rect in anno.rects if (rect.classID == options.classID or rect.classID == -1)]
# prevent division by zero when fixing aspect ratio
for anno in annoIDL:
anno.rects = [rect for rect in anno.rects if rect.width() > 0 and rect.height() > 0]
for anno in detIDL:
anno.rects = [rect for rect in anno.rects if rect.width() > 0 and rect.height() > 0]
for anno in ignoreIDL:
anno.rects = [rect for rect in anno.rects if rect.width() > 0 and rect.height() > 0]
# Fix aspect ratio
if (not options.aspectRatio == None):
forceAspectRatio(annoIDL, options.aspectRatio)
forceAspectRatio(detIDL, options.aspectRatio)
forceAspectRatio(ignoreIDL, options.aspectRatio)
# Deselect detections with too low score
if (not options.minScore == None):
| for i,anno in enumerate(detIDL):
validRects = []
for rect in anno.rects:
if (rect.score >= options.minScore):
| validRects.append(rect)
anno.rects = validRects
# Clip detections to the image dimensions
if(options.clipWidth != None or options.clipHeight != None):
min_x = -float('inf')
min_y = -float('inf')
max_x = float('inf')
max_y = float('inf')
if(options.clipWidth != None):
min_x = 0
max_x = options.clipWidth
if(options.clipHeight != None):
min_y = 0
max_y = options.clipHeight
print "Clipping width: (%.02f-%.02f); clipping height: (%.02f-%.02f)" % (min_x, max_x, min_y, max_y)
for anno in annoIDL:
for rect in anno:
rect.clipToImage(min_x, max_x, min_y, max_y)
for anno in detIDL:
for rect in anno:
rect.clipToImage(min_x, max_x, min_y, max_y)
# Setup matching style; standard is Pascal
# style
matchingStyle = 1
# Pascal style
if (options.pascalStyle == True):
matchingStyle = 1
if (options.leibeStyle == True):
matchingStyle = 0
if (options.pascalStyle and options.leibeStyle):
print "Conflicting matching styles!"
sys.exit(1)
if (options.dropFirst == True):
print "Drop first frame of each sequence..."
newIDL = []
for i, anno in enumerate(detIDL):
if (i > 1 and detIDL[i].frameNr == detIDL[i-1].frameNr + 1 and detIDL[i].frameNr == detIDL[i-2].frameNr + 2 and detIDL[i].frameNr == detIDL[i-3].frameNr + 3 and detIDL[i].frameNr == detIDL[i-4].frameNr + 4):
newIDL.append(anno)
detIDL = newIDL
# Asort detections which are too small/too big
print "Asorting too large/ too small detections"
asort(annoIDL, detIDL, minWidth, minHeight, matchingStyle, options.minCover, options.minOverlap, options.maxDistance, maxWidth, maxHeight)
#Debugging asort
#saveIDL("testGT.idl", annoIDL)
#saveIDL("testDET.idl", detIDL)
noAnnotations = 0
for anno in annoIDL:
for j,detAnno in enumerate(detIDL):
if (suffixMatch(anno.imageName, detIDL[j].imageName) and anno.frameNr == detIDL[j].frameNr):
noAnnotations = noAnnotations + len(anno.rects)
break
print "#Annotations:", noAnnotations
###--- set up graphs ---###
print "Setting up graphs ..."
graphs = []
allRects = []
missingFrames = 0
for i in xrange(len(annoIDL)):
imageFound = False
filterIndex = -1
for j, detAnno in enumerate(detIDL):
if (suffixMatch(annoIDL[i].imageName, detIDL[j].imageName) and annoIDL[i].frameNr == detIDL[j].frameNr):
filterIndex = j
imageFound = True
break
if(not imageFound):
print "No annotation/detection pair found for: " + annoIDL[i].imageName + " frame: " + str(annoIDL[i].frameNr)
missingFrames += 1
continue;
graphs.append(AnnoGraph(annoIDL[i], detIDL[filterIndex], ignoreIDL[i], matchingStyle, options.minCover, options.minOverlap, options.maxDistance, options.ignoreOverlap))
for j,rect in enumerate(detIDL[filterIndex]):
newRect = detAnnoRect()
newRect.imageName = anno.imageName
newRect.frameNr = anno.frameNr
newRect.rect = rect
newRect.imageIndex = i - missingFrames
newRect.boxIndex = j
allRects.append(newRect)
print "missingFrames: ", missingFrames
print "Number of detections on annotated frames: " , len(allRects)
###--- get scores from all rects ---###
print "Sorting scores ..."
allRects.sort(cmpDetAnnoRectsByScore)
allRects.reverse()
###--- gradually decrease score ---###
print "Gradually decrease score ..."
lastScore = float('infinity')
precs = [1.0]
recalls = [0.0]
#fppi = [ 10**(math.floor(math.log(1.0 / float(len(annoIDL)))/math.log(10) * 10.0) / 10.0) ]
fppi = [ 1.0 / float(len(annoIDL)) ]
scores = [lastScore]
numDet = len(allRects)
sf = lastsf = 0
cd = lastcd = 0
iflow = lastiflow = 0
changed = False
firstFP = True
for i,nextrect in enumerate(allRects):
score = nextrect.rect.score;
# updating true and false positive counts
sf = sf - graphs[nextrect.imageIndex].maxflow()
cd = cd - graphs[nextrect.imageIndex].consideredDets()
iflow = iflow - graphs[nextrect.imageIndex].ignoredFlow()
#changed = changed or graphs[nextrect.imageInd |
#%% Libraries: Built-In
import numpy as np
#% Libraries: Custom
#%%
class Combiner(object):
def forward(self, input_array, weights, const):
## Define in child
pass
def backprop(self, error_array, backprop_array, learn_weight = 1e-0):
## Define in child
pass
#%%
class Linear(Combiner):
def forward(self, input_array, weights, const):
cross_vals = input_array * weights
summed_vals = cross_vals.sum(axis = 1, keepdims = True)
combined_array = summed_vals + const
return combined_array
def backprop(self, input_array, error_array, backprop_array, weights, prior_coefs, learn_weight):
#print(input_array.shape, error_array.shape, backprop_array.shape, weights.shape)
gradient_weights, gradient_const = self.gradient(
input_array,
error_array,
backprop_array
)
learning_weights, learning_const = self.learning_rate(
input_array,
error_array,
backprop_array,
weights.shape[1] + weights.shape[2],
prior_coefs
)
step_weights = gradient_weights * learning_weights * learn_weight
step_const = gradient_const * learning_const * learn_weight
new_backprop = self.update_backprop(backprop_array, weights)
return ((step_weights, step_const), new_backprop)
def gradient(self, input_array, error_array, backprop_array):
error_prop = -(error_array * backprop_array).sum(axis = 2, keepdims = True).swapaxes(1, 2)
gradient_weights = (input_array * error_prop).mean(axis = 0, keepdims = True)
gradient_const = error_prop.mean(axis = 0, keepdims = True)
return (gradient_weights, gradient_const)
def learning_rate(self, input_array, error_array, backprop_array, current_coefs, prior_coefs):
hessian_items = self.hessian(input_array, backprop_array)
step_items = self.step_size(hessian_items, current_coefs, prior_coefs)
return step_items
def hessian(self, input_array, backprop_array):
square_input = input_array ** 2
square_backprop = backprop_array.sum(axis = 2, keepdims = True).swapaxes(1, 2) ** 2
hessian_weights = (square_input * square_backprop).mean(axis = 0, keepdims = True)
hessian_weights[hessian_weights == 0] = 1
hessian_const = square_backprop.mean(axis = 0, keepdims = True)
hessian_const[hessian_const == 0] = 1
return (hessian_weights, hessian_const)
def ste | p_size(self, hes | sian_items, current_coefs, prior_coefs):
step_size = tuple([(1 / hessian) / (current_coefs + prior_coefs) for hessian in hessian_items])
return step_size
def update_backprop(self, backprop_array, weights):
new_backprop = weights.dot(backprop_array).squeeze(axis = 3).swapaxes(0, 2)
return new_backprop
#%%
|
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import os as _os
import re
from portage import _unicode_decode
from portage.exception import InvalidData
#########################################################
# This an re-implementaion of dev-util/lafilefixer-0.5.
# rewrite_lafile() takes the contents of an lafile as a string
# It then parses the dependency_libs and inherited_linker_flags
# entries.
# We insist on dependency_libs being present. inherited_linker_flags
# is optional.
# There are strict rules about the syntax imposed by libtool's libltdl.
# See 'parse_dotla_file' and 'trim' functions in libltdl/ltdl.c.
# Note that duplicated entries of dependency_libs and inherited_linker_flags
# are ignored by libtool (last one wins), but we treat it as error (like
# lafilefixer does).
# What it does:
# * Replaces all .la files with absolut paths in dependency_libs with
# corresponding -l* and -L* entries
# (/usr/lib64/libfoo.la -> -L/usr/lib64 -lfoo)
# * Moves various flags (see flag_re below) to inherited_linker_flags,
# if such an entry was present.
# * Reorders dependency_libs such that all -R* entries precede -L* entries
# and these precede all other entries.
# * Remove duplicated entries from dependency_libs
# * Takes care that no entry to inherited_linker_flags is added that is
# already there.
#########################################################
#These regexes are used to parse the interesting entries in the la file
dep_libs_re = re.compile(b"dependency_libs='(?P<value>[^']*)'$")
inh_link_flags_re = re.compile(b"inherited_linker_flags='(?P<value>[^']*)'$")
#regexes for replacing stuff in -L entries.
#replace 'X11R6/lib' and 'local/lib' with 'lib', no idea what's this about.
X11_local_sub = re.compile(b"X11R6/lib|local/lib")
#get rid of the '..'
pkgconfig_sub1 = re.compile(b"usr/lib[^/]*/pkgconfig/\.\./\.\.")
pkgconfig_sub2 = re.compile(b"(?P<usrlib>usr/lib[^/]*)/pkgconfig/\.\.")
#detect f | lags that should go into inherited_linker_flags instead of dependency_libs
flag_re = re.compile(b"-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads")
def _parse_lafile_contents(contents):
"""
Parses 'dependency_libs' and 'inherited_linker_flags' lines.
"""
dep_libs = None
inh_link_flags = None
for line in contents.split(b"\n"):
m = dep_libs_re.match(line)
if m:
if dep_libs is not None:
raise InvalidData("duplicated dependency_libs entry")
| dep_libs = m.group("value")
continue
m = inh_link_flags_re.match(line)
if m:
if inh_link_flags is not None:
raise InvalidData("duplicated inherited_linker_flags entry")
inh_link_flags = m.group("value")
continue
return dep_libs, inh_link_flags
def rewrite_lafile(contents):
"""
Given the contents of an .la file, parse and fix it.
This operates with strings of raw bytes (assumed to contain some ascii
characters), in order to avoid any potential character encoding issues.
Raises 'InvalidData' if the .la file is invalid.
@param contents: the contents of a libtool archive file
@type contents: bytes
@rtype: tuple
@return: (True, fixed_contents) if something needed to be
fixed, (False, None) otherwise.
"""
#Parse the 'dependency_libs' and 'inherited_linker_flags' lines.
dep_libs, inh_link_flags = \
_parse_lafile_contents(contents)
if dep_libs is None:
raise InvalidData("missing or invalid dependency_libs")
new_dep_libs = []
new_inh_link_flags = []
librpath = []
libladir = []
if inh_link_flags is not None:
new_inh_link_flags = inh_link_flags.split()
#Check entries in 'dependency_libs'.
for dep_libs_entry in dep_libs.split():
if dep_libs_entry.startswith(b"-l"):
#-lfoo, keep it
if dep_libs_entry not in new_dep_libs:
new_dep_libs.append(dep_libs_entry)
elif dep_libs_entry.endswith(b".la"):
#Two cases:
#1) /usr/lib64/libfoo.la, turn it into -lfoo and append -L/usr/lib64 to libladir
#2) libfoo.la, keep it
dir, file = _os.path.split(dep_libs_entry)
if not dir or not file.startswith(b"lib"):
if dep_libs_entry not in new_dep_libs:
new_dep_libs.append(dep_libs_entry)
else:
#/usr/lib64/libfoo.la -> -lfoo
lib = b"-l" + file[3:-3]
if lib not in new_dep_libs:
new_dep_libs.append(lib)
#/usr/lib64/libfoo.la -> -L/usr/lib64
ladir = b"-L" + dir
if ladir not in libladir:
libladir.append(ladir)
elif dep_libs_entry.startswith(b"-L"):
#Do some replacement magic and store them in 'libladir'.
#This allows us to place all -L entries at the beginning
#of 'dependency_libs'.
ladir = dep_libs_entry
ladir = X11_local_sub.sub(b"lib", ladir)
ladir = pkgconfig_sub1.sub(b"usr", ladir)
ladir = pkgconfig_sub2.sub(b"\g<usrlib>", ladir)
if ladir not in libladir:
libladir.append(ladir)
elif dep_libs_entry.startswith(b"-R"):
if dep_libs_entry not in librpath:
librpath.append(dep_libs_entry)
elif flag_re.match(dep_libs_entry):
#All this stuff goes into inh_link_flags, if the la file has such an entry.
#If it doesn't, they stay in 'dependency_libs'.
if inh_link_flags is not None:
if dep_libs_entry not in new_inh_link_flags:
new_inh_link_flags.append(dep_libs_entry)
else:
if dep_libs_entry not in new_dep_libs:
new_dep_libs.append(dep_libs_entry)
else:
raise InvalidData("Error: Unexpected entry '%s' in 'dependency_libs'" \
% _unicode_decode(dep_libs_entry))
#What should 'dependency_libs' and 'inherited_linker_flags' look like?
expected_dep_libs = b""
for x in (librpath, libladir, new_dep_libs):
if x:
expected_dep_libs += b" " + b" ".join(x)
expected_inh_link_flags = b""
if new_inh_link_flags:
expected_inh_link_flags += b" " + b" ".join(new_inh_link_flags)
#Don't touch the file if we don't need to, otherwise put the expected values into
#'contents' and write it into the la file.
changed = False
if dep_libs != expected_dep_libs:
contents = contents.replace(b"dependency_libs='" + dep_libs + b"'", \
b"dependency_libs='" + expected_dep_libs + b"'")
changed = True
if inh_link_flags is not None and expected_inh_link_flags != inh_link_flags:
contents = contents.replace(b"inherited_linker_flags='" + inh_link_flags + b"'", \
b"inherited_linker_flags='" + expected_inh_link_flags + b"'")
changed = True
if changed:
return True, contents
else:
return False, None
|
self.addElement(remove)
# Unpacking or unconfiguring of a package must happen after
# its pre-dependencies are configured, or before they are
# unconfigured. We do the same for normal dependencies
# (non-pre) in an advisory fashion.
for req in pkg.requires:
if isinstance(req, PreRequires):
req_type_priority = MEDIUM
else:
req_type_priority = LOW
relations = []
def add_relation(pred, succ, priority=MEDIUM):
relations.append((pred, succ, priority))
for prv in req.providedby:
for prvpkg in prv.packages:
if changeset.get(prvpkg) is INSTALL:
if op is INSTALL:
# reqpkg=INSTALL, prvpkg=INSTALL
# ------------------------------
# When the package requiring a dependency and
# the package providing a dependency are both
| # being installed, the | unpack of the dependency
# must necessarily happen before the config of
# the dependent, and in pre-depends the unpack
# of the dependent must necessarily happen
# after the config of the dependency.
add_relation((prvpkg, UNPACK), config)
add_relation((prvpkg, CONFIG), config)
add_relation((prvpkg, CONFIG), unpack,
req_type_priority)
else:
# reqpkg=REMOVE, prvpkg=INSTALL
# -----------------------------
# When the package requiring a dependency is
# being removed, and the package providing the
# dependency is being installed, the unpack
# of the dependency must necessarily happen
# before the unconfiguration of the dependent,
# and on pre-requires the configuration of the
# dependency must happen before the
# unconfiguration of the dependent.
add_relation((prvpkg, UNPACK), remove)
add_relation((prvpkg, CONFIG), remove,
req_type_priority)
elif prvpkg.installed:
if changeset.get(prvpkg) is not REMOVE:
break
if op is INSTALL:
# reqpkg=INSTALL, prvpkg=REMOVE
# ------------------------------
# When the package providing the dependency
# is being removed, it may only be used by
# the dependent package before the former is
# removed from the system. This means that
# for both dependencies and pre-dependencies
# the removal must happen before the
# configuration.
add_relation(config, (prvpkg, REMOVE))
else:
# reqpkg=REMOVE, prvpkg=REMOVE
# ------------------------------
# When both the package requiring the dependency
# and the one providing it are being removed,
# the removal of pre-dependencies must
# necessarily be done before the dependency
# removal. We can't enforce it for dependencies
# because it would easily create a cycle.
add_relation(remove, (prvpkg, REMOVE),
req_type_priority)
else:
continue
break
else:
for relation in relations:
self.addSuccessor(*relation)
if op is INSTALL:
# That's a nice trick. We put the removed package after
# the upgrading package installation. If this relation
# is broken, it means that some conflict has moved the
# upgraded package removal due to a loop. In these cases
# we remove the package before the upgrade process,
# otherwise we do the upgrade and forget about the
# removal which is after.
upgpkgs = [upgpkg for prv in pkg.provides
for upg in prv.upgradedby
for upgpkg in upg.packages]
upgpkgs.extend([prvpkg for upg in pkg.upgrades
for prv in upg.providedby
for prvpkg in prv.packages])
for upgpkg in upgpkgs:
if changeset.get(upgpkg) is REMOVE:
self.addSuccessor(unpack, (upgpkg, REMOVE), MEDIUM)
# Conflicted packages being removed must go in
# before this package's unpacking.
cnfpkgs = [prvpkg for cnf in pkg.conflicts
for prv in cnf.providedby
for prvpkg in prv.packages
if prvpkg.name != pkg.name]
cnfpkgs.extend([cnfpkg for prv in pkg.provides
for cnf in prv.conflictedby
for cnfpkg in cnf.packages
if cnfpkg.name != pkg.name])
for cnfpkg in cnfpkgs:
if changeset.get(cnfpkg) is REMOVE:
self.addSuccessor((cnfpkg, REMOVE), unpack, HIGH)
class DebPackageManager(PackageManager):
MAXPKGSPEROP = 50
def commit(self, changeset, pkgpaths):
prog = iface.getProgress(self)
prog.start()
prog.setTopic(_("Committing transaction..."))
prog.show()
# Compute upgraded packages
upgraded = {}
for pkg in changeset.keys():
if changeset[pkg] is INSTALL:
upgpkgs = [upgpkg for prv in pkg.provides
for upg in prv.upgradedby
for upgpkg in upg.packages
if upgpkg.installed]
upgpkgs.extend([prvpkg for upg in pkg.upgrades
for prv in upg.providedby
for prvpkg in prv.packages
if prvpkg.installed])
if upgpkgs:
for upgpkg in upgpkgs:
assert changeset.get(upgpkg) is REMOVE, \
"Installing %s while %s is kept?" % \
(pkg, upgpkg)
assert upgpkg not in upgraded, \
"Two packages (%s and %s) upgrading the " \
"same installed package (%s)!?" % \
(pkg, upgraded[upgpkg], upgpkg)
upgraded[upgpkg] = pkg
sorter = DebSorter(changeset)
sorted = sorter.getSorted()
prog.set(0, len(sorted))
baseargs = shlex.split(sysconf.get("dpkg", "dpkg"))
opt = sysconf.get("deb-root")
if opt:
baseargs.append("--root=%s" % opt)
opt = s |
import sublime
import unittest
from PackageBoilerplate import package_boilerplate
# Remember:
# Install AAAPT package to run the tests
# Save package_boilerplate to reload the tests
clas | s Test_BasePath(unittest.TestCase):
def test_join_combines_the_packages_path_with_the_supplied_one(self):
result = package_boilerplate.BasePath.join(" | some/new/path")
self.assertEquals(result, sublime.packages_path() + "/PackageBoilerplate/some/new/path")
def test_join_combines_the_packages_path_with_all_the_supplied_arguments(self):
result = package_boilerplate.BasePath.join("some", "new", "path")
self.assertEquals(result, sublime.packages_path() + "/PackageBoilerplate/some/new/path")
|
#!/usr/bin/env python3
# Copyright (C) 2016 Job Snijders <job@instituut.net>
#
# This file is part of rtrsub
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the follow | ing disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import rtrsub
version = rtrsub.__version__
import codecs
import os
import sys
from os.path import abspath, dirname, join
from setuptools import setup, find_packages
here = abspath(dirname(__file__))
def parse_requirements(filename):
""" load requirements from a pip requirements file """
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
with codecs.open(join(here, 'README.md'), encoding='utf-8') as f:
README = f.read()
if sys.argv[-1] == 'publish':
os.system('python3 setup.py sdist upload')
print("You probably want to also tag the version now:")
print((" git tag -a %s -m 'version %s'" % (version, version)))
print(" git push --tags")
sys.exit()
install_reqs = parse_requirements('requirements.txt')
reqs = install_reqs
setup(
name='rtrsub',
version=version,
maintainer="Job Snijders",
maintainer_email='job@instituut.net',
url='https://github.com/job/rtrsub',
description='RTR Substitution',
long_description=README,
long_description_content_type="text/markdown",
license='BSD 2-Clause',
keywords='rpki prefix routing networking',
setup_requires=reqs,
install_requires=reqs,
classifiers=[
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Networking',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3 :: Only'
],
packages=find_packages(exclude=['tests', 'tests.*']),
entry_points={'console_scripts': ['rtrsub = rtrsub.rtrsub:main']},
)
|
# Same version and same pre-release, check if dev version
if self.is_devversion is other.is_devversion:
vercmp = 0
elif self.is_devversion:
vercmp = -1
else:
vercmp = 1
return vercmp
def __lt__(self, other):
return self._compare(other) < 0
def __le__(self, other):
return self._compare(other) <= 0
def __eq__(self, other):
return self._compare(other) == 0
def __ne__(self, other):
return self._compare(other) != 0
def __gt__(self, other):
return self._compare(other) > 0
def __ge__(self, other):
return self._compare(other) >= 0
def __repr(self):
return "NumpyVersion(%s)" % self.vstring
class ResettableCache(dict):
"""
Dictionary whose elements mey depend one from another.
If entry `B` depends on entry `A`, changing the values of entry `A` will
reset the value of entry `B` to a default (None); deleteing entry `A` will
delete entry `B`. The connections between entries are stored in a
`_resetdict` private attribute.
Parameters
----------
reset : dictionary, optional
An optional dictionary, associated a sequence of entries to any key
of the object.
items : var, optional
An optional dictionary used to initialize the dictionary
Examples
--------
>>> reset = dict(a=('b',), b=('c',))
>>> cache = resettable_cache(a=0, b=1, c=2, reset=reset)
>>> assert_equal(cache, dict(a=0, b=1, c=2))
>>> print("Try resetting a")
>>> cache['a'] = 1
>>> assert_equal(cache, dict(a=1, b=None, c=None))
>>> cache['c'] = 2
>>> assert_equal(cache, dict(a=1, b=None, c=2))
>>> cache['b'] = 0
>>> assert_equal(cache, dict(a=1, b=0, c=None))
>>> print("Try deleting b")
>>> del(cache['a'])
>>> assert_equal(cache, {})
"""
def __init__(self, reset=None, **items):
self._resetdict = reset or {}
dict.__init__(self, **items)
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
# if hasattr needed for unpickling with protocol=2
if hasattr(self, '_resetdict'):
for mustreset in self._resetdict.get(key, []):
self[mustreset] = None
def __delitem__(self, key):
dict.__delitem__(self, key)
for mustreset in self._resetdict.get(key, []):
del(self[mustreset])
# def __getstate__(self):
# print('pickling wrapper', self.__dict__)
# return self.__dict__
#
# def __setstate__(self, dict_):
# print('unpickling wrapper', dict_)
# self.__dict__.update(dict_)
resettable_cache = ResettableCache
def _next_regular(target):
"""
Find the next regular number greater than or equal to target.
Regular numbers are composites of the prime factors 2, 3, and 5.
Also known as 5-smooth numbers or Hamming numbers, these are the optimal
size for inputs to FFTPACK.
Target must be a positive integer.
"""
if target <= 6:
return target
# Quickly check if it's already a power of 2
if not (target & (target - 1)):
return target
match = float('inf') # Anything found will be smaller
p5 = 1
while p5 < target:
p35 = p5
while p35 < target:
# Ceiling integer division, avoiding conversion to float
# (quotient = ceil(target / p35))
quotient = -(-target // p35)
# Quickly find next power of 2 >= quotient
try:
p2 = 2 ** ((quotient - 1).bit_length())
except AttributeError:
# Fallback for Python <2.7
p2 = 2 ** _bit_length_26(quotient - 1)
N = p2 * p35
if N == target:
return N
elif N < match:
match = N
p35 *= 3
if p35 == target:
return p35
if p35 < match:
match = p35
p5 *= 5
if p5 == target:
return p5
if p5 < match:
match = p5
return match
if NumpyVersion(np.__version__) >= '1.7.1':
np_matrix_rank = np.linalg.matrix_rank
else:
def np_matrix_rank(M, tol=None):
"""
Return matrix rank of array using SVD method
Rank of the array is the number of SVD singular values of the array that are
greater than `tol`.
Parameters
----------
M : {(M,), (M, N)} array_like
array of <=2 dimensions
tol : {None, float}, optional
threshold below which SVD values are considered zero. If `tol` is
None, and ``S`` is an array with singular values for `M`, and
``eps`` is the epsilon value for datatype of ``S``, then `tol` is
set to ``S.max() * max(M.shape) * eps``.
Notes
-----
The default threshold to detect rank deficiency is a test on the magnitude
of the singular values of `M`. By default, we identify singular values less
than ``S.max() * max(M.shape) * eps`` as indicating rank deficiency (with
the symbols defined above). This is the algorithm MATLAB uses [1]. It also
appears in *Numerical recipes* in the discussion of SVD solutions for linear
least squares [2].
This default threshold is designed to detect rank deficiency accounting for
the numerical errors of the SVD computation. Imagine that there is a column
in `M` that is an exact (in floating point) linear combination of other
columns in `M`. Computing the SVD on `M` will not produce a singular value
exactly equal to 0 in general: any difference of the smallest SVD value from
0 will be caused by numerical imprecision in the calculation of the SVD.
Our threshold for small SVD values takes this numerical imprecision into
account, and the default threshold will detect such numerical rank
deficiency. The threshold may declare a matrix `M` rank deficient even if
the linear combination of some columns of `M` is not exactly equal to
another column of `M` but only numerically very close to another column of
`M`.
We chose our default threshold because it is in wide use. Other thresholds
are possible. For example, elsewhere in the 2007 edition of *Numerical
recipes* there is an alternative threshold of ``S.max() *
np.finfo(M.dtype).eps / 2. * np.sqrt(m + n + 1.)``. The authors describe
this threshold as being based on "expected roundoff error" (p 71).
The thresholds above deal with floating point roundoff error in the
calculation of the SVD. However, you may have more information about the
sources of error in `M` that would make you consider other tolerance values
to detect *effective* rank deficiency. The most useful measure of the
tolerance depends on the operations you intend to use on your matrix. For
example, if your | data come from uncertain measurements with uncertainties
greater than floating point epsilon, choosing a tolerance near that
uncertainty may be preferable. The tolerance may be absolute if the
uncertainties are ab | solute rather than relative.
References
----------
.. [1] MATLAB reference documention, "Rank"
http://www.mathworks.com/help/techdoc/ref/rank.html
.. [2] W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery,
"Numerical Recipes (3rd edition)", Cambridge University Press, 2007,
page 795.
Examples
--------
>>> from numpy.linalg import matrix_rank
>>> matrix_rank(np.eye(4)) # Full rank matrix
4
>>> I=np.eye(4); I[-1,-1] = 0. # rank deficient matrix
>>> matrix_rank(I)
3
>>> matrix_rank(np.ones((4,))) # 1 dimension - rank 1 unless all 0
1
>>> matrix_rank(np.zeros((4,)))
|
.slice_ind = 10
assert exc.value.args[0] == "Can only set slice_ind for 3D images"
def test_slice_disabled_for_no_data(self):
client = self.new_client()
assert client.slice_ind is None
with pytest.raises(IndexError) as exc:
client.slice_ind = 10
assert exc.value.args[0] == "Can only set slice_ind for 3D images"
def test_slice_enabled_for_3D(self):
client = self.create_client_with_cube()
assert client.slice_ind is not None
client.slice_ind = 5
assert client.slice_ind == 5
def test_add_subset_via_method(self):
client = self.new_client()
self.collect.append(self.im) |
s = self.im.new_subset()
client.add_layer(s)
assert s in client.artists
def test_remove_data(self):
client = self.new_client()
self.collect.append(self.im)
s = se | lf.im.new_subset()
client.add_layer(self.im)
assert self.im in client.artists
assert s in client.artists
client.delete_layer(self.im)
assert client.display_data is not self.im
assert not self.im in client.artists
assert not s in client.artists
def test_delete_data(self):
client = self.create_client_with_image()
client.delete_layer(self.im)
assert not self.im in client.artists
def test_set_attribute(self):
client = self.create_client_with_image()
atts = self.im.component_ids()
assert len(atts) > 1
for att in atts:
client.set_attribute(att)
assert client.display_attribute is att
def test_get_attribute(self):
client = self.create_client_with_image()
atts = self.im.component_ids()
assert len(atts) > 1
for att in atts:
client.set_attribute(att)
assert client.display_attribute is att
def test_set_data_and_attribute(self):
client = self.create_client_with_image()
atts = self.im.component_ids()
assert len(atts) > 1
for att in atts:
client.set_data(self.im, attribute=att)
assert client.display_attribute is att
assert client.display_data is self.im
def test_slice_ori_on_2d_raises(self):
client = self.create_client_with_image()
with pytest.raises(IndexError) as exc:
client.set_slice_ori(0)
assert exc.value.args[0] == "Can only set slice_ori for 3D images"
def test_slice_ori_out_of_bounds(self):
client = self.create_client_with_image()
self.collect.append(self.cube)
client.set_data(self.cube)
with pytest.raises(ValueError) as exc:
client.set_slice_ori(100)
assert exc.value.args[0] == "Orientation must be 0, 1, or 2"
def test_apply_roi_2d(self):
"""apply_roi is applied to all edit_subsets"""
client = self.create_client_with_image()
roi = core.roi.PolygonalROI(vx=[10, 20, 20, 10],
vy=[10, 10, 20, 20])
client.apply_roi(roi)
roi2 = self.im.edit_subset.subset_state.roi
state = self.im.edit_subset.subset_state
assert roi2.to_polygon()[0] == roi.to_polygon()[0]
assert roi2.to_polygon()[1] == roi.to_polygon()[1]
assert state.xatt is self.im.get_pixel_component_id(1)
assert state.yatt is self.im.get_pixel_component_id(0)
def test_apply_roi_3d(self):
client = self.create_client_with_cube()
self.cube.coords = DummyCoords()
roi = core.roi.PolygonalROI(vx=[10, 20, 20, 10],
vy=[10, 10, 20, 20])
client.set_slice_ori(0)
client.apply_roi(roi)
state = self.cube.edit_subset.subset_state
roi2 = state.roi
assert state.xatt is self.cube.get_pixel_component_id(2)
assert state.yatt is self.cube.get_pixel_component_id(1)
assert roi2.to_polygon()[0] == roi.to_polygon()[0]
assert roi2.to_polygon()[1] == roi.to_polygon()[1]
client.set_slice_ori(1)
client.apply_roi(roi)
state = self.cube.edit_subset.subset_state
roi2 = state.roi
assert state.xatt is self.cube.get_pixel_component_id(2)
assert state.yatt is self.cube.get_pixel_component_id(0)
assert roi2.to_polygon()[0] == roi.to_polygon()[0]
assert roi2.to_polygon()[1] == roi.to_polygon()[1]
client.set_slice_ori(2)
client.apply_roi(roi)
state = self.cube.edit_subset.subset_state
roi2 = state.roi
assert state.xatt is self.cube.get_pixel_component_id(1)
assert state.yatt is self.cube.get_pixel_component_id(0)
assert roi2.to_polygon()[0] == roi.to_polygon()[0]
assert roi2.to_polygon()[1] == roi.to_polygon()[1]
def test_subsets_shown_on_init(self):
client = self.create_client_with_image()
subset = self.im.edit_subset
assert subset in client.artists
def test_add_scatter_layer(self):
client = self.create_client_with_image_and_scatter()
assert self.scatter in client.artists
for a in client.artists[self.scatter]:
assert a.visible
def test_data_scatter_emphasis_updates_on_slice_change(self):
# regression test for 367
client = self.create_client_with_cube_and_scatter()
layer = client.artists[self.scatter][0]
emph0 = layer.emphasis
client.slice = (2, 'y', 'x')
assert layer.emphasis is not emph0
def test_scatter_persistent(self):
"""Ensure that updates to data plot don't erase scatter artists"""
client = self.create_client_with_image_and_scatter()
assert self.scatter in client.artists
client._update_data_plot()
assert self.scatter in client.artists
def test_scatter_sync(self):
""" Regression test for #360 """
client = self.create_client_with_image_and_scatter()
client.register_to_hub(self.collect.hub)
self.scatter.label = 'scatter'
sg = self.collect.new_subset_group()
subset = sg.subsets[-1]
assert subset.data is self.scatter
client.add_scatter_layer(subset)
art = client.artists[subset][0].artists
sg.subset_state = self.scatter.id['x'] > 2
client._update_subset_single(subset)
assert client.artists[subset][0].artists is not art
def test_scatter_subsets_not_auto_added(self):
"""Scatter subsets should not be added by
SubsetAddMessage"""
c = self.create_client_with_image()
self.collect.append(self.scatter)
c.register_to_hub(self.collect.hub)
s = self.scatter.new_subset()
assert s not in c.artists
def test_scatter_layer_does_not_set_display_data(self):
c = self.create_client_with_image()
self.collect.append(self.scatter)
d = c.display_data
c.set_data(self.scatter)
assert c.display_data is d
def test_4d(self):
c = self.create_client_with_hypercube()
assert c.display_data is self.cube4
def test_format_coord_works_without_data(self):
# regression test for 402
client = self.new_client()
expected = dict(labels=['x=3', 'y=5'],
pix=(3, 5), world=(3, 5), value=np.nan)
assert client.point_details(3, 5) == expected
def test_visibility_toggles(self):
c = self.create_client_with_image()
s = self.im.edit_subset
c.add_layer(s)
c.set_visible(self.im, False)
assert not c.is_visible(self.im)
assert c.is_visible(s)
c.set_visible(self.im, True)
assert c.is_visible(self.im)
assert c.is_visible(s)
c.set_visible(s, False)
assert c.is_visible(self.im)
assert not c.is_visible(s)
def test_component_replaced(self):
# Regression test for #508
c = self.create_client_with_image()
d = c.display_data
a = c.display_attribute
test = core.ComponentID('test')
c.register_to_hub(d.hub)
d.update_id(a, test)
assert |
#!/usr/bin/python
from math import exp
import shtest, sys
def exp_test(p, base, types=[], epsilon=0):
if base > 0:
result = [pow(base, a) for a in p]
else:
result = [exp(a) for a in p]
return shtest.make_test(result, [p], types, epsilon)
def insert_into(test, base=0):
test.add_test(exp_test((0.0, 1.0, 2.0), base))
test.add_test(exp_test((0.1, 0.25, 0.3, 0.5), base))
test.add_test(exp_test((-2.0, -3.0), base))
test.add_test(exp_test((-0.5, -1.0), base))
if base == 10:
test.add_test(exp_test((2.3, 2.9), base, [], 0.1))
test.add_test(exp_test((3.8, 4.0), base, [], 1))
else:
test.add_test(exp_test((2.3, 2.9), base))
test.add_test(exp_test((3.8, 4.0), base))
# Test exp in s | tream programs
test = shtest.StreamTest('exp', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp', 1))
insert_into(test)
test.output_header(sys.stdout)
test.output(sys.stdout, False)
# Test exp2 in stream programs
test = shtest.StreamTest('exp2', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp2', 1))
insert_into(test, 2)
test.output(sys.stdout, False)
# Test exp10 in stream programs
test = shtest.StreamTest('exp10', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp10', 1 | ))
insert_into(test, 10)
test.output(sys.stdout, False)
# Test exp in immediate mode
test = shtest.ImmediateTest('exp_im', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp', 1))
insert_into(test)
test.output(sys.stdout, False)
# Test exp2 in immediate mode
test = shtest.ImmediateTest('exp2_im', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp2', 1))
insert_into(test, 2)
test.output(sys.stdout, False)
# Test exp10 in immediate mode
test = shtest.ImmediateTest('exp10_im', 1)
test.add_call(shtest.Call(shtest.Call.call, 'exp10', 1))
insert_into(test, 10)
test.output(sys.stdout, False)
test.output_footer(sys.stdout)
|
from untwisted.network import spawn
from untwisted.event import get_event
from untwisted.splits import Terminator
from re import *
GENERAL_STR = '[^ ]+'
GENERAL_REG = compile(GENERAL_STR)
SESSION_STR = '\*\*\*\* Starting FICS session as (?P<username>.+) \*\*\*\*'
SESSION_REG = compile(SESSION_STR)
TELL_STR = '(?P<nick>[a-zA-Z]+)(?P<mode>.*) tells you:(?P<msg>.+)'
TELL_REG = compile(TELL_STR)
SAY_STR = '(?P<nick>[a-zA-Z]+)(?P<mode>.*) says:(?P<msg>.+)'
SAY_REG = compile(SAY_STR)
SHOUT_STR = '(?P<nick>[a-zA-Z]+)(?P<mode>.*) shouts:(?P<msg>.+)'
SHOUT_REG = compile(SHOUT_STR)
START_SESSION = get_event()
TELL = get_event()
SAY = get_event()
SHOUT = get_event()
def install(spin):
spin.add_map(Terminator.FOUND, spliter)
def spliter(spin, data):
m = findall(GENERAL_REG, data)
if m: spawn(spin, *m)
m = match(SESSION_REG, data)
try:
username = m.group('username')
except:
pass
else:
spawn(spin, START_SESSION, username)
m = match( | TELL_REG, data)
try:
nick = m.group('nick')
msg = m.group('msg')
mode = m.group('mode')
except:
pas | s
else:
spawn(spin, TELL, nick, mode, msg)
spawn(spin, '%s tells you:' % nick, mode, msg)
m = match(SAY_REG, data)
try:
nick = m.group('nick')
msg = m.group('msg')
mode = m.group('mode')
except:
pass
else:
spawn(spin, SAY, nick, mode, msg)
spawn(spin, '%s says:' % nick, mode, msg)
m = match(SHOUT_REG, data)
try:
nick = m.group('nick')
mode = m.group('mode')
msg = m.group('msg')
except:
pass
else:
spawn(spin, SHOUT, nick, mode, msg)
|
from textwrap import dedent
def get_definition_and_inference_st | ate(Script, source):
first, = Script(dedent(source)).infer()
return first._name._value, first._inference_state
def test_function_execution(Script):
"""
We've been having an issue of a mutable list that was changed inside the
function execution. Test if an execution always returns the same result.
"""
s = """
def x():
return str()
x"""
func, inference_state = get_definition_and_infer | ence_state(Script, s)
# Now just use the internals of the result (easiest way to get a fully
# usable function).
# Should return the same result both times.
assert len(func.execute_with_values()) == 1
assert len(func.execute_with_values()) == 1
def test_class_mro(Script):
s = """
class X(object):
pass
X"""
cls, inference_state = get_definition_and_inference_state(Script, s)
mro = cls.py__mro__()
assert [c.name.string_name for c in mro] == ['X', 'object']
|
import pygame
import sys
from game import constants, gamestate
from game.ai.easy import EasyAI
from game.media import media
from game.scene import Scene
# List of menu options (text, action_method, condition) where condition is None or a callable.
# If it is a callable that returns False, the option is not shown.
CONTINUE = 0
NEW_GAME = 1
QUIT = 2
OPTIONS = [
('Continue', 'opt_continue', lambda scene: scene.game_running),
('2 Player', 'start_2_player', None),
('Vs CPU', 'start_vs_cpu', None),
('Computer Battle!', 'start_cpu_vs_cpu', None),
('Quit', 'opt_quit', None),
]
class MenuScene(Scene):
def load(self):
self.font = pygame.font.Font(constants.MENU_FONT, constants.MENU_FONT_SIZE)
self.active_font = pygame.font.Font(constants.MENU_FONT, constants.MENU_FONT_SIZE_ACTIVE)
media.play_music('intro')
def setup(self, first_time=False):
# Selected menu choice - if "Continue" is there, have that selected
self._current_option = NEW_GAME if first_time else CONTINUE
self.game_running = self.manager.get_state('main', 'running')
def render_options(self, screen):
x, y = 30, 30
for index, (text, action, show) in enumerate(OPTIONS):
if show is not None and not show(self):
continue
active = index == self._current_option
font = self.active_font if active else self.font
surf = font.render(text, True, constants.MENU_FONT_COLOR)
screen.blit(surf, (x, y))
if active:
screen.blit(media['i | mg.arrow'], | (x - 25, y + 12))
y += surf.get_height() + 10
def render(self, screen):
screen.blit(media['img.title'], (0, 0))
self.render_options(screen)
def opt_continue(self):
self.manager.switch_scene('main')
return True
def new_match(self, player1, player2):
media.fade_music(1000)
gamestate.new_game(player1, player2)
self.manager.switch_scene('main')
return True
def start_2_player(self):
self.new_match(gamestate.HUMAN, gamestate.HUMAN)
def start_vs_cpu(self):
self.new_match(gamestate.HUMAN, EasyAI())
def start_cpu_vs_cpu(self):
self.new_match(EasyAI(), EasyAI())
def opt_quit(self):
sys.exit()
def do_event(self, event):
if event.type == pygame.KEYUP:
if event.key == pygame.K_ESCAPE:
if self.game_running:
self.manager.switch_scene('main')
return
elif event.key in (pygame.K_UP, pygame.K_DOWN):
media['snd.button'].play()
move = -1 if event.key == pygame.K_UP else 1
self._current_option = (self._current_option + move) % len(OPTIONS)
if self._current_option == CONTINUE and not self.game_running:
self._current_option = NEW_GAME if event.key == pygame.K_DOWN else (len(OPTIONS) - 1)
elif event.key == pygame.K_RETURN:
if self._current_option != NEW_GAME:
media['snd.button_press'].play()
action = OPTIONS[self._current_option][1]
return getattr(self, action)()
return False
|
# -*- test-case-name: twisted.test.test_fdesc -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Utility functions for dealing with POSIX file descriptors.
"""
import os
import errno
try:
import fcntl
except ImportError:
fcntl = None
# twisted imports
from twisted.internet.main import CONNECTION_LOST, CONNECTION_DONE
def setNonBlocking(fd):
"""
Set the file description of the given file descriptor to non-blocking.
"""
if fcntl is None:
return
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
flags = flags | os.O_NON | BLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
def setBlocking(fd):
"""
Set the file description of the given file descripto | r to blocking.
"""
if fcntl is None:
return
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
flags = flags & ~os.O_NONBLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
if fcntl is None:
# fcntl isn't available on Windows. By default, handles aren't
# inherited on Windows, so we can do nothing here.
_setCloseOnExec = _unsetCloseOnExec = lambda fd: None
else:
def _setCloseOnExec(fd):
"""
Make a file descriptor close-on-exec.
"""
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags = flags | fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
def _unsetCloseOnExec(fd):
"""
Make a file descriptor close-on-exec.
"""
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags = flags & ~fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
def readFromFD(fd, callback):
"""
Read from file descriptor, calling callback with resulting data.
If successful, call 'callback' with a single argument: the
resulting data.
Returns same thing FileDescriptor.doRead would: CONNECTION_LOST,
CONNECTION_DONE, or None.
@type fd: C{int}
@param fd: non-blocking file descriptor to be read from.
@param callback: a callable which accepts a single argument. If
data is read from the file descriptor it will be called with this
data. Handling exceptions from calling the callback is up to the
caller.
Note that if the descriptor is still connected but no data is read,
None will be returned but callback will not be called.
@return: CONNECTION_LOST on error, CONNECTION_DONE when fd is
closed, otherwise None.
"""
try:
output = os.read(fd, 8192)
except (OSError, IOError) as ioe:
if ioe.args[0] in (errno.EAGAIN, errno.EINTR):
return
else:
return CONNECTION_LOST
if not output:
return CONNECTION_DONE
callback(output)
def writeToFD(fd, data):
"""
Write data to file descriptor.
Returns same thing FileDescriptor.writeSomeData would.
@type fd: C{int}
@param fd: non-blocking file descriptor to be written to.
@type data: C{str} or C{buffer}
@param data: bytes to write to fd.
@return: number of bytes written, or CONNECTION_LOST.
"""
try:
return os.write(fd, data)
except (OSError, IOError) as io:
if io.errno in (errno.EAGAIN, errno.EINTR):
return 0
return CONNECTION_LOST
__all__ = ["setNonBlocking", "setBlocking", "readFromFD", "writeToFD"]
|
x = np.linspace(0, 100, samples)
return a, b, x, samples
def similarity_data() -> Tuple[np.ndarray, np.ndarray, int, np.ndarray, int]:
rotation = np.array([0.1, 0.2, 0.3])
translation = np.array([4, 5, 6])
scale = 2
samples = 100
x = np.random.rand(samples, 3)
return rotation, translation, scale, x, samples
def add_outliers(ratio_outliers: float, x: np.ndarray, min: float, max: float) -> None:
for index in np.random.permutation(len(x))[: int(ratio_outliers * len(x))]:
shape = x[index].shape
noise = np.random.uniform(min, max, siz | e=shape)
if len(shape) == 0:
sign = 1 if np.random.randint(2) > 0 else -1
else:
sign = [1 i | f r > 0 else -1 for r in np.random.randint(2, size=shape)]
x[int(index)] += sign * noise
def test_uniform_line_ransac() -> None:
a, b, x, samples = line_data()
scale = 2.0
y = a * x + b + np.random.rand(x.shape[0]) * scale
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_line(data, scale, params, pyrobust.RansacType.RANSAC)
assert result.score == samples
assert len(result.inliers_indices) == samples
def test_outliers_line_ransac() -> None:
a, b, x, samples = line_data()
scale = 2.0
y = a * x + b + np.random.rand(x.shape[0]) * scale
ratio_outliers = 0.4
outliers_max = 5.0
add_outliers(ratio_outliers, x, scale, outliers_max)
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_line(data, scale, params, pyrobust.RansacType.RANSAC)
inliers_count = (1 - ratio_outliers) * samples
assert np.allclose(result.score, inliers_count, atol=1)
assert np.allclose(len(result.inliers_indices), inliers_count, atol=1)
def test_normal_line_msac() -> None:
a, b, x, samples = line_data()
sigma = 2.0
y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])
multiplier = 1.96
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_line(
data, multiplier * sigma, params, pyrobust.RansacType.MSAC
)
confidence = 0.95 # 1.96*MAD -> 95% rejecting inliers
assert np.isclose(
len(result.inliers_indices), samples, rtol=(1 - confidence), atol=8
)
def test_outliers_line_msac() -> None:
a, b, x, samples = line_data()
sigma = 2.0
y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])
multiplier = 1.96
ratio_outliers = 0.4
outliers_max = 5.0
add_outliers(ratio_outliers, x, multiplier * sigma, multiplier * outliers_max)
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_line(
data, multiplier * sigma, params, pyrobust.RansacType.MSAC
)
inliers_count = (1 - ratio_outliers) * samples
confidence = 0.95 # 1.96*MAD -> 95% rejecting inliers
assert np.isclose(
len(result.inliers_indices), inliers_count, rtol=(1 - confidence), atol=5
)
def test_normal_line_LMedS() -> None:
a, b, x, samples = line_data()
sigma = 2.0
y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])
multiplier = 1.96
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_line(data, multiplier, params, pyrobust.RansacType.LMedS)
confidence = 0.95 # 1.96*MAD -> 95% rejecting inliers
assert np.isclose(
len(result.inliers_indices), samples, rtol=(1 - confidence), atol=11
)
def test_outliers_line_LMedS() -> None:
a, b, x, samples = line_data()
sigma = 2.0
y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])
multiplier = 1.96
ratio_outliers = 0.4
outliers_max = 5.0
add_outliers(ratio_outliers, x, multiplier * sigma, multiplier * outliers_max)
data = np.array([x, y]).transpose()
params = pyrobust.RobustEstimatorParams()
# can't be used with LMedS as an over-estimated sigma will make it stop early
params.use_iteration_reduction = False
result = pyrobust.ransac_line(data, multiplier, params, pyrobust.RansacType.LMedS)
inliers_count = (1 - ratio_outliers) * samples
confidence = 0.95 # 1.96*MAD -> 95% rejecting inliers
assert np.isclose(
len(result.inliers_indices), inliers_count, rtol=(1 - confidence), atol=8
)
def test_outliers_similarity_ransac() -> None:
rotation, translation, scale, x, samples = similarity_data()
similarity = pygeometry.Similarity(rotation, translation, scale)
y = np.array([similarity.transform(p) for p in x])
sigma = 0.001
y += np.random.normal(scale=sigma, size=y.shape)
outliers_max = 1.0
ratio_outliers = 0.3
add_outliers(ratio_outliers, x, scale, outliers_max)
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_similarity(x, y, 0.1, params, pyrobust.RansacType.RANSAC)
inliers_count = (1 - ratio_outliers) * samples
confidence = 0.95 # 1.96*MAD -> 95% rejecting inliers
assert np.isclose(
len(result.inliers_indices), inliers_count, rtol=(1 - confidence), atol=8
)
def test_uniform_essential_ransac(pairs_and_their_E) -> None:
for f1, f2, _, _ in pairs_and_their_E:
points = np.concatenate((f1, f2), axis=1)
scale = 1e-2
points += np.random.rand(*points.shape) * scale
f1, f2 = points[:, 0:3], points[:, 3:6]
f1 /= np.linalg.norm(f1, axis=1)[:, None]
f2 /= np.linalg.norm(f2, axis=1)[:, None]
scale_eps_ratio = 5e-1
params = pyrobust.RobustEstimatorParams()
params.use_iteration_reduction = False
result = pyrobust.ransac_essential(
f1, f2, scale * (1.0 + scale_eps_ratio), params, pyrobust.RansacType.RANSAC
)
assert len(result.inliers_indices) == len(f1) == len(f2)
def test_outliers_essential_ransac(pairs_and_their_E) -> None:
for f1, f2, _, _ in pairs_and_their_E:
points = np.concatenate((f1, f2), axis=1)
scale = 1e-3
points += np.random.rand(*points.shape) * scale
ratio_outliers = 0.3
add_outliers(ratio_outliers, points, 0.1, 0.4)
f1, f2 = points[:, 0:3], points[:, 3:6]
f1 /= np.linalg.norm(f1, axis=1)[:, None]
f2 /= np.linalg.norm(f2, axis=1)[:, None]
scale_eps_ratio = 0.5
params = pyrobust.RobustEstimatorParams()
result = pyrobust.ransac_essential(
f1, f2, scale * (1.0 + scale_eps_ratio), params, pyrobust.RansacType.RANSAC
)
tolerance = 0.12 # some outliers might have been moved along the epipolar
inliers_count = (1 - ratio_outliers) * len(points)
assert np.isclose(len(result.inliers_indices), inliers_count, rtol=tolerance)
def test_outliers_relative_pose_ransac(pairs_and_their_E) -> None:
for f1, f2, _, pose in pairs_and_their_E:
points = np.concatenate((f1, f2), axis=1)
scale = 1e-3
points += np.random.rand(*points.shape) * scale
ratio_outliers = 0.3
add_outliers(ratio_outliers, points, 0.1, 1.0)
f1, f2 = points[:, 0:3], points[:, 3:6]
f1 /= np.linalg.norm(f1, axis=1)[:, None]
f2 /= np.linalg.norm(f2, axis=1)[:, None]
scale_eps_ratio = 1e-1
params = pyrobust.RobustEstimatorParams()
params.iterations = 1000
result = pyrobust.ransac_relative_pose(
f1, f2, scale * (1.0 + scale_eps_ratio), params, pyrobust.RansacType.RANSAC
)
expected = pose.get_world_to_cam()[:3]
expected[:, 3] /= np.linalg.norm(expected[:, 3])
tolerance = 0.15
inliers_count = (1 - ratio_outliers) * len(points)
assert np.isclose(len(result.inliers_indices), inliers_count, rtol=tolerance)
assert np.linalg.norm(expected - result.lo_model, ord="fro") < 16e-2
def test_outliers_relative_rotation_ransac(pairs_and_their_E) -> None:
for f1, _, _, _ in pairs_and_their_E:
vec_x = np.random.rand(3)
vec_x /= np.linalg.norm(vec_x)
|
import redis
import json
from flask im | port current_app
class CachingService:
rc = None
def cache(self):
if self.rc is None:
self.rc = redis.StrictRedis(host=current_app.config['CACHE_HOST'], port=current_app.config['CACHE_PORT'], db=0)
return self.rc
def get(self, key: str) -> dict:
v = self.cache().get(key)
retVal = None
if v is not None:
retVal = json.loads(v.decode("utf-8" | ))
return retVal
def set(self, key: str, value: dict):
self.cache().set(key, json.dumps(value))
def remove(self, key: str):
self.cache().delete(key)
|
#!/usr/bin/python
import sys
from subprocess import call
print "Usage: bg_count.py ListOfBamFiles Reference"
try:
li = sys.argv[1]
except:
li = raw_input("Introduce List of indexed BAM files: ")
try:
ref = sys.argv[2]
except:
ref = raw_input("Introduce Reference in FASTA format: ")
files = open(li).readlines()
li_bg = []
li_names = | []
for file in files:
file = file[:-1]
li_bg.append(file+".bg")
name = file.split(".")
li_names.append(name[0])
call("genomeCoverageBed -bg -ibam %s > %s.bg" % (file,file), shell=True)
call("unionBedGraphs -header -i %s -names %s -g %s -empty > samples1and2.txt" % (" ".join(li_bg), " | ".join(li_names), ref+".fai"), shell=True)
call("coverage_seq_bed.py samples1and2.txt", shell=True)
|
'billing-account-name': 'foo',
'apis': [],
'concurrent_api_activation': True,
'service-accounts': []
}
def test_merge_no_iam_policies(self):
"""Test output of the function when there are no IAM policies in the
properties"""
env = {'project_number': '123'}
properties = {}
e | xpected = {
'bindings': [
{
'role': 'roles/owner',
| 'members':
['serviceAccount:123@cloudservices.gserviceaccount.com']
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_merge_with_existing_non_owner_policy(self):
"""Test output of the function when there are existing non owner IAM
policies in the properties"""
env = {'project_number': '123'}
properties = {
'iam-policy': {
'bindings': [
{
'role': 'roles/viewer',
'members': ['user:foobar@barbaz.com']
}
]
}
}
expected = {
'bindings': [
{
'role': 'roles/viewer',
'members': ['user:foobar@barbaz.com']
},
{
'role': 'roles/owner',
'members':
['serviceAccount:123@cloudservices.gserviceaccount.com']
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_merge_with_different_owner_policy(self):
"""Test output of the function when there is an existing but different
owner IAM policy in the properties"""
env = {'project_number': '123'}
properties = {
'iam-policy': {
'bindings': [
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com']
}
]
}
}
expected = {
'bindings': [
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com',
('serviceAccount:123@cloudservices'
'.gserviceaccount.com')]
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_merge_with_same_owner_policy(self):
"""Test output of the function when the exact same policy already exists"""
env = {'project_number': '123'}
properties = {
'iam-policy': {
'bindings': [
{
'role': 'roles/viewer',
'members': ['user:foobar@barbaz.com']
},
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com',
('serviceAccount:123@cloudservices'
'.gserviceaccount.com')]
}
]
}
}
expected = {
'bindings': [
{
'role': 'roles/viewer',
'members': ['user:foobar@barbaz.com']
},
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com',
('serviceAccount:123@cloudservices'
'.gserviceaccount.com')]
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_merge_with_missing_bindings_but_other_key_present(self):
""""Test the function when there are no bindings in the iam policy block
but some other unknown key exists"""
env = {'project_number': '123'}
properties = {
'iam-policy': {
'foobar': {
'strangekey': 1
}
}
}
expected = {
'foobar': {
'strangekey': 1
},
'bindings': [
{
'role': 'roles/owner',
'members': [('serviceAccount:123@cloudservices'
'.gserviceaccount.com')]
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_merge_with_different_owner_policy_and_other_key(self):
"""Test output of the function when there is an existing but different
owner IAM policy in the properties and some unknown key that exists"""
env = {'project_number': '123'}
properties = {
'iam-policy': {
'foobar': {
'strangekey': 1
},
'bindings': [
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com']
}
]
}
}
expected = {
'foobar': {
'strangekey': 1
},
'bindings': [
{
'role': 'roles/owner',
'members': ['user:foobar@barbaz.com',
('serviceAccount:123@cloudservices'
'.gserviceaccount.com')]
}
]
}
actual_iam_policies = (
p.MergeCallingServiceAccountWithOwnerPermissinsIntoBindings(
env, properties))
self.assertEqual(expected, actual_iam_policies)
def test_only_one_of_organizationid_or_parentfolderid(self):
"""Test that we validate that there can be exactly one of organization-id
or parent-folder-id specified"""
properties_oid = {
'organization-id': "12345"
}
properties_folder = {
'parent-folder-id': "12345"
}
properties_both = {
'organization-id': "12345",
'parent-folder-id': "12345"
}
properties_none = {}
self.assertTrue(p.IsProjectParentValid(properties_oid))
self.assertTrue(p.IsProjectParentValid(properties_folder))
self.assertFalse(p.IsProjectParentValid(properties_both))
self.assertFalse(p.IsProjectParentValid(properties_none))
def test_generateconfig_sets_project_parent(self):
"""Test that we set the right values for project parent"""
env = copy.deepcopy(self.default_env)
properties = copy.deepcopy(self.default_properties)
context = Context(env, properties)
resources = p.GenerateConfig(context)['resources']
expected_project_parent = {
'type': 'organization',
'id': "1234"
}
project_resource = [
resource for resource in resources
if resource['type'] == 'cloudresourcemanager.v1.project']
self.assertEquals(
expected_project_parent, project_resource[0]['properties']['parent'])
properties['parent-folder-id'] = "1234"
del properties['organization-id']
context = Context(env, properties)
resources = p.GenerateConfig(context)['resources']
expected_project_parent = {
'type': 'folder',
'id': "1234"
}
project_resource = [
resource for resource in resources
if resource['type'] == 'cloudresourcemanager.v1.project']
self.assertEquals(
expected_project_parent, project_resource[0]['properties']['parent'])
def test_generateconfig_fails_if_both_folder_and_org_present(self):
"""Test that we sys.exit() if both the parents are present"""
env = copy.deepcopy(self.default_env)
properties = copy.deepcopy(self.default_properties)
properties['parent-folder-id'] = "1234"
context = Context(env, properties)
with self.assertRaises(SystemExit) as cm:
p.GenerateConfig(context)
self.assertEqual(cm.exception.code,
('Invalid [organization-id, parent-folder-id], '
'must specify exactly one.'))
def t |
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-22 11:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('WorkflowEngine', '0001_initial'),
('tags', '0013_auto_20180925_1142'),
]
operations = [
migratio | ns.AddField(
model_name='tag',
name='t | ask',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tags', to='WorkflowEngine.ProcessTask'),
),
migrations.AddField(
model_name='tagstructure',
name='structure_unit',
field=models.ForeignKey(limit_choices_to={'structure__is_template': False}, null=True, on_delete=django.db.models.deletion.PROTECT, to='tags.StructureUnit'),
),
]
|
"""Test that sys.modules is used properly by import."""
from .. import util
import sys
from types import MethodType
import unittest
class UseCache:
"""When it comes to sys.modules, import prefers it over anything else.
Once a name has been resolved, sys.modules is checked to see if it contains
the module desired. If so, then it is returned [use cache]. If it is not
found, then the proper steps are taken to perform the import, but
sys.modules is still used to return the imported module (e.g., not what a
loader returns) [from cache on return]. This also applies to imports of
things contained within a package and thus get assigned as an attribute
[from cache to attribute] or pulled in thanks to a fromlist import
[from cache for fromlist]. But if sys.modules contains None then
ImportError is raised [None in cache].
"""
def test_using_cache(self):
# [use cache]
module_to_use = "some module found!"
with util.uncache('some_module'):
sys.modules['some_module'] = module_to_use
module = self.__import__('some_module')
self.assertEqual(id(module_to_use), id(module))
def test_None_in_cache(self):
#[None in cache]
name = 'using_None'
with util.uncache(name):
sys.modules[name] = None
with self.assertRaises(ImportError) as cm:
self.__import__(name)
self.assertEqual(cm.exception.name, name)
(Frozen_UseCache,
Source_UseCache
) = util.test_both(UseCache, __import__=util.__import__)
class ImportlibUseCache(UseCache, unittest.TestCase):
# Pertinent only to PEP 302; exec_module() doesn't return a module.
__import__ = util.__import__['Source']
def create_mock(self, *names, return_=None):
mock = util.mock_modules(*names)
o | riginal_load = mock.load_module
def load_module(self, fullname):
original_load(fullname)
return return_
mock.load_module = MethodType(load_module, mock)
return mock
# __import__ inconsistent between loaders and built-in import when it comes
# to when to use the module in sys.modules and when not to.
def test_using_cache_after_loader(self):
# [from cache on return]
with self.create_mock('module') as mock:
with util.imp | ort_state(meta_path=[mock]):
module = self.__import__('module')
self.assertEqual(id(module), id(sys.modules['module']))
# See test_using_cache_after_loader() for reasoning.
def test_using_cache_for_assigning_to_attribute(self):
# [from cache to attribute]
with self.create_mock('pkg.__init__', 'pkg.module') as importer:
with util.import_state(meta_path=[importer]):
module = self.__import__('pkg.module')
self.assertTrue(hasattr(module, 'module'))
self.assertEqual(id(module.module),
id(sys.modules['pkg.module']))
# See test_using_cache_after_loader() for reasoning.
def test_using_cache_for_fromlist(self):
# [from cache for fromlist]
with self.create_mock('pkg.__init__', 'pkg.module') as importer:
with util.import_state(meta_path=[importer]):
module = self.__import__('pkg', fromlist=['module'])
self.assertTrue(hasattr(module, 'module'))
self.assertEqual(id(module.module),
id(sys.modules['pkg.module']))
if __name__ == '__main__':
unittest.main()
|
from | __future__ import absolute_im | port
from tridiagonal_core import *
|
ic", "beer on", 2, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("switch.test")
assert state.state == STATE_ON
await common.async_turn_off(hass, "switch.test")
mqtt_mock.async_publish.assert_called_once_with(
"command-topic", "beer off", 2, False
)
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
"""Test the controlling state via topic and JSON message."""
assert await async_setup_component(
hass,
switch.DOMAIN,
{
switch.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
"payload_on": "beer on",
"payload_off": "beer off",
"value_template": "{{ value_json.val }}",
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
async_fire_mqtt_message(hass, "state-topic", '{"val":"beer on"}')
state = hass.states.get("switch.test")
assert state.state == STATE_ON
async_fire_mqtt_message(hass, "state-topic", '{"val":"beer off"}')
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
async def test_availability_when_connection_lost(hass, mqtt_mock):
"""Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_availability_without_topic(hass, mqtt_mock):
"""Test availability without defined availability topic."""
await help_test_availability_without_topic(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_default_availability_payload(hass, mqtt_mock):
"""Test availability by default payload with defined topic."""
config = {
switch.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
"payload_on": 1,
"payload_off": 0,
}
}
await help_test_default_availability_payload(
hass, mqtt_mock, switch.DOMAIN, config, True, "state-topic", "1"
)
async def test_custom_availability_payload(hass, mqtt_mock):
"""Test availability by custom payload with defined topic."""
config = {
switch.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
"payload_on": 1,
"payload_off": 0,
}
}
await help_test_custom_availability_payload(
hass, mqtt_mock, switch.DOMAIN, config, True, "state-topic", "1"
)
async def test_custom_state_payload(hass, mqtt_mock):
"""Test the state payload."""
assert await async_setup_component(
hass,
switch.DOMAIN,
{
switch.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
"payload_on": 1,
"payload_off": 0,
"state_on": "HIGH",
"state_off": "LOW",
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
assert not state.attributes.get(ATTR_ASSUMED_STATE)
async_fire_mqtt_message(hass, "state-topic", "HIGH")
state = hass.states.get("switch.test")
assert state.state == STATE_ON
async_fire_mqtt_message(hass, "state-topic", "LOW")
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_setting_blocked_attribute_via_mqtt_json_message(hass, mqtt_mock):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG, MQTT_SWITCH_ATTRIBUTES_BLOCKED
)
async def test_setting_attribute_with_template(hass, mqtt_mock):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict(
hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON(
hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
"""Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr(
hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_unique_id(hass, mqtt_mock):
"""Test unique id option only creates one switch per unique_id."""
config = {
switch.DOMAIN: [
{
"platform": "mqtt",
"name": "Test 1",
"state_topic": "test-topic",
"command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE",
},
{
"platform": "mqtt",
"name": "Test 2",
"state_topic": "test-topic",
"command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE",
},
]
}
await help_test_unique_id(hass, mqtt_mock, switch.DOMAIN, config)
async def test_discovery_removal_switch(hass, mqtt_mock, caplog):
"""Test removal of discovered switch."""
data = (
'{ "name": "test",'
' "state_topic": "test_topic",'
' "command_topic": "test_topic" }'
)
await help_test_discovery_removal(hass, mqtt_mock, caplog, switch.DOMAIN, data)
async def test_discovery_update_switch_topic_template(hass, mqtt_mock, caplog):
"""Test update of discovered switch."""
config1 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN])
| config2 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN])
config1["name"] = "Beer"
config2["name"] = "Milk"
config1["state_topic"] = "switch/st | ate1"
config2["state_topic"] = "switch/state2"
config1["value_template"] = "{{ value_json.state1.state }}"
config2["value_template"] = "{{ value_json.state2.state }}"
state_data1 = [
([("switch/state1", '{"state1":{"state":"ON"}}')], "on", None),
]
state_data2 = [
([("switch/state2", '{"state2":{"state":"OFF"}}')], "off", None),
([("switch/state2", '{"state2":{"state":"ON"}}')], "on", None),
([("switch/state1", '{"state1":{"state":"OFF"}}')], "on", None),
([("switch/state1", '{"state2":{"state":"OFF"}}')], "on", None),
([("switch/state2", '{"state1":{"state":"OFF"}}')], "on", None),
([("switch/state2", '{"state2":{"state":"OFF"}}')], "off", None),
]
await help_test_discovery_update(
hass,
mqtt_mock,
caplog,
switch.DOMAIN,
config1,
config2,
state_data1=state_data1,
state_data2=state_data2,
)
async def test_discovery_update_switch_template(hass, mqtt_mock, caplog):
"""Test update of discovered switch."""
config1 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN])
config1["name"] = "Beer"
config2["name"] = "Milk"
config1["state_topic"] = "switch/state1" |
f group_id:
asset_group_list = asset_group_list.filter(id=group_id)
if keyword:
asset_group_list = asset_group_list.filter(Q(name__contains=keyword) | Q(comment__contains=keyword))
asset_group_list, p, asset_groups, page_range, current_page, show_first, show_end = pages(asset_group_list, request)
return my_render('jasset/group_list.html', locals(), request)
@require_role('admin')
def group_del(request):
"""
Group delete view
删除主机组
"""
group_ids = request.GET.get('id', '')
group_id_list = group_ids.split(',')
for group_id in group_id_list:
AssetGroup.objects.filter(id=group_id).delete()
return HttpResponse(u'删除成功')
@require_role('admin')
def asset_add(request):
"""
Asset add view
添加资产
"""
header_title, path1, path2 = u'添加资产', u'资产管理', u'添加资产'
asset_group_all = AssetGroup.objects.all()
af = AssetForm()
default_setting = get_object(Setting, name='default')
default_port = default_setting.field2 if default_setting else ''
if request.method == 'POST':
af_post = AssetForm(request.POST)
ip = request.POST.get('ip', '')
hostname = request.POST.get('hostname', '')
is_active = True if request.POST.get('is_active') == '1' else False
use_default_auth = request.POST.get('use_default_auth', '')
uuid_r = uuid.uuid4().get_hex()
try:
if Asset.objects.filter(hostname=unicode(hostname)):
error = u'该主机名 %s 已存在!' % hostname
raise ServerError(error)
except ServerError:
pass
else:
if af_post.is_valid():
asset_save = af_post.save(commit=False)
if not use_default_auth:
password = request.POST.get('password', '')
password_encode = CRYPTOR.encrypt(password)
asset_save.password = password_encode
if not ip:
asset_save.ip = hostname
asset_save.is_active = True if is_active else False
asset_save.uuid = uuid_r
asset_save.save()
af_post.save_m2m()
viewer_vnc = os.path.join(KEY_DIR, 'keys', 'viewer.vnc')
if viewer_vnc:
fwrite = file(viewer_vnc, "a+")
context= "%s: %s:5901" % (uuid_r, hostname)
fwrite.write(context)
fwrite.close()
msg = u'主机 %s 添加成功' % hostname
else:
esg = u'主机 %s 添加失败' % hostname
return my_render('jasset/asset_add.html', locals(), request)
@require_role('admin')
def asset_add_batch(request):
header_title, path1, path2 = u'添加资产', u'资产管理', u'批量添加'
return my_render('jasset/asset_ | add_batch.html', locals(), request)
@require_role('admin')
def asset_del(request):
"""
del a asset
删除主机
"""
asset_id = request.GET.get('id', '')
if asset_id:
Asset.objects.filter(id=asset_id).delete()
if request.method == 'POST':
asset_batch = request.GET.get('arg', '')
asset_id_all = str(request.POST.ge | t('asset_id_all', ''))
if asset_batch:
for asset_id in asset_id_all.split(','):
asset = get_object(Asset, id=asset_id)
asset.delete()
return HttpResponse(u'删除成功')
@require_role(role='super')
def asset_edit(request):
"""
edit a asset
修改主机
"""
header_title, path1, path2 = u'修改资产', u'资产管理', u'修改资产'
asset_id = request.GET.get('id', '')
username = request.user.username
asset = get_object(Asset, id=asset_id)
if asset:
password_old = asset.password
# asset_old = copy_model_instance(asset)
af = AssetForm(instance=asset)
if request.method == 'POST':
af_post = AssetForm(request.POST, instance=asset)
ip = request.POST.get('ip', '')
hostname = request.POST.get('hostname', '')
password = request.POST.get('password', '')
is_active = True if request.POST.get('is_active') == '1' else False
use_default_auth = request.POST.get('use_default_auth', '')
try:
asset_test = get_object(Asset, hostname=hostname)
if asset_test and asset_id != unicode(asset_test.id):
emg = u'该主机名 %s 已存在!' % hostname
raise ServerError(emg)
except ServerError:
pass
else:
if af_post.is_valid():
af_save = af_post.save(commit=False)
if use_default_auth:
af_save.username = ''
af_save.password = ''
af_save.port = None
else:
if password:
password_encode = CRYPTOR.encrypt(password)
af_save.password = password_encode
else:
af_save.password = password_old
af_save.is_active = True if is_active else False
af_save.save()
af_post.save_m2m()
# asset_new = get_object(Asset, id=asset_id)
# asset_diff_one(asset_old, asset_new)
info = asset_diff(af_post.__dict__.get('initial'), request.POST)
db_asset_alert(asset, username, info)
smg = u'主机 %s 修改成功' % ip
else:
emg = u'主机 %s 修改失败' % ip
return my_render('jasset/error.html', locals(), request)
return HttpResponseRedirect(reverse('asset_detail')+'?id=%s' % asset_id)
return my_render('jasset/asset_edit.html', locals(), request)
@require_role('user')
def asset_list(request):
"""
asset list view
"""
header_title, path1, path2 = u'查看资产', u'资产管理', u'查看资产'
username = request.user.username
user_perm = request.session['role_id']
idc_all = IDC.objects.filter()
asset_group_all = AssetGroup.objects.all()
asset_types = ASSET_TYPE
asset_status = ASSET_STATUS
idc_name = request.GET.get('idc', '')
group_name = request.GET.get('group', '')
asset_type = request.GET.get('asset_type', '')
status = request.GET.get('status', '')
keyword = request.GET.get('keyword', '')
export = request.GET.get("export", False)
group_id = request.GET.get("group_id", '')
idc_id = request.GET.get("idc_id", '')
asset_id_all = request.GET.getlist("id", '')
if group_id:
group = get_object(AssetGroup, id=group_id)
if group:
asset_find = Asset.objects.filter(group=group)
elif idc_id:
idc = get_object(IDC, id=idc_id)
if idc:
asset_find = Asset.objects.filter(idc=idc)
else:
if user_perm != 0:
asset_find = Asset.objects.all()
else:
asset_id_all = []
user = get_object(User, username=username)
asset_perm = get_group_user_perm(user) if user else {'asset': ''}
user_asset_perm = asset_perm['asset'].keys()
for asset in user_asset_perm:
asset_id_all.append(asset.id)
asset_find = Asset.objects.filter(pk__in=asset_id_all)
asset_group_all = list(asset_perm['asset_group'])
if idc_name:
asset_find = asset_find.filter(idc__name__contains=idc_name)
if group_name:
asset_find = asset_find.filter(group__name__contains=group_name)
if asset_type:
asset_find = asset_find.filter(asset_type__contains=asset_type)
if status:
asset_find = asset_find.filter(status__contains=status)
if keyword:
asset_find = asset_find.filter(
Q(hostname__contains=keyword) |
Q(other_ip__contains=keyword) |
Q(ip__contains=keyword) |
Q(remote_ip__contains=keyword) |
Q(comment__contains=keyword) |
Q(username__contains=keyword) |
Q(group__name__contains=keyword) |
Q(cpu__contains=keyword) |
Q(memory__contains=keyword) |
Q(disk__contains=keyword) |
Q(brand__contains=keyword) |
Q(cabinet__contains=keyword) |
Q(sn__contains=keyword) |
Q(system_type__contains=keyword) | |
#!/usr/bin/env python3
# This script prints a new "servers.json" to stdout.
# It prunes the offline servers from the existing list (note: run with Tor proxy to keep .onions),
# and adds new servers from provided file(s) of candidate servers.
# A file o | f new candidate servers can be created via e.g.:
# $ ./electrum_ltc/scripts/servers.py > reply.txt
import asyncio
import sys
import json
from electrum_ltc.network im | port Network
from electrum_ltc.util import create_and_start_event_loop, log_exceptions
from electrum_ltc.simple_config import SimpleConfig
from electrum_ltc import constants
try:
fname1 = sys.argv[1]
fname2 = sys.argv[2] if len(sys.argv) > 2 else None
except Exception:
print("usage: update_default_servers.py <file1> [<file2>]")
print(" - the file(s) should contain json hostmaps for new servers to be added")
print(" - if two files are provided, their intersection is used (peers found in both).\n"
" file1 should have the newer data.")
sys.exit(1)
def get_newly_added_servers(fname1, fname2=None):
with open(fname1) as f:
res_hostmap = json.loads(f.read())
if fname2 is not None:
with open(fname2) as f:
dict2 = json.loads(f.read())
common_set = set.intersection(set(res_hostmap), set(dict2))
res_hostmap = {k: v for k, v in res_hostmap.items() if k in common_set}
return res_hostmap
# testnet?
#constants.set_testnet()
config = SimpleConfig({'testnet': False})
loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()
@log_exceptions
async def f():
try:
# prune existing servers
old_servers_all = constants.net.DEFAULT_SERVERS
old_servers_online = await network.prune_offline_servers(constants.net.DEFAULT_SERVERS)
# add new servers
newly_added_servers = get_newly_added_servers(fname1, fname2)
res_servers = {**old_servers_online, **newly_added_servers}
print(json.dumps(res_servers, indent=4, sort_keys=True))
print(f"got reply from {len(old_servers_online)}/{len(old_servers_all)} old servers", file=sys.stderr)
print(f"len(newly_added_servers)={len(newly_added_servers)}. total: {len(res_servers)}", file=sys.stderr)
finally:
stopping_fut.set_result(1)
asyncio.run_coroutine_threadsafe(f(), loop)
|
# -*- coding: utf-8 -*-
"""Display download counts of GitHub releases."""
__program__ = 'github-d | ownload-count'
__vers | ion__ = '0.0.1'
__description__ = 'Display download counts of GitHub releases'
|
#!/usr/bin/env python
im | port os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", | "sufwebapp1.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
|
"""HaloEndpoint class"""
import cloudpassage.sanity as sanity
from .utility import Utility as utility
from .http_helper import HttpHelper
class HaloEndpoint(object):
"""Base class inherited by other specific HaloEndpoint classes."""
default_endpoint_version = 1
def __init__(self, session, **kwargs):
self.session = session
self.max_pages = 100
self.set_endpoint_version(kwargs)
def set_endpoint_version(self, kwargs):
"""Validate and set the endpoint version."""
if "endpoint_version" in kwargs:
version = kwargs["endpoint_version"]
if isinstance(version, int):
self.endpoint_version = version
else:
raise TypeError("Bad endpoint version {}".format(version))
else:
self.endpoint_version = self.default_endpoint_version
@classmethod
def endpoint(cls):
"""Not implemented at this level. Raises exception."""
raise NotImplementedError
@classmethod
def pagination_key(cls):
"""Not implemented at this level. Raises exception."""
raise NotImplementedError
@classmethod
def object_key(cls):
"""Not implemented at this level. Raises exception."""
raise NotImplementedError
def list_all(self, **kwargs):
"""Lists all objects of this type.
Returns:
list: List of objects (represented as dictionary-type objects)
Note:
This method supports query parameters via keyword arguments.
"""
request = HttpHelper(self.session)
params = utility.sanitize_url_params(kwargs)
response = request.get_paginated(self.endpoint(),
self.pagination_key(), self.max_pages,
params=params)
return response
def describe(self, object_id):
"""Get the detailed configuration by ID
Args:
object_id (str): ID to retrieve detailed configuration information
for
Returns:
dict: dictionary object representing the entire object.
"""
request = HttpHelper(self.session)
describe_endpoint = "%s/%s" % (self.endpoint(), object_id)
return request.get(describe_endpoint)[self.object_key()]
def create(self, object_body):
"""Create from JSON document.
Returns the ID of the new object
"""
request = HttpHelper(self.session)
request_body = utility.policy_to_dict(object_body)
return request.post(self.endpoint(),
request_body)[self.object_key()]["id"]
def delete(self, object_id):
"""Delete by ID. Success returns None"""
sanity.validate_object_id(object_id)
reques | t = HttpHelper(self.session)
delete_endpoint = "%s/%s" % (self.endpoint(), obje | ct_id)
request.delete(delete_endpoint)
return None
def update(self, object_body):
"""Update. Success returns None"""
request = HttpHelper(self.session)
request_body = utility.policy_to_dict(object_body)
object_id = request_body[self.object_key()]["id"]
sanity.validate_object_id(object_id)
update_endpoint = "%s/%s" % (self.endpoint(), object_id)
request.put(update_endpoint, request_body)
return None
|
# -*- coding: utf | -8 -*-
"""
fudcon.ui.backend
------
fudcon ui back | end application package
"""
|
# -*- coding: utf-8 -*-
#
# amsn - a python client for the WLM Network
#
# Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful | ,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from amsn2.ui import base
from PyQt4 import Qt
from PyQt4 import QtCore
from PyQt4 | import QtGui
from fadingwidget import FadingWidget
from image import Image
class aMSNSplashScreen(QtGui.QSplashScreen, base.aMSNSplashScreen):
def __init__(self, amsn_core, parent):
QtGui.QSplashScreen.__init__(self, parent)
self._theme_manager = amsn_core._theme_manager
def show(self):
self.setVisible(True)
QtGui.qApp.processEvents()
def hide(self):
self.setVisible(False)
QtGui.qApp.processEvents()
def set_text(self, text):
self.showMessage(text)
QtGui.qApp.processEvents()
def set_image(self, image):
img = Image(self._theme_manager, image)
self.setPixmap(img)
QtGui.qApp.processEvents()
|
## | begin license ##
#
# "Weightless" is a High Performance Asynchronous Networking Library. See http://weightless.io
#
# Copyright (C) 2012-2013, 2017, 2020-2021 Seecr (Seek You Too B.V.) https://seecr.nl
#
# This file is part of "Weightless"
#
# "Weightless" is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either versi | on 2 of the License, or
# (at your option) any later version.
#
# "Weightless" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with "Weightless"; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
## end license ##
import sys
from contextlib import contextmanager
from functools import wraps
from io import StringIO
def _set_replaced_stream(name, replacement=None):
stream = getattr(sys, name)
def andBackAgain():
setattr(sys, name, stream)
streamReplacement = StringIO() if replacement is None else replacement
setattr(sys, name, streamReplacement)
return streamReplacement, andBackAgain
class _ContextMngrOrDecorated(object):
def __init__(self, streamName, replacement=None):
self._streamName = streamName
self._replacement = replacement
def __call__(self, func):
@wraps(func)
def wrapper(*args, **kwargs):
with self:
return func(*args, **kwargs)
return wrapper
def __enter__(self):
mockStream, self._back = _set_replaced_stream(self._streamName, self._replacement)
return mockStream
def __exit__(self, exc_type, exc_value, traceback):
self._back()
return False
def stderr_replaced(*func_arg):
if func_arg:
return _ContextMngrOrDecorated(streamName='stderr')(*func_arg)
return _ContextMngrOrDecorated(streamName='stderr')
def stdout_replaced(*func_arg):
if func_arg:
return _ContextMngrOrDecorated(streamName='stdout')(*func_arg)
return _ContextMngrOrDecorated(streamName='stdout')
def stdin_replaced(inStream=None):
return _ContextMngrOrDecorated(streamName='stdin', replacement=inStream)
|
# __init__.py
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Michael Bayer mike_mp@zzzcomputing.com
|
#
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
__version__ = | '0.3.4'
|
import fechbase
class Records(fechbase.RecordsBase):
def __init__(self):
fechbase.RecordsBase.__init__(self)
self.fields = [
{'name': 'FORM TYPE', 'number': '1'},
{'name': 'FILER FEC CMTE ID', 'number' | : '2'},
{'name': 'ENTITY TYPE', 'number': '3'},
{'name': 'NAME (Payee)', 'number': '4'},
{'name': 'STREET 1', 'number': '5'},
{'name': 'STREET 2', 'numb | er': '6'},
{'name': 'CITY', 'number': '7'},
{'name': 'STATE', 'number': '8'},
{'name': 'ZIP', 'number': '9'},
{'name': 'TRANSDESC', 'number': '10'},
{'name': 'Of Expenditure', 'number': '11-'},
{'name': 'AMOUNT', 'number': '12'},
{'name': 'SUPPORT/OPPOSE', 'number': '13'},
{'name': 'S/O FEC CAN ID NUMBER', 'number': '14'},
{'name': 'S/O CAN/NAME', 'number': '15'},
{'name': 'S/O CAN/OFFICE', 'number': '16'},
{'name': 'S/O CAN/STATE', 'number': '17'},
{'name': 'S/O CAN/DIST', 'number': '18'},
{'name': 'FEC COMMITTEE ID NUMBER', 'number': '19'},
{'name': 'Unused field', 'number': '20'},
{'name': 'Unused field', 'number': '21'},
{'name': 'Unused field', 'number': '22'},
{'name': 'Unused field', 'number': '23'},
{'name': 'Unused field', 'number': '24'},
{'name': 'CONDUIT NAME', 'number': '25'},
{'name': 'CONDUIT STREET 1', 'number': '26'},
{'name': 'CONDUIT STREET 2', 'number': '27'},
{'name': 'CONDUIT CITY', 'number': '28'},
{'name': 'CONDUIT STATE', 'number': '29'},
{'name': 'CONDUIT ZIP', 'number': '30'},
{'name': 'AMENDED CD', 'number': '31'},
{'name': 'TRAN ID', 'number': '32'},
]
self.fields_names = self.hash_names(self.fields)
|
import contextvars
import gettext
import os
from telebot.asyncio_handler_backends import BaseMiddleware
try:
from babel.support import LazyProxy
babel_imported = True
except ImportError:
babel_imported = False
class I18N(BaseMiddleware):
"""
This middleware provides high-level tool for internationalization
It is based on gettext util.
"""
context_lang = contextvars.ContextVar('language', default=None)
def __init__(self, translations_path, domain_name: str):
super().__init__()
self.update_types = self.process_update_types()
self.path = translations_path
self.domain = domain_name
self.translations = self.find_translations()
@property
def available_translations(self):
return list(self.translations)
def gettext(self, text: str, lang: str = None):
"""
Singular translations
"""
if lang is None:
lang = self.context_lang.get()
if lang not in self.translations:
return text
translator = self.translations[lang]
return translator.gettext(text)
def ngettext(self, singular: str, plural: str, lang: str = None, n=1):
"""
| Plural translations
"""
if lang is None:
lang = sel | f.context_lang.get()
if lang not in self.translations:
if n == 1:
return singular
return plural
translator = self.translations[lang]
return translator.ngettext(singular, plural, n)
def lazy_gettext(self, text: str, lang: str = None):
if not babel_imported:
raise RuntimeError('babel module is not imported. Check that you installed it.')
return LazyProxy(self.gettext, text, lang, enable_cache=False)
def lazy_ngettext(self, singular: str, plural: str, lang: str = None, n=1):
if not babel_imported:
raise RuntimeError('babel module is not imported. Check that you installed it.')
return LazyProxy(self.ngettext, singular, plural, lang, n, enable_cache=False)
async def get_user_language(self, obj):
"""
You need to override this method and return user language
"""
raise NotImplementedError
def process_update_types(self) -> list:
"""
You need to override this method and return any update types which you want to be processed
"""
raise NotImplementedError
async def pre_process(self, message, data):
"""
context language variable will be set each time when update from 'process_update_types' comes
value is the result of 'get_user_language' method
"""
self.context_lang.set(await self.get_user_language(obj=message))
async def post_process(self, message, data, exception):
pass
def find_translations(self):
"""
Looks for translations with passed 'domain' in passed 'path'
"""
if not os.path.exists(self.path):
raise RuntimeError(f"Translations directory by path: {self.path!r} was not found")
result = {}
for name in os.listdir(self.path):
translations_path = os.path.join(self.path, name, 'LC_MESSAGES')
if not os.path.isdir(translations_path):
continue
po_file = os.path.join(translations_path, self.domain + '.po')
mo_file = po_file[:-2] + 'mo'
if os.path.isfile(po_file) and not os.path.isfile(mo_file):
raise FileNotFoundError(f"Translations for: {name!r} were not compiled!")
with open(mo_file, 'rb') as file:
result[name] = gettext.GNUTranslations(file)
return result
|
tecture}/{project.targetName}")
csbuild.SetIntermediateDirectory("Intermediate/{project.userData.subdir}/{project.activeToolchainName}/{project.outputArchitecture}/{project.targetName}/{project.name}")
csbuild.Toolchain("msvc").AddCompilerFlags(
"/fp:fast",
"/wd\"4530\"",
"/wd\"4067\"",
"/wd\"4351\"",
"/constexpr:steps1000000",
)
if not csbuild.GetOption("no_threads"):
csbuild.Toolchain("gcc", "ios", "android").AddCompilerFlags("-pthread")
if csbuild.GetOption("no_exceptions"):
csbuild.Toolchain("gcc", "ios", "android").AddCompilerFlags("-fno-exceptions")
else:
csbuild.Toolchain("msvc").AddCompilerFlags("/EHsc")
@csbuild.projec | t("collections", "collections")
def collections():
csbuild.SetOutput("libsprawl_collections", csbuild.ProjectType.StaticLibrary)
csbuild.EnableHeaderInstall()
@csbuild.project("tag", "tag")
def collections():
csbuild.SetOutput("libsprawl_tag", csbuild.ProjectType.StaticLibrary)
csbuild.EnableHeaderInstall()
@csbuild.project("if", "if")
def collections():
csbuild.SetOutput("libsprawl_if", csbuild.ProjectType.StaticLibrary)
csbuild.EnableHeaderInstall()
@csbuild.proje | ct("network", "network")
def network():
csbuild.SetOutput("libsprawl_network", csbuild.ProjectType.StaticLibrary)
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("serialization", "serialization")
def serialization():
csbuild.SetOutput("libsprawl_serialization", csbuild.ProjectType.StaticLibrary)
csbuild.AddExcludeDirectories("serialization/mongo")
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("time", "time")
def timeProject():
csbuild.SetOutput("libsprawl_time", csbuild.ProjectType.StaticLibrary)
csbuild.Toolchain("gcc").AddExcludeFiles("time/*_windows.cpp")
if platform.system() == "Darwin":
csbuild.Toolchain("gcc").AddExcludeFiles("time/*_linux.cpp")
else:
csbuild.Toolchain("gcc").AddExcludeFiles("time/*_osx.cpp")
csbuild.Toolchain("msvc").AddExcludeFiles("time/*_linux.cpp", "time/*_osx.cpp")
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("filesystem", "filesystem")
def filesystem():
csbuild.SetOutput("libsprawl_filesystem", csbuild.ProjectType.StaticLibrary)
csbuild.Toolchain("gcc").AddExcludeFiles("filesystem/*_windows.cpp")
csbuild.Toolchain("msvc").AddExcludeFiles("filesystem/*_linux.cpp")
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("threading", "threading")
def threading():
csbuild.SetOutput("libsprawl_threading", csbuild.ProjectType.StaticLibrary)
if platform.system() != "Darwin":
@csbuild.scope(csbuild.ScopeDef.Final)
def finalScope():
csbuild.Toolchain("gcc").Linker().AddLinkerFlags("-pthread")
csbuild.Toolchain("gcc").AddExcludeFiles("threading/*_windows.cpp")
if platform.system() == "Darwin":
csbuild.Toolchain("gcc").AddExcludeFiles("threading/event_linux.cpp")
else:
csbuild.Toolchain("gcc").AddExcludeFiles("threading/event_osx.cpp")
csbuild.Toolchain("msvc").AddExcludeFiles(
"threading/*_linux.cpp",
"threading/*_osx.cpp"
)
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
MongoDir = csbuild.GetOption("with_mongo")
BoostDir = csbuild.GetOption("with_boost")
if (not MongoDir) ^ (not BoostDir):
log.LOG_ERROR("Both mongo and boost directories must be specified to build MongoSerializer.");
csbuild.Exit(1)
if MongoDir and BoostDir:
MongoDir = os.path.abspath(MongoDir)
BoostDir = os.path.abspath(BoostDir)
@csbuild.project("serialization-mongo", "serialization/mongo")
def serialization():
csbuild.SetOutput("libsprawl_serialization-mongo", csbuild.ProjectType.StaticLibrary)
csbuild.AddDefines("BOOST_ALL_NO_LIB")
csbuild.AddIncludeDirectories(
"./serialization",
os.path.join(MongoDir, "include"),
os.path.join(BoostDir, "include")
)
csbuild.AddLibraryDirectories(
os.path.join(MongoDir, "lib"),
os.path.join(BoostDir, "lib")
)
csbuild.SetHeaderInstallSubdirectory("sprawl/serialization")
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("memory", "memory")
def memory():
csbuild.SetOutput("libsprawl_memory", csbuild.ProjectType.StaticLibrary)
csbuild.EnableHeaderInstall()
@csbuild.project("string", "string")
def string():
csbuild.SetOutput("libsprawl_string", csbuild.ProjectType.StaticLibrary)
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("hash", "hash")
def hash():
csbuild.SetOutput("libsprawl_hash", csbuild.ProjectType.StaticLibrary)
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("logging", "logging")
def logging():
csbuild.SetOutput("libsprawl_logging", csbuild.ProjectType.StaticLibrary)
@csbuild.scope(csbuild.ScopeDef.Final)
def finalScope():
if platform.system() != "Darwin":
csbuild.Toolchain("gcc").AddLibraries(
"bfd",
)
csbuild.Toolchain("msvc").AddLibraries(
"DbgHelp"
)
csbuild.Toolchain("gcc").AddExcludeFiles("logging/*_windows.cpp")
if platform.system() == "Darwin":
csbuild.Toolchain("gcc").AddExcludeFiles("logging/*_linux.cpp")
else:
csbuild.Toolchain("gcc").AddExcludeFiles("logging/*_osx.cpp")
csbuild.Toolchain("msvc").AddExcludeFiles(
"logging/*_linux.cpp",
"logging/*_osx.cpp"
)
csbuild.EnableOutputInstall()
csbuild.EnableHeaderInstall()
@csbuild.project("common", "common")
def common():
csbuild.SetOutput("libsprawl_common", csbuild.ProjectType.StaticLibrary)
csbuild.EnableHeaderInstall()
UnitTestDepends = ["serialization", "string", "hash", "time", "threading", "filesystem", "logging"]
if MongoDir:
UnitTestDepends.append("serialization-mongo")
@csbuild.project("UnitTests", "UnitTests", UnitTestDepends)
def UnitTests():
csbuild.DisableChunkedBuild()
csbuild.SetOutput("SprawlUnitTest")
csbuild.SetOutputDirectory("bin/{project.userData.subdir}/{project.activeToolchainName}/{project.outputArchitecture}/{project.targetName}")
csbuild.EnableOutputInstall()
csbuild.AddIncludeDirectories(
"UnitTests/gtest",
"UnitTests/gtest/include",
)
csbuild.Toolchain("gcc").Compiler().AddWarnFlags("no-undef", "no-switch-enum", "no-missing-field-initializers")
csbuild.AddExcludeFiles(
"UnitTests/gtest/src/gtest-death-test.cc",
"UnitTests/gtest/src/gtest-filepath.cc",
"UnitTests/gtest/src/gtest-internal-inl.h",
"UnitTests/gtest/src/gtest-port.cc",
"UnitTests/gtest/src/gtest-printers.cc",
"UnitTests/gtest/src/gtest-test-part.cc",
"UnitTests/gtest/src/gtest-typed-test.cc",
"UnitTests/gtest/src/gtest.cc",
)
if MongoDir:
csbuild.AddIncludeDirectories(
"./serialization",
os.path.join(MongoDir, "include"),
os.path.join(BoostDir, "include")
)
csbuild.AddLibraryDirectories(
os.path.join(MongoDir, "lib"),
os.path.join(BoostDir, "lib")
)
csbuild.AddLibraries(
"mongoclient",
"boost_filesystem",
"boost_system",
"boost_thread",
"boost_program_options",
"ssl",
"crypto",
)
csbuild.Toolchain("gcc").AddLibraries("pthread")
csbuild.Toolchain("gcc").AddCompilerFlags("-pthread")
csbuild.AddDefines("WITH_MONGO")
else:
csbuild.AddExcludeFiles(
"UnitTests/UnitTests_MongoReplicable.cpp",
)
@csbuild.project("QueueTests", "QueueTests", ["time", "threading"])
def UnitTests():
csbuild.DisableChunkedBuild()
csbuild.SetOutput("QueueTests")
csbuild.SetOutputDirectory("bin/{project.userData.subdir}/{project.activeToolchainName}/{project.outputArchitecture}/{project.targetName}")
csbuild.EnableOutputInstall()
csbuild.Toolchain("gcc").Compiler().AddWarnFlags("no-undef", "no-switch-enum", "no-missing-field-initializers")
csbuild.AddIncludeDirectories("QueueTests/ext/include")
csbuild.AddLibraryDirectories("QueueTests/ext/lib/{project.userData.subdir}-{project.outputArchitecture}")
csbuild.AddExcludeDirectories("QueueTests/ext")
csbuild.AddLibraries("tbb")
if platform.system() == "Windows":
@csbuild.postMakeStep
def postMake(project):
for f in glob.glob("QueueTests/ext/lib/{project.userData.subdir}-{project.outputArchitecture}/*".format(project=project)):
basename = os.path.basename(f)
dest = os.path.join(project.outputDir, ba |
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provide a simple /version handler."""
import handlers
import handlers.base as hbase
import handlers.response as hresponse
import models
# pylint: disable=too-many-public-methods
class | VersionHandler(hbase.BaseHandler):
"""Handle request to the /version URL.
Provide the backend version number in use. |
"""
def __init__(self, application, request, **kwargs):
super(VersionHandler, self).__init__(application, request, **kwargs)
def execute_get(self, *args, **kwargs):
response = hresponse.HandlerResponse()
response.result = [
{
models.VERSION_FULL_KEY: handlers.__versionfull__,
models.VERSION_KEY: handlers.__version__,
}
]
return response
def execute_post(self, *args, **kwargs):
return hresponse.HandlerResponse(501)
def execute_delete(self, *args, **kwargs):
return hresponse.HandlerResponse(501)
|
# -*- coding: utf-8 -*-
#
# This file is part of EventGhost.
# Copyright © 2005-2019 EventGhost Project <http://www.eventghost.org/>
#
# EventGhost is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 2 of the License, or (at your option)
# any later version.
#
# EventGhost is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with EventGhost. If not, see <http://www.gnu.org/licenses/>.
import sys
import wx
from ctypes import windll
from time import gmtime
from types import ModuleType
from os import listdir, makedirs, chdir
from os.path import join, basename, isdir, exists, splitext
# Local imports
import eg
def DeInit():
eg.PrintDebugNotice("stopping threads")
eg.actionThread.Func(eg.actionThread.StopSession)()
eg.scheduler.Stop()
eg.actionThread.Stop()
eg.eventThread.Stop()
eg.socketSever.Stop()
eg.PrintDebugNotice("shutting down")
eg.config.Save()
eg.messageReceiver.Stop()
if eg.dummyAsyncoreDispatcher:
eg.dummyAsyncoreDispatcher.close()
def ImportAll():
def Traverse(root, moduleRoot):
for name in listdir(root):
path = join(root, name)
if isdir(path):
name = basename(path)
if name in [".svn", ".git", ".idea"]:
continue
if not exists(join(path, "__init__.py")):
continue
moduleName = moduleRoot + "." + name
#print moduleName
__import__(moduleName)
Traverse(path, moduleName)
continue
base, ext = splitext(name)
if ext != ".py":
continue
if base == "__init__":
continue
moduleName = moduleRoot + "." + base
if moduleName in (
"eg.StaticImports",
"eg.CorePluginModule.EventGhost.OsdSkins.Default",
):
continue
#print moduleName
__import__(moduleName)
Traverse(join(eg.mainDir, "eg"), "eg")
Traverse(eg.corePluginDir, "eg.CorePluginModule")
def Init():
import WinApi.pywin32_patches # NOQA
import WinApi.wx_patches # NOQA
import WinApi.GenPaths # NOQA
def InitGui():
import __builtin__
__builtin__.raw_input = RawInput
__builtin__.input = Input
eg.scheduler.start()
eg.messageReceiver.Start()
eg.document = eg.Document()
if eg.config.showTrayIcon:
if not (eg.config.hideOnStartup or eg.startupArguments.hideOnStartup):
eg.document.ShowFrame()
else:
eg.document.ShowFrame()
if eg.config.hideOnStartup or eg.startupArguments.hideOnStartup:
eg.mainFrame.Iconize(True)
eg.actionThread.Start()
eg.eventThread.startupEvent = eg.startupArguments.startupEvent
config = eg.config
startupFile = eg.startupArguments.startupFile
if startupFile is None:
startupFile = config.autoloadFilePath
if startupFile and not exists(startupFile):
eg.PrintError(eg.text.Error.FileNotFound % startupFile)
startupFile = None
eg.eventThread.Start()
wx.CallAfter(
eg.eventThread.Call,
eg.eventThread.StartSession,
startupFile
)
if config.checkUpdate:
# avoid more than one check per day
| today = gmtime()[:3]
if config.lastUpdateCheckDate != today:
config. | lastUpdateCheckDate = today
wx.CallAfter(eg.CheckUpdate.Start)
# Register restart handler for easy crash recovery.
if eg.WindowsVersion >= 'Vista':
args = " ".join(eg.app.GetArguments())
windll.kernel32.RegisterApplicationRestart(args, 8)
eg.Print(eg.text.MainFrame.Logger.welcomeText)
import LoopbackSocket
eg.socketSever = LoopbackSocket.Start()
def InitPathsAndBuiltins():
import cFunctions
import __builtin__
eg.folderPath = eg.FolderPath()
eg.mainDir = eg.folderPath.mainDir
eg.configDir = eg.folderPath.configDir
eg.corePluginDir = eg.folderPath.corePluginDir
eg.localPluginDir = eg.folderPath.localPluginDir
eg.imagesDir = eg.folderPath.imagesDir
eg.languagesDir = eg.folderPath.languagesDir
eg.sitePackagesDir = eg.folderPath.sitePackagesDir
if not exists(eg.configDir):
try:
makedirs(eg.configDir)
except:
pass
if not exists(eg.localPluginDir):
try:
makedirs(eg.localPluginDir)
except:
eg.localPluginDir = eg.corePluginDir
if eg.Cli.args.isMain:
if exists(eg.configDir):
chdir(eg.configDir)
else:
chdir(eg.mainDir)
__builtin__.wx = wx
corePluginPackage = ModuleType("eg.CorePluginModule")
corePluginPackage.__path__ = [eg.corePluginDir]
userPluginPackage = ModuleType("eg.UserPluginModule")
userPluginPackage.__path__ = [eg.localPluginDir]
sys.modules["eg.CorePluginModule"] = corePluginPackage
sys.modules["eg.UserPluginModule"] = userPluginPackage
sys.modules['eg.cFunctions'] = cFunctions
eg.pluginDirs = [eg.corePluginDir, eg.localPluginDir]
eg.cFunctions = cFunctions
eg.CorePluginModule = corePluginPackage
eg.UserPluginModule = userPluginPackage
def InitPil():
"""
Initialize PIL's Image module.
"""
import PIL.Image
import PIL.PngImagePlugin
import PIL.JpegImagePlugin
import PIL.BmpImagePlugin
import PIL.GifImagePlugin
PIL.Image._initialized = 2
# replace builtin input() with a small dialog
def Input(prompt=None):
return eval(eg.SimpleInputDialog.RawInput(prompt))
# replace builtin raw_input() with a small dialog
def RawInput(prompt=None):
return eg.SimpleInputDialog.RawInput(prompt)
|
"""empty message
Revision ID: 0038 add topics to magazines
Revises: 0037 add magazine_id to emails
Create Date: 2020-02-05 01:29:38.265454
"""
# revision identifiers, used by Alembic.
revision = '0038 add topic | s to magazines'
down_revision = '0037 add magazine_id to emails'
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('magazines', sa.Column('topics', sa.String(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('magazines', | 'topics')
# ### end Alembic commands ###
|
# -*- coding: utf-8 -*-
from GestureAgentsTUIO.Tuio import TuioCursorEvents
from GestureAgentsDemo.Geometry import Ring, Circle
from GestureAgentsDemo.Render import drawBatch
from GestureAgents.Recognizer import Recognizer
import pyglet.clock
from pyglet.sprite import Sprite
from pyglet.resource import Loader
from GestureAgents.AppRecognizer import AppRecognizer
from weakref import WeakKeyDictionary
from math import sin, cos, pi
from unipath import Path
def notifier(fnotified, function):
def notifierfunction(*args, **kwargs):
function(*args, **kwargs)
fnotified(*args, **kwargs)
return notifierfunction
rcolors = {
'RecognizerZoomRotate' : (0, 255, 0),
'RecognizerMove' : (0, 0, 255)
}
ICONPATH = Path(Path(__file__).parent, "icons")
loader = Loader([ICONPATH])
class customSprite(object):
def __init__(self, image):
self.image = image
def getCentered(self, pos):
self.image.x, self.image.y = pos
def updateDisplay(self):
pass
def create_recognizer_icon(r, group):
# print Path(ICONPATH, r + ".png")
if Path(ICONPATH, r + ".png").exists():
t = loader.image(r + ".png")
sprite = Sprite(t, batch=drawBatch, group=group)
sprite.scale = 0.25
return customSprite(sprite)
else:
color = rcolors.get(r, (255, 255, 255))
return Circle(5, 20, group=group, color=color)
class FingerFollower(object):
DebugApp = True
def __init__(self, agent, group=None):
self.agent = agent
self.ring = None
self.dead = False
self.group = group
self.agent.newCursor.register(FingerFollower.newCursor, self)
self.agent.updateCursor.register(FingerFollower.updateCursor, self)
self.agent.removeCursor.register(FingerFollower.removeCursor, self)
self.agent.finishAgent.register(FingerFollower.finishAgent, self)
self.recognizersymbols = WeakKeyDictionary()
def pos(self):
return self.agent.pos
def newCursor(self, a):
self.updateCursor(a)
def updateCursor(self, a):
if not self.ring:
self.ring = Ring(10, 4, 20, group=self.group, color=(255, 0, 0))
self.ring.getCentered(self.pos())
self.ring.updateDisplay()
cx, cy = self.pos()
for n, c in enumerate(self.recognizersymbols.values()):
x = cx + 20 * cos(n * pi / 5)
y = cy + 20 * sin(n * pi / 5)
c.getCentered((x, y))
c.updateDisplay()
def removeCursor(self, a):
self.ring = None
def finishAgent(self, a):
self.dead = True
self.agent.newCursor.unregister(self)
self.agent.updateCursor.unregister(self)
self.agent.removeCursor.unregister(self)
self.agent.finishAgent.unregister(self)
def update(self, dt=0):
actuals = set(apprecognizers_subscribed(self.agent))
anteriors = set(self.recognizersymbols)
pending = actuals - anteriors
for r in pending:
name = r.original_recognizer.__name__
self.recognizersymbols[r] = create_recognizer_icon(name, self.group)
if pending:
self.updateCursor(None)
class FingerShadow(object):
DebugApp = True
def __init__(self, system, group=None):
self.group = group
TuioCursorEvents.newAgent.reg | ister(FingerShadow.newAgentCursor, self)
self.curshadows = WeakKeyDictionary()
# Update.register(FingerShadow.update, self)
pyglet.clock.schedule_interval(self.update, .1)
# self.apprecognizerlist = WeakSet()
# AppRecognizer.acquire = notifier(self.NewAppRecognizer, AppRecognizer.acquire)
def newAgentCursor(self, A):
if A not in self.curshadows:
ff = FingerFollower(A, group=self.group)
| self.curshadows[A] = ff
def update(self, dt=0):
for a in list(self.curshadows.itervalues()):
if a.dead:
del self.curshadows[a.agent]
else:
a.update()
# print len(self.apprecognizerlist)
def NewAppRecognizer(self, *args, **kwargs):
print args[0]
def recognizers_subscribed(agent):
recognizers = set()
for event in agent.events.values():
recognizers = recognizers.union(event.lookupf.keys())
return recognizers
def apprecognizers_subscribed(agent, a_process=None):
if a_process is None:
a_process = set()
for r in recognizers_subscribed(agent):
if not isinstance(r, Recognizer):
continue
if r.failed:
continue
if type(r) is AppRecognizer:
yield r
else:
agent = r.agent
if agent not in a_process:
a_process.add(agent)
for rr in apprecognizers_subscribed(agent, a_process):
yield rr
def getSourceAgents(recog):
pendent = [recog]
for r in pendent:
try:
for a in recog.get_agents_acquired_or_confirmed():
if TuioCursorEvents in a.owners:
yield a
pendent.extend(a.owners)
except AttributeError:
pass
|
SEC | ONDS_IN | _DAY = 86400
|
models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
initialTemperature = models.FloatField(blank=False,validators=[MinValueValidator(0)])
finalTemperature = models.FloatField(blank=False,validators=[MinValueValidator(0)])
#class Meta:
#unique_together = ("initialTemperature","finalTemperature")
def __unicode__(self):
return "id: %s" % (self.uuid, )
class chemotaxisTimet0tot1Type_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
#Add a type selector if an experiment type of this is added
#Add a foreign key to the defined experiment model
#class Meta:
#unique_together = ()
def __unicode__(self):
return "id: %s" % (self.uuid )
class galvanotaxisTimet0tot1Type_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
description = models.TextField(max_length=1000, blank=True, default='')
ELECTRICSHOCK = 'ES'
GALVANOTAXISOPTIONS = (
(ELECTRICSHOCK,"Electric shocks"),
)
galvanotaxisType = models.CharField(max_length=60, blank=False,choices=GALVANOTAXISOPTIONS, default=ELECTRICSHOCK)
electricShockConf = models.ForeignKey("electricShockType_model", blank=True, null=True)
def __unicode__(self):
return "id: %s" % (self.uuid )
class phototaxisTimet0tot1Type_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
description = models.TextField(max_length=1000, blank=True)
POINTSOURCELIGHT = 'PSL'
PHOTOTAXISOPTIONS = (
(POINTSOURCELIGHT,"pointsourcelight"),
)
phototaxisType = models.CharField(max_length=60, blank=False,choices=PHOTOTAXISOPTIONS, default=POINTSOURCELIGHT)
pointSourceLightConf = models.ForeignKey("pointSourceLightType_model", blank=True, null=True)
#class Meta:
#unique_together = ()
def __unicode__(self):
return "id: %s" % (self.uuid, )
# Experiment wide experiment type
class experimentWideConfType_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
description = models.TextField(max_length=1000, blank=True, default='No description provided')
MECHANOSENSATION ='MS'
CHEMOTAXIS = 'CT'
TERMOTAXIS = 'TT'
GALVANOTAXIS = 'GT'
PHOTOTAXIS = 'PT'
EXPERIMENTCATEGORY = (
(MECHANOSENSATION,"mechanosensation"),
(CHEMOTAXIS,"chemotaxis"),
(TERMOTAXIS,"termotaxis"),
(GALVANOTAXIS,"galvanotaxis"),
(PHOTOTAXIS,"phototaxis"),
)
experimentCategory = models.CharField(max_length=60, blank=False,choices=EXPERIMENTCATEGORY, default=MECHANOSENSATION)
#GE: Revise to force the user to fill one of the followings
mechanosensation = models.ForeignKey("mechanosensationExpWideType_model", blank=True, null=True)
chemotaxis = models.ForeignKey("chemotaxisExperimentWideType_model", blank=True, null=True)
termotaxis = models.ForeignKey("termotaxisExperimentWideType_model", blank=True, null=True)
galvanotaxis = models.ForeignKey("galvanotaxisExperimentWideType_model", blank=True, null=True)
phototaxis = models.ForeignKey("phototaxisExperimentWideType_model", blank=True, null=True)
#class Meta:
#unique_together = ("mechanosensation","chemotaxis","termotaxis","galvanotaxis","phototaxis")
def __unicode__(self):
return "id: %s" % (self.uuid, )
class mechanosensationExpWideType_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
#Add a type selector if an experiment type of this is added
#Add a foreign key to the defined experiment model
#class Meta:
#unique_together = ()
def __unicode__(self):
return "id: %s" % (self.uuid, )
class termotaxisExperimentWideType_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
description = models.TextField(max_length=1000, blank=True)
LINEARTHERMALGRADIENT = 'LT'
TERMOTAXIS = (
(LINEARTHERMALGRADIENT,"linearThermalGradient"),
)
termotaxisType = models.CharField(max_length=60, blank=False,choices=TERMOTAXIS, default=LINEARTHERMALGRADIENT)
| linearThermalGradient = models.ForeignKey("linearThermalGradientType_model",blank=True, null=True)
#class Meta:
#unique_together = ()
def __unicode__(self):
return "id: %s" % (self.uuid, )
class linearThermalGradientType_model(models.Model):
uuid = mo | dels.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
temperatureRightHorizonal = models.FloatField(blank=False)
temperatureLeftHorizontal = models.FloatField(blank=False)
#class Meta:
#unique_together = ("temperatureRightHorizonal","temperatureLeftHorizontal")
def __unicode__(self):
return "id: %s" % (self.uuid, )
class chemotaxisExperimentWideType_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
description = models.TextField(max_length=1000, blank=True)
STATICPOINTSOURCE = 'SPS'
CHEMICALQUADRANTS1 = 'CQ1'
CHEMICALQUADRANTS2 = 'CQ2'
CHEMICALQUADRANTS4 = 'CQ4'
OSMOTICRING = 'OR'
CHEMICALCATEGORY = (
(STATICPOINTSOURCE,"Static point source"),
(CHEMICALQUADRANTS1,"chemicalquadrants1"),
(CHEMICALQUADRANTS2,"chemicalquadrants2"),
(CHEMICALQUADRANTS4,"chemicalquadrants4"),
(OSMOTICRING,"osmoticring"),
)
chemicalCategory = models.CharField(max_length=60, blank=False,choices=CHEMICALCATEGORY, default=CHEMICALQUADRANTS1)
staticPointSourceConf = models.ForeignKey("staticPointSourceType_model", blank=True, null=True)
chemotaxisQuadrants1 = models.ForeignKey("chemotaxisQuadrantsType_1_model", blank=True, null=True)
chemotaxisQuadrants2 = models.ForeignKey("chemotaxisQuadrantsType_2_model", blank=True, null=True)
chemotaxisQuadrants4 = models.ForeignKey("chemotaxisQuadrantsType_4_model", blank=True, null=True)
osmoticRing = models.ForeignKey("osmoticRingType_model", blank=True, null=True)
#class Meta:
#unique_together = ("chemicalCategory","chemotaxisQuadrants","osmoticRing")
def __unicode__(self):
return "id: %s" % (self.uuid, )
class chemotaxisQuadrantsType_1_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
quadrantChemical = models.ForeignKey("chemicalType_model",related_name='access_quadrant_1_1', blank=False)
quadrantChemicalConcentration = models.FloatField(blank=False) #Provide in 1 mol / l = Molar = 1M
#class Meta:
#unique_together = ("quadrantsPlacement","numberOfQuadrants","quadrantChemical","quadrantBarrierChemical","quadrantChemicalConcentration","quadrantBarrierChemicalConcentration" )
def __unicode__(self):
return "id: %s" % (self.uuid, )
class chemotaxisQuadrantsType_2_model(models.Model):
uuid = models.CharField(('Unique Identifier'), max_length=36, primary_key=True, default=generate_new_uuid)
quadrant_1_Chemical = models.ForeignKey("chemicalType_model",related_name='access_quadrant_2_1', blank=False)
quadrant_2_Chemical = models.ForeignKey("chemicalType_model",related_name='access_quadrant_2_2', blank=False)
quadrant_1_ChemicalConcentration = models.FloatField(blank=False)#Provide in 1 mol / l = Molar = 1M
quadrant_2_ChemicalConcentration = models.FloatField(blank=False)#Provide in 1 mol / l = Molar = 1M
quadrantBarrierChemical = models.ForeignKey("chemicalType_model",related_name='access_quadrant_2_Barrier', blank=False)
quadrantBarrierChemicalConcentration = models.FloatField(blank=False)#Provide in 1 mol / l = Molar = 1M
#class Meta:
#uni |
ticle, rules=None):
"""Extract info from google scholar article
Doctest:
.. doctest::
Mock:
>>> class Article: pass
>>> article = Article()
>>> article.as_citation = lambda: '''
... @inproceedings{murta2014noworkflow,
... title={noWorkflow: capturing and analyzing provenance of scripts},
... author={Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana},
... booktitle={International Provenance and Annotation Workshop},
... pages={71--83},
... year={2014},
... organization={Springer}
... }'''
>>> article.attrs = {
... 'excerpt': ['Abstract'],
... 'cluster_id': ['5458343950729529273'],
... 'url_citations': ['http://scholar.google.com/scholar?cites=5458343950729529273&as_sdt=2005&sciodt=0,5&hl=en'],
... }
>>> article.div = None
Test:
>>> reload() # Deterministic name
>>> extract_info(article)
{'place1': 'International Provenance and Annotation Workshop', 'year': 2014, 'pp': '71--83', 'authors': 'Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana', 'name': 'noWorkflow: capturing and analyzing provenance of scripts', 'entrytype': 'inproceedings', 'place': 'IPAW', 'display': 'murta', 'pyref': 'murta2014b', 'organization': 'Springer', 'ID': 'murta2014noworkflow', 'excerpt': 'Abstract', 'cluster_id': '5458343950729529273', 'scholar': 'http://scholar.google.com/scholar?cites=5458343950729529273&as_sdt=2005&sciodt=0,5&hl=en'}
"""
rules = rules or config.BIBTEX_TO_INFO
as_citation = article.as_citation()
if not isinstance(as_citation, str):
as_citation = as_citation.decode("utf-8")
citation = parse_bibtex(as_citation)[0]
converter = ConvertDict(rules)
return converter.run(citation, article=article)
def info_to_code(article, rules=None):
"""Convert info dict into code
Required attributes:
* pyref
* display
* year
* name
* place || place1
Doctest:
.. doctest::
>>> print(info_to_code({
... 'pyref': 'pimentel2017a',
... 'display': 'disp',
... 'year': 2017,
... 'name': 'snowballing',
... 'authors': 'Pimentel, Joao',
... 'place1': 'CACM'
... }))
<BLANKLINE>
pimentel2017a = DB(Work(
2017, "snowballing",
display="disp",
authors="Pimentel, Joao",
place1="CACM",
))
With place:
>>> print(info_to_code({
... 'pyref': 'murta2014a',
... 'display': 'noworkflow',
... 'year': 2014,
... 'name': 'noWorkflow: capturing and analyzing provenance of scripts',
... 'authors': 'Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana',
... 'place': config.MODULES['places'].IPAW,
... }))
<BLANKLINE>
murta2014a = DB(Work(
2014, "noWorkflow: capturing and analyzing provenance of scripts",
display="noworkflow",
authors="Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana",
place=IPAW,
))
With string place:
>>> print(info_to_code({
... 'pyref': 'murta2014a',
... 'display': 'noworkflow',
... 'year': 2014,
... 'name': 'noWorkflow: capturing and analyzing provenance of scripts',
... 'authors': 'Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana',
... 'place': 'IPAW',
... }))
<BLANKLINE>
murta2014a = DB(Work(
2014, "noWorkflow: capturing and analyzing provenance of scripts",
display="noworkflow",
authors="Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana",
place=IPAW,
))
With _work_type, due, excerpt, others:
>>> print(info_to_code({
... '_work_type': 'WorkSnowball',
... 'due': 'Unrelated to my snowballing',
... 'excerpt': 'Ignore excerpt',
... 'other': 'Do not ignore other fields',
... 'pyref': 'murta2014a',
... 'display': 'noworkflow',
... 'year': 2014,
... 'name': 'noWorkflow: capturing and analyzing provenance of scripts',
... 'authors': 'Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana',
... 'place': config.MODULES['places'].IPAW,
... }))
<BLANKLINE>
murta2014a = DB(WorkSnowball(
2014, "noWorkflow: capturing and analyzing provenance o | f scripts",
due="Unrelated to my snowballing",
display="noworkflow",
authors="Murta, Leonardo and Braganholo, Vanessa and Chirigati, Fernando and Koop, David and Freire, Juliana",
place=IPAW,
other='Do not ignore other fields',
))
"""
rules = rules or config.INFO_TO_INSERT
info = copy(article)
converter = ConvertDict(rules)
| return converter.run(info)
def set_by_info(work, info, set_scholar=True, rules=None):
"""Find attributes that should be modified in a work object to make it match an info object"""
rules = rules or config.BIBTEX_TO_INFO
rules.get("<set_before>", lambda x, y: None)(work, info)
work_keys = {k for k in work.__dict__.keys() if not k.startswith("__")} - rules["<set_ignore_keys>"]
meta_keys = info.keys() - rules.get("<set_ignore_keys>", set())
show_result = OrderedDict(
(key, None) for key in rules.get("<set_order>", [])
)
set_result = {}
shared = meta_keys & work_keys
for key in shared:
value = info[key]
add = False
if key in rules.get("<set_ignore_but_show>", set()):
add = True
elif getattr(work, key) != value and key not in getattr(work, rules.get("<set_ignore_attr>", "ignoreattrs"), set()):
add = True
set_result[key] = (value, getattr(work, key))
elif key in rules.get("<set_always_show>", set()):
add = True
if add:
show_result[key] = (value, getattr(work, key))
for key in meta_keys - work_keys:
value = info[key]
set_result[key] = (value, None)
show_result[key] = (value, "")
if set_scholar and rules.get("<scholar_ok>") and not hasattr(work, rules["<scholar_ok>"]):
set_result[rules["<scholar_ok>"]] = (True, None)
result = {
"show": show_result,
"set": set_result,
}
if "<pos_diff>" in rules:
rules["<pos_diff>"](work, info, result)
return result
def changes_dict_to_set_attribute(metakey, changes_dict, end=";"):
"""Convert dictionart of changes to set_attribute instructions"""
result = []
for key, (value, old) in changes_dict.items():
result.append("set_attribute({!r}, {!r}, {!r}, old={!r})".format(metakey, key, value, old))
return "\n".join(result) + end
def citation_text(workref, cited, ref="", backward=False):
"""Create code for citation
Arguments:
* `workref` -- work varname that is cited (by default)
* `cited` -- work info dict that cites the work (by default)
Keyword arguments:
* `ref` -- citation number
* `backward` -- invert citation: `workref` cites `cited`
Doctest:
.. doctest::
>>> print(citation_text('freire2008a', {'pyref': 'murta2014a'}))
<BLANKLINE>
DB(Citation(
murta2014a, freire2008a, ref="",
contexts=[
<BLANKLINE>
],
))
<BLANKLINE>
>>> print(citation_text('pimentel2015a', {'pyref': 'murta2014a'}, backward=True, ref="[8]"))
<BLANKLINE>
DB(Citation(
pimentel2015a, murta2014a, ref="[8]",
contexts=[
<BLANKLINE>
],
))
<BLANK |
import os
import sys
from os.path import dirname, join |
import pytest
sys.path.insert(0, join(dirname(__file__), "..", ".."))
from wptrunner import browsers
_products = browsers.product_list
_active_products = set()
if "CURRENT_TOX_ENV" in os.environ:
current_tox_env_split = os.environ["CURRENT_TOX_ENV"].split("-")
tox_env_extra_browsers = {
"chrome": {"chrome_android", "chrome_webdriver"},
"edge": {"edge_webdriver"},
"safari": {"safari_webdriver"},
"servo": {"servodr | iver"},
}
_active_products = set(_products) & set(current_tox_env_split)
for product in frozenset(_active_products):
_active_products |= tox_env_extra_browsers.get(product, set())
else:
_active_products = set(_products)
class all_products(object):
def __init__(self, arg, marks={}):
self.arg = arg
self.marks = marks
def __call__(self, f):
params = []
for product in _products:
if product in self.marks:
params.append(pytest.param(product, marks=self.marks[product]))
else:
params.append(product)
return pytest.mark.parametrize(self.arg, params)(f)
class active_products(object):
def __init__(self, arg, marks={}):
self.arg = arg
self.marks = marks
def __call__(self, f):
params = []
for product in _products:
if product not in _active_products:
params.append(pytest.param(product, marks=pytest.mark.skip(reason="wrong toxenv")))
elif product in self.marks:
params.append(pytest.param(product, marks=self.marks[product]))
else:
params.append(product)
return pytest.mark.parametrize(self.arg, params)(f)
|
# verify we can test things
self.assertTrue(distro.set_owners(["superlab","basement1"]))
self.assertTrue(profile.set_owners(["superlab","basement1"]))
self.assertTrue(profile.set_kickstart("/tmp/test_cobbler_kickstart"))
self.assertTrue(system.set_owners(["superlab","basement1","basement3"]))
self.assertTrue(repo.set_owners([]))
self.api.add_distro(distro)
self.api.add_profile(profile)
self.api.add_system(system)
self.api.add_repo(repo)
# now edit the groups file. We won't test the full XMLRPC
# auth stack here, but just the module in question
authorize = authz_module.authorize
# if the users.conf file exists, back it up for the tests
if os.path.exists("/etc/cobbler/users.conf"):
shutil.copyfile("/etc/cobbler/users.conf","/tmp/cobbler_ubak")
fd = open("/etc/cobbler/users.conf","w+")
fd.write("\n")
fd.write("[admins]\n")
fd.write("admin1 = 1\n")
fd.write("\n")
fd.write("[superlab]\n")
fd.write("superlab1 = 1\n")
fd.write("superlab2 = 1\n")
fd.write("\n")
fd.write("[basement]\n")
fd.write("basement1 = 1\n")
fd.write("basement2 = 1\n")
fd.write("basement3 = 1\n")
fd.close()
xo = self.api.find_distro("testdistro0")
xn = "testdistro0"
ro = self.api.find_repo("test_repo")
rn = "test_repo"
# WARNING: complex test explanation follows!
# we must ensure those who can edit the kickstart are only those
# who can edit all objects that depend on the said kickstart
# in this test, superlab & basement1 can edit test_profile0
# superlab & basement1/3 can edit test_system0
# the systems share a common kickstart record (in this case
# explicitly set, which is a bit arbitrary as they are parent/child
# nodes, but the concept is not limited to this).
# Therefore the correct result is that the following users can edit:
# admin1, superlab1, superlab2
# And these folks can't
# basement1, basement2
# Basement2 is rejected because the kickstart is shared by something
# basmeent2 can not edit.
for user in [ "admin1", "superlab1", "superlab2", "basement1" ]:
self.assertTrue(1==authorize(self.api, user, "modify_kickstart", "/tmp/test_cobbler_kickstart"), "%s can modify_kickstart" % user)
for user in [ "basement2", "dne" ]:
self.assertTrue(0==authorize(self.api, user, "modify_kickstart", "/tmp/test_cobbler_kickstart"), "%s can modify_kickstart" % user)
# ensure admin1 can edit (he's an admin) and do other tasks
# same applies to basement1 who is explicitl | y added as a user
# and superlab1 who is in a group in the ownership list
for user in ["admin1","superlab1","basement1"]:
self.assertTrue(1==authorize(self.api, us | er, "save_distro", xo),"%s can save_distro" % user)
self.assertTrue(1==authorize(self.api, user, "modify_distro", xo),"%s can modify_distro" % user)
self.assertTrue(1==authorize(self.api, user, "copy_distro", xo),"%s can copy_distro" % user)
self.assertTrue(1==authorize(self.api, user, "remove_distro", xn),"%s can remove_distro" % user)
# ensure all users in the file can sync
for user in [ "admin1", "superlab1", "basement1", "basement2" ]:
self.assertTrue(1==authorize(self.api, user, "sync"))
# make sure basement2 can't edit (not in group)
# and same goes for "dne" (does not exist in users.conf)
for user in [ "basement2", "dne" ]:
self.assertTrue(0==authorize(self.api, user, "save_distro", xo), "user %s cannot save_distro" % user)
self.assertTrue(0==authorize(self.api, user, "modify_distro", xo), "user %s cannot modify_distro" % user)
self.assertTrue(0==authorize(self.api, user, "remove_distro", xn), "user %s cannot remove_distro" % user)
# basement2 is in the file so he can still copy
self.assertTrue(1==authorize(self.api, "basement2", "copy_distro", xo), "basement2 can copy_distro")
# dne can not copy or sync either (not in the users.conf)
self.assertTrue(0==authorize(self.api, "dne", "copy_distro", xo), "dne cannot copy_distro")
self.assertTrue(0==authorize(self.api, "dne", "sync"), "dne cannot sync")
# unlike the distro testdistro0, testrepo0 is unowned
# so any user in the file will be able to edit it.
for user in [ "admin1", "superlab1", "basement1", "basement2" ]:
self.assertTrue(1==authorize(self.api, user, "save_repo", ro), "user %s can save_repo" % user)
# though dne is still not listed and will be denied
self.assertTrue(0==authorize(self.api, "dne", "save_repo", ro), "dne cannot save_repo")
# if we survive, restore the users file as module testing is done
if os.path.exists("/tmp/cobbler_ubak"):
shutil.copyfile("/etc/cobbler/users.conf","/tmp/cobbler_ubak")
class MultiNIC(BootTest):
def test_multi_nic_support(self):
system = self.api.new_system()
self.assertTrue(system.set_name("nictest"))
self.assertTrue(system.set_profile("testprofile0"))
self.assertTrue(system.set_hostname("zero","intf0"))
self.assertTrue(system.set_mac_address("EE:FF:DD:CC:DD:CC","intf1"))
self.assertTrue(system.set_ip_address("127.0.0.5","intf2"))
self.assertTrue(system.set_dhcp_tag("zero","intf3"))
self.assertTrue(system.set_virt_bridge("zero","intf4"))
self.assertTrue(system.set_gateway("192.168.1.25","intf4"))
self.assertTrue(system.set_mac_address("AA:AA:BB:BB:CC:CC","intf4"))
self.assertTrue(system.set_hostname("fooserver","intf4"))
self.assertTrue(system.set_dhcp_tag("red","intf4"))
self.assertTrue(system.set_ip_address("192.168.1.26","intf4"))
self.assertTrue(system.set_subnet("255.255.255.0","intf4"))
self.assertTrue(system.set_dhcp_tag("tag2","intf5"))
self.assertTrue(self.api.systems().add(system))
# mixing in some higher level API calls with some lower level internal stuff
# just to make sure it's all good.
self.assertTrue(self.api.find_system(hostname="zero"))
self.assertTrue(self.api.systems().find(mac_address="EE:FF:DD:CC:DD:CC"))
self.assertTrue(self.api.systems().find(ip_address="127.0.0.5"))
self.assertTrue(self.api.find_system(virt_bridge="zero"))
self.assertTrue(self.api.systems().find(gateway="192.168.1.25"))
self.assertTrue(self.api.systems().find(subnet="255.255.255.0"))
self.assertTrue(self.api.find_system(dhcp_tag="tag2"))
self.assertTrue(self.api.systems().find(dhcp_tag="zero"))
# verify that systems has exactly 5 interfaces
self.assertTrue(len(system.interfaces.keys()) == 6)
# now check one interface to make sure it's exactly right
# and we didn't accidentally fill in any other fields elsewhere
self.assertTrue(system.interfaces.has_key("intf4"))
for (name,intf) in system.interfaces.iteritems():
if name == "intf4": # xmlrpc dicts must have string keys, so we must also
self.assertTrue(intf["gateway"] == "192.168.1.25")
self.assertTrue(intf["virt_bridge"] == "zero")
self.assertTrue(intf["subnet"] == "255.255.255.0")
self.assertTrue(intf["mac_address"] == "AA:AA:BB:BB:CC:CC")
self.assertTrue(intf["ip_address"] == "192.168.1.26")
self.assertTrue(intf["hostname"] == "fooserver")
self.assertTrue(intf["dhcp_tag"] == "red")
class Utilities(BootTest):
def _expeq(self, expected, actual):
try:
self.failUnlessEqual(expected, actual,
"Expected: %s; actual: %s" % (expected, actual))
except:
self.fail("exception during failUnlessEqual")
de |
# -*- coding: ut | f-8 -*-
# Generated by Django 1.11 on 2017-07-03 18:14
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("ui", "0003_add_videofile"),
]
operations = [
migrations.CreateModel(
name="VideoThumbnail",
fields=[
(
"id",
models.A | utoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("s3_object_key", models.TextField(unique=True)),
("bucket_name", models.CharField(max_length=63)),
("preset_id", models.CharField(blank=True, max_length=128, null=True)),
("max_width", models.IntegerField(blank=True, null=True)),
("max_height", models.IntegerField(blank=True, null=True)),
(
"video",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="ui.Video"
),
),
],
options={
"abstract": False,
},
),
]
|
r"""
Three.js Enums
These correspond to the enum property names in the THREE js object
"""
# Custom Blending Equation Constants
# http://threejs.org/docs/index.html#Reference/Constants/CustomBlendingEquation
Equations = [
'AddEquation',
'SubtractEquation',
'ReverseSubtractEquation',
'MinEquation',
'MaxEquation'
]
DestinationFactors = [
'ZeroFactor',
'OneFactor',
'SrcColorFactor',
'OneMinusSrcColorFactor',
'SrcAlphaFactor',
'OneMinusSrcAlphaFactor',
'DstAlphaFactor',
'OneMinusDstAlphaFactor'
]
SourceFactors = [
'DstColorFactor',
'OneMinusDstColorFactor',
'SrcAlphaSaturateFactor'
]
# Material Constants
# http://threejs.org/docs/index.html#Reference/Constants/Materials
Side = [
'FrontSide',
'BackSide',
'DoubleSide'
]
Shading = [
'FlatShading',
'SmoothShading'
]
Colors = [
'NoColors',
'FaceColors',
'VertexColors'
]
BlendingMode = [
'NoBlending',
'NormalBlending',
'AdditiveBlending',
'SubtractiveBlending',
'MultiplyBlending',
'CustomBlending'
]
# Texture Constants
# http://threejs.org/docs/index.html#Reference/Constants/Textures
Operations = [
'MultiplyOperation',
'MixOperation',
'AddOperation'
]
MappingModes = [
'UVMapping',
'CubeReflectionMapping',
'CubeRefractionMapping',
'EquirectangularReflectionMapping',
'EquirectangularRefractionMapping',
'SphericalReflectionMapping'
]
WrappingModes = [
'RepeatWrapping',
'ClampToEdgeWrapping',
'MirroredRepeatWrapping'
]
Filters = [
'NearestFilter',
'NearestMipMapNearestFilter',
'NearestMipMapLinearFilter',
'LinearFilter',
'LinearMipMapNearestFilter',
'LinearMipMapLinearFilter'
]
DataTypes = [
'UnsignedByteType',
'ByteType',
'ShortType',
'UnsignedShortType',
'IntType',
'UnsignedIntType',
' | FloatType',
'HalfFloatType'
]
PixelTypes = [
'UnsignedShort4444Type',
'UnsignedShort5551Type',
'UnsignedShort565T | ype'
]
PixelFormats = [
'AlphaFormat',
'RGBFormat',
'RGBAFormat',
'LuminanceFormat',
'LuminanceAlphaFormat',
'RGBEFormat'
]
CompressedTextureFormats = [
'RGB_S3TC_DXT1_Format',
'RGBA_S3TC_DXT1_Format',
'RGBA_S3TC_DXT3_Format',
'RGBA_S3TC_DXT5_Format',
'RGB_PVRTC_4BPPV1_Format',
'RGB_PVRTC_2BPPV1_Format',
'RGBA_PVRTC_4BPPV1_Format',
'RGBA_PVRTC_2BPPV1_Format'
]
# Misc
Lines = [
'LineStrip',
'LinePieces'
]
Renderers = [
'webgl',
'canvas',
'auto'
]
|
rade",
"sec-websocket-accept": "Kxep+hNu9n51529fGidYu7a3wO0="}
self.assertEqual(_validate_header(required_header, key, None), (True, None))
header = required_header.copy()
header["upgrade"] = "http"
self.assertEqual(_validate_header(header, key, None), (False, None))
del header["upgrade"]
self.assertEqual(_validate_header(header, k | ey, None), (False, None))
header = required_header.copy()
header["connection"] = "something"
self.assertEqual(_validate_header(header, key, None), (False, None))
del header["connection"]
self.assertEqual(_validate_header(header, key, | None), (False, None))
header = required_header.copy()
header["sec-websocket-accept"] = "something"
self.assertEqual(_validate_header(header, key, None), (False, None))
del header["sec-websocket-accept"]
self.assertEqual(_validate_header(header, key, None), (False, None))
header = required_header.copy()
header["sec-websocket-protocol"] = "sub1"
self.assertEqual(_validate_header(header, key, ["sub1", "sub2"]), (True, "sub1"))
# This case will print out a logging error using the error() function, but that is expected
self.assertEqual(_validate_header(header, key, ["sub2", "sub3"]), (False, None))
header = required_header.copy()
header["sec-websocket-protocol"] = "sUb1"
self.assertEqual(_validate_header(header, key, ["Sub1", "suB2"]), (True, "sub1"))
header = required_header.copy()
# This case will print out a logging error using the error() function, but that is expected
self.assertEqual(_validate_header(header, key, ["Sub1", "suB2"]), (False, None))
def testReadHeader(self):
status, header, status_message = read_headers(HeaderSockMock("data/header01.txt"))
self.assertEqual(status, 101)
self.assertEqual(header["connection"], "Upgrade")
status, header, status_message = read_headers(HeaderSockMock("data/header03.txt"))
self.assertEqual(status, 101)
self.assertEqual(header["connection"], "Upgrade, Keep-Alive")
HeaderSockMock("data/header02.txt")
self.assertRaises(ws.WebSocketException, read_headers, HeaderSockMock("data/header02.txt"))
def testSend(self):
# TODO: add longer frame data
sock = ws.WebSocket()
sock.set_mask_key(create_mask_key)
s = sock.sock = HeaderSockMock("data/header01.txt")
sock.send("Hello")
self.assertEqual(s.sent[0], b'\x81\x85abcd)\x07\x0f\x08\x0e')
sock.send("こんにちは")
self.assertEqual(s.sent[1], b'\x81\x8fabcd\x82\xe3\xf0\x87\xe3\xf1\x80\xe5\xca\x81\xe2\xc5\x82\xe3\xcc')
# sock.send("x" * 5000)
# self.assertEqual(s.sent[1], b'\x81\x8fabcd\x82\xe3\xf0\x87\xe3\xf1\x80\xe5\xca\x81\xe2\xc5\x82\xe3\xcc")
self.assertEqual(sock.send_binary(b'1111111111101'), 19)
def testRecv(self):
# TODO: add longer frame data
sock = ws.WebSocket()
s = sock.sock = SockMock()
something = b'\x81\x8fabcd\x82\xe3\xf0\x87\xe3\xf1\x80\xe5\xca\x81\xe2\xc5\x82\xe3\xcc'
s.add_packet(something)
data = sock.recv()
self.assertEqual(data, "こんにちは")
s.add_packet(b'\x81\x85abcd)\x07\x0f\x08\x0e')
data = sock.recv()
self.assertEqual(data, "Hello")
@unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled")
def testIter(self):
count = 2
s = ws.create_connection('wss://api.bitfinex.com/ws/2')
s.send('{"event": "subscribe", "channel": "ticker"}')
for _ in s:
count -= 1
if count == 0:
break
@unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled")
def testNext(self):
sock = ws.create_connection('wss://api.bitfinex.com/ws/2')
self.assertEqual(str, type(next(sock)))
def testInternalRecvStrict(self):
sock = ws.WebSocket()
s = sock.sock = SockMock()
s.add_packet(b'foo')
s.add_packet(socket.timeout())
s.add_packet(b'bar')
# s.add_packet(SSLError("The read operation timed out"))
s.add_packet(b'baz')
with self.assertRaises(ws.WebSocketTimeoutException):
sock.frame_buffer.recv_strict(9)
# with self.assertRaises(SSLError):
# data = sock._recv_strict(9)
data = sock.frame_buffer.recv_strict(9)
self.assertEqual(data, b'foobarbaz')
with self.assertRaises(ws.WebSocketConnectionClosedException):
sock.frame_buffer.recv_strict(1)
def testRecvTimeout(self):
sock = ws.WebSocket()
s = sock.sock = SockMock()
s.add_packet(b'\x81')
s.add_packet(socket.timeout())
s.add_packet(b'\x8dabcd\x29\x07\x0f\x08\x0e')
s.add_packet(socket.timeout())
s.add_packet(b'\x4e\x43\x33\x0e\x10\x0f\x00\x40')
with self.assertRaises(ws.WebSocketTimeoutException):
sock.recv()
with self.assertRaises(ws.WebSocketTimeoutException):
sock.recv()
data = sock.recv()
self.assertEqual(data, "Hello, World!")
with self.assertRaises(ws.WebSocketConnectionClosedException):
sock.recv()
def testRecvWithSimpleFragmentation(self):
sock = ws.WebSocket()
s = sock.sock = SockMock()
# OPCODE=TEXT, FIN=0, MSG="Brevity is "
s.add_packet(b'\x01\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C')
# OPCODE=CONT, FIN=1, MSG="the soul of wit"
s.add_packet(b'\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17')
data = sock.recv()
self.assertEqual(data, "Brevity is the soul of wit")
with self.assertRaises(ws.WebSocketConnectionClosedException):
sock.recv()
def testRecvWithFireEventOfFragmentation(self):
sock = ws.WebSocket(fire_cont_frame=True)
s = sock.sock = SockMock()
# OPCODE=TEXT, FIN=0, MSG="Brevity is "
s.add_packet(b'\x01\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C')
# OPCODE=CONT, FIN=0, MSG="Brevity is "
s.add_packet(b'\x00\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C')
# OPCODE=CONT, FIN=1, MSG="the soul of wit"
s.add_packet(b'\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17')
_, data = sock.recv_data()
self.assertEqual(data, b'Brevity is ')
_, data = sock.recv_data()
self.assertEqual(data, b'Brevity is ')
_, data = sock.recv_data()
self.assertEqual(data, b'the soul of wit')
# OPCODE=CONT, FIN=0, MSG="Brevity is "
s.add_packet(b'\x80\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C')
with self.assertRaises(ws.WebSocketException):
sock.recv_data()
with self.assertRaises(ws.WebSocketConnectionClosedException):
sock.recv()
def testClose(self):
sock = ws.WebSocket()
sock.connected = True
sock.close
sock = ws.WebSocket()
s = sock.sock = SockMock()
sock.connected = True
s.add_packet(b'\x88\x80\x17\x98p\x84')
sock.recv()
self.assertEqual(sock.connected, False)
def testRecvContFragmentation(self):
sock = ws.WebSocket()
s = sock.sock = SockMock()
# OPCODE=CONT, FIN=1, MSG="the soul of wit"
s.add_packet(b'\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17')
self.assertRaises(ws.WebSocketException, sock.recv)
def testRecvWithProlongedFragmentation(self):
sock = ws.WebSocket()
s = sock.sock = SockMock()
# OPCODE=TEXT, FIN=0, MSG="Once more unto the breach, "
s.add_packet(b'\x01\x9babcd.\x0c\x00\x01A\x0f\x0c\x16\x04B\x16\n\x15\rC\x10\t\x07C\x06\x13\x07\x02\x07\tNC')
# OPCODE=CONT, FIN=0, MSG="dear friends, "
s.add_packet(b'\x00\x8eabcd\x05\x07\x02\x16A\x04\x11\r\x04\x0c\x07\x17MB')
# OPCODE=CONT, FIN=1, MSG="once more"
s.add_packet(b'\x80\x89abcd\x0e\x0c\x00\x01A\x0f\x0c\x16\x04')
data = sock.recv()
sel |
#!/usr/bin/env python
from blob import Blob
from foreground_processor import ForegroundProcessor
import cv2
import operator
import rospy
from blob_detector.msg import Blob as BlobMsg
from blob_detector.msg import Blobs as BlobsMsg
import numpy as np
class BlobDetector(ForegroundProcessor):
def __init__(self, node_name):
super(BlobDetector, self).__init__(node_name)
self.pub = rospy.Publisher('/blobs', BlobsMsg)
def find_blobs(self, rgbd):
mask = rgbd.depth_mask_sm
contours0 = cv2.findContours( mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = [cv2.approxPolyDP(cnt, 3, True) for cnt in contours0[0]]
blobs = [Blob(contour=c, source_rgbd=rgbd) for c in contours]
blobs = [b for b in blobs if b.area > 800] # filter
| [b.compute_params() for b in blobs] # cpu intensive initialization
return blobs
def process_depth_mask_image(self, rgbd):
blobs = self.find_blobs(rgbd)
#for blob in blobs:
# blob.set_world_coordinates_from_depth(rgbd.depth | _raw)
self.process_blobs(blobs, rgbd)
def publish_blobs(self, blobs):
blobs_msg = BlobsMsg()
for blob in blobs:
blob_msg = blob.to_msg()
blobs_msg.blobs.append(blob_msg)
self.pub.publish(blobs_msg)
def show_blobs(self, blobs, rgbd):
for blob in blobs:
blob.draw(rgbd.depth_color_sm)
self.show_depth_color(rgbd)
def process_blobs(self, blobs, rgbd):
self.publish_blobs(blobs)
self.show_blobs(self, blobs, rgbd)
if __name__ == '__main__':
bd = BlobDetector('fg')
bd.run()
|
{ | 'board_id': 812,
'public_url': 'https://p.datadoghq.c | om/sb/20756e0cd4'}
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('flooding_lib', '__first__'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='ExportRun',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200, verbose_name='Name')),
('description', models.TextField(verbose_name='Description', blank=True)),
('export_type', models.IntegerField(default=10, choices=[(10, 'Water depth map')])),
('export_max_waterdepth', models.BooleanField(default=True, verbose_name='The maximal | waterdepth')),
('export_max_flowvelocity', models.BooleanField(default=True, verbose_name='The maximal flowvelocity')),
('export_possibly_flooded', models.BooleanField(default=True, verbose_name='The flooded area')),
('export_arrival_times', models.BooleanField(default=True, verbose_n | ame='The arrival times')),
('export_period_of_increasing_waterlevel', models.BooleanField(default=True, verbose_name='The period of increasing waterlevel')),
('export_inundation_sources', models.BooleanField(default=True, verbose_name='The sources of inundation')),
('export_scenario_data', models.BooleanField(default=False, verbose_name='All scenario data')),
('creation_date', models.DateTimeField(null=True, verbose_name='Creation date', blank=True)),
('run_date', models.DateTimeField(null=True, verbose_name='Run date', blank=True)),
('approved_date', models.DateTimeField(null=True, verbose_name='Approved date', blank=True)),
('gridsize', models.PositiveIntegerField(default=50, verbose_name='Gridsize')),
('state', models.IntegerField(default=10, choices=[(10, 'Waiting'), (50, 'Ready')])),
('public', models.BooleanField(default=True, verbose_name='Publicly visible')),
('archived', models.BooleanField(default=False, verbose_name='Moved to the archive')),
('owner', models.ForeignKey(verbose_name='Owner', to=settings.AUTH_USER_MODEL)),
('scenarios', models.ManyToManyField(to='flooding_lib.Scenario')),
],
options={
'ordering': ['creation_date'],
'verbose_name': 'Export run',
'verbose_name_plural': 'Export runs',
'permissions': (('can_create', 'Can create export'), ('can_download', 'Can download exportresult')),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Result',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200)),
('file_basename', models.CharField(max_length=100)),
('area', models.IntegerField(choices=[(10, 'Diked area'), (20, 'Province'), (30, 'Country')])),
('export_run', models.ForeignKey(to='exporttool.ExportRun')),
],
options={
'verbose_name': 'Result',
'verbose_name_plural': 'Results',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Setting',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('key', models.CharField(unique=True, max_length=200)),
('value', models.CharField(max_length=200)),
('remarks', models.TextField(null=True, blank=True)),
],
options={
},
bases=(models.Model,),
),
]
|
import cPickle
class GameState:
# g = GameState(11,22,3,4,5) init
# g.pickle('test.gamestate') save
# x = GameState().unpickle('test.gamestate') lo | ad
def __init__ | (self,rulesfile=None,turns=None,connection=None,
cache=None,verbosity=None, pickle_location=None):
if pickle_location is None:
self.rulesfile = rulesfile
self.turns = turns
self.connection = connection
self.cache = cache
self.verbosity = verbosity
def pickle(self, file_name):
file = open(file_name, 'wb')
cPickle.dump(self, file)
file.close()
return
def unpickle(self, pickle_location):
file = open(pickle_location, 'rb')
old = cPickle.load(file)
file.close()
return old
|
"""
<This library provides a Python interface for the Telegram Bot API>
Copyright (C) <2015> <Jacopo De Luca>
This program is free software: you can redistribute it and/or modify
it under the terms of the G | NU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a | copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
class Location(object):
"""
This object represents a point on the map.
"""
def __init__(self, longitude, latitude):
"""
:param longitude: Longitude as defined by sender
:type longitude: float
:param latitude: Latitude as defined by sender
:type latitude: float
"""
self.longitude = longitude
self.latitude = latitude
@staticmethod
def build_from_json(jlocation):
"""
:param jlocation: A dictionary that contains JSON-parsed object
:type jlocation: dict
:rtype: Location
"""
return Location(jlocation['longitude'], jlocation['latitude'])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.