def autodoc(obj):
    """Autodocument all Options for class `obj`"""
    mro = list(inspect.getmro(obj))
    mro.reverse()
    # Keep parent object in order to write only missing options
    if len(mro) > 1:
        parent_class = mro[-2]
    else:
        parent_class = False
    # Keep only names
    mro = [cls.__name__ for cls in mro]
    # Skip xmlrpc stuff
    if not 'ConfigurationInterface' in mro:
        print 'Object does not inherit from base ConfigurationInterface class. Skipping autodoc.', mro
        return False
    i = mro.index('ConfigurationInterface')
    mro = mro[i:]

    fname = '.'.join(mro) + '.rst'
    path_rst = os.path.join(autodoc_dir, fname)


    if not os.path.exists(path_rst):
        logging.debug('Creating index.rst', path_rst)
        open(path_rst, 'w').close()

    rst = open(path_rst, 'r').read()
    parent_conf = getattr(parent_class, 'conf_def', [])
    rst = update_rst(obj.conf_def, rst, parent_conf, obj.__name__)
    # Write on output file
    if len(rst)>0:
        open(path_rst, 'w').write(rst)
    return True
Exemplo n.º 2
0
    def drawShape(self, painter, rect):
        """Draw pixmap."""
        s = self.settings
        # draw border and fill
        painter.drawRect(rect)
        # cache pixmap
        w, h = rect.width(), rect.height()
        if self.cachefilename != s.iconname or w != self.cachewidth or h != self.cacheheight:
            self.updateCachedPixmap(w, h)
        pixmap = self.cachepixmap
        # pixmap rectangle
        prect = QtCore.QRectF(pixmap.rect())
        logging.debug(prect)
#		# preserve aspect ratio
        if s.aspect:
            xr = rect.width() / prect.width()
            yr = rect.height() / prect.height()

            if xr > yr:
                rect = QtCore.QRectF(rect.left() + (rect.width() -
                                                    prect.width() * yr) * 0.5,
                                     rect.top(),
                                     prect.width() * yr,
                                     rect.height())
            else:
                rect = QtCore.QRectF(rect.left(),
                                     rect.top() + (rect.height() -
                                                   prect.height() * xr) * 0.5,
                                     rect.width(),
                                     prect.height() * xr)

        # finally draw pixmap
        painter.drawPixmap(rect, pixmap, prect)
 def test_water(self):
     """Filled with water test data"""
     N = 10
     beta = np.ones(N) * 4.3
     R0 = np.ones(N) * 6220
     T = np.ones(N) * 25
     out = self.do(beta, R0, T)
     self.assertEqual(len(out), N)
     logging.debug('water', out)
 def test_water(self):
     """Filled with water test data"""
     N = 10
     beta = np.ones(N) * 4.3
     R0 = np.ones(N) * 6220
     T = np.ones(N) * 25
     out = self.do(beta, R0, T)
     self.assertEqual(len(out), N)
     logging.debug('water', out)
    def do(self, beta, R0, T, dil='', dilT='', gdil='', gdilT='', **kw):
        fields = self.fields.copy()
        doc = document.Document()
        p = self.create_plugin(doc, fields, beta, R0, T, dil='', dilT='', gdil='', gdilT='', **kw)

        logging.debug('get ds')
        p.getDatasets(fields)
        logging.debug('update ds')
        out = p.updateDatasets(fields, veusz.plugins.DatasetPluginHelper(doc))
        return out
 def search(self, start=None, expect=90, delta=None):
     if not delta:
         delta = self.delta
         if not delta:
             delta = 3 * self.density
     expect *= self.density
     if start is not None:
         start *= self.density
         self.dp.point_index = start
         self.dp.x = self.dp.xData[self.dp.point_index]
         self.dp.y = self.dp.yData[self.dp.point_index]
     logging.debug('starting from', self.dp.point_index, self.dp.x, self.dp.y)
     self.assertTrue(self.dp.critical_search(self.dp.settings.search))
     logging.debug('ending in', self.dp.point_index, self.dp.x, self.dp.y)
     self.assertAlmostEqual(self.dp.point_index, expect, delta=delta)
    def create_plugin(self, doc, fields, beta, R0, T, dil='', dilT='', gdil='', gdilT='', **kw):

        ds = {'beta': beta, 'R0': R0, 'T': T, 'dil': dil,
              'dilT': dilT, 'gdil': gdil, 'gdilT': gdilT}
        for k in ds.keys():
            if ds[k] == '':
                fields[k] = ''
                continue
            logging.debug('inserting data', k)
            insertData(doc, {k: ds[k]})
            fields[k] = k
        fields.update(kw)
        fields['ds_out'] = 'out'
        logging.debug('build op')
        return SurfaceTensionPlugin(**fields)
 def test_infnan(self):
     """Check tolerance towards nan/inf"""
     N = 10
     beta = np.ones(N)
     R0 = np.ones(N)
     beta[-1] = 0  # induce divide by zero (inf)
     R0[-2] = 0
     beta[-2] = 0  # induce nan
     T = np.arange(25, 25 + N)
     out = self.do(beta, R0, T)
     self.assertEqual(len(out), N)
     # Both nan and inf should be converted to zero
     self.assertEqual(out[-1], 0)
     self.assertEqual(out[-2], 0)
     logging.debug(out)
def write_ts(lang, ctx):
    """Output context to .ts formatted file"""
    filename = os.path.join(pathLang, 'misura_' + lang + '.ts')
    out = open(filename, 'w')
    out.write(header % lang)
    for c, ent in ctx.iteritems():
        out.write(context_h % c)
        logging.debug('\tContext:', c)
        for s, e in ent.iteritems():
            if e[0] == '':
                out.write(u_entry % (s, e[0], e[1]))
            else:
                out.write(entry % (s, e[0], e[1]))
        out.write(context_f)
    out.write(footer)
 def test_infnan(self):
     """Check tolerance towards nan/inf"""
     N = 10
     beta = np.ones(N)
     R0 = np.ones(N)
     beta[-1] = 0  # induce divide by zero (inf)
     R0[-2] = 0
     beta[-2] = 0  # induce nan
     T = np.arange(25, 25 + N)
     out = self.do(beta, R0, T)
     self.assertEqual(len(out), N)
     # Both nan and inf should be converted to zero
     self.assertEqual(out[-1], 0)
     self.assertEqual(out[-2], 0)
     logging.debug(out)
Exemplo n.º 11
0
 def _addSettings(klass, s):
     """Construct list of settings."""
     lst = ['None'] + veusz.utils.action._iconcache.keys()
     lst.sort()
     logging.debug(lst)
     s.add(veusz.setting.Choice('iconname',
                                lst,
                                'None',
                                descr='Icon name',
                                usertext='IconName'),
           posn=0)
     s.add(veusz.setting.Bool('aspect', True,
                              descr='Preserve aspect ratio',
                              usertext='Preserve aspect',
                              formatting=True),
           posn=0)
Exemplo n.º 12
0
    def check_import(self, op, names=False):
        """Simulate a data import operation"""
        logging.debug('check_import', op)
        fp = indexer.SharedFile(op)
        fp.load_conf()
        rm = devtree.recursiveModel(fp.conf)
        fp.close()
        # Simulate an import
        imp = filedata.OperationMisuraImport(
            filedata.ImportParamsMisura(filename=op))
        doc = filedata.MisuraDocument()
        imp.do(doc)
#        if names is not False:
#            self.assertEqual(set(imp.outdatasets), names)
        for ds in doc.data.itervalues():
            self.assertFalse(np.isnan(ds.data).any())
        return doc
Exemplo n.º 13
0
def collect_conf(module, translations):
    """Scan a module for all classes defining a conf_def iterable attribute."""
    names = dir(module)
    missing = 0
    for name in names:
        obj = getattr(module, name, False)
        if obj is False:
            continue
        if not hasattr(obj, 'conf_def'):
            continue
        conf_def = getattr(obj, 'conf_def', False)
        if not conf_def:
            continue
        # Skip modules defining a conf_def list at their root.
        if getattr(obj, '__bases__', False) is False:
            continue
        if obj in done: continue
        done.add(obj)
        logging.debug('Found conf_def', obj.__name__, conf_def)
        autodoc(obj)
        for el in conf_def:
            if not isinstance(el, dict):
                continue
            tr = el.get('name', False)
            if not tr:
                continue
            h = el.get('handle', False)
            if not h:
                missing += 1
                h = '!!!_missing_handle_{}'.format(missing)
            logging.debug(obj, h, tr)
            translations[h] = tr
            # Get translatable option names
            opt = el.get('options', False)
            if not opt:
                continue
            if not el.has_key('values'):
                continue
            for i, o in enumerate(opt):
                h1 = h + '_opt{}'.format(i)
                translations[h1] = o
    return translations, missing
Exemplo n.º 14
0
def scan_client_source(path, out=False):
    retn = {}
    for root, dirs, files in os.walk(path):
        for fn in files:
            if not fn.endswith('.py'):
                continue
            fp = os.path.join(root, fn)
            logging.debug('Scanning', fp)
            python_find_strings(fp, retn)
    # Simplify output
    if not out:
        out = {}
    for ctx, msgs in retn.iteritems():
        if not out.has_key(ctx):
            out[ctx] = {}
        for msg in msgs:
            v = mescape(msg.string)
            out[ctx][v] = ('', '')
#         out[ctx] += [msg.string for msg in msgs]
    return out
Exemplo n.º 15
0
def language_sync():
    """Merge all translatable strings from runtime requests, code analysis, already translated code."""
    # Translation contexts
    contexts = {'Option': {}}

    # Collect from server code analysis
    trcode = collect()
    for v in trcode.values():
        v = mescape(v)
        contexts['Option'][v] = ('', '')

    # Collect from client code analysis
    contexts = scan_client_source(pathClient, out=contexts)

    statistics = {}
    for l in langs:
        logging.debug('LANGUAGE:', l)
        ctx = update(l, contexts.copy(), base='misura')
        ctx = update(l, ctx)
        write_ts(l, ctx)
        statistics[l] = stats(ctx)
        # cancello tutte le traduzioni, mantenendo però le chiavi
        contexts = {}
        for c, v in ctx.iteritems():
            if not contexts.has_key(c):
                contexts[c] = {}
            for k, e in v.iteritems():
                contexts[c][k] = ('', '')

    logging.debug('Completeness:')
    for l in langs:
        s = statistics[l]
        logging.debug('%s: %.2f %% (missing: %i)' %
                      (l.upper(), 100. * s[1] / (s[1] + s[2]), s[2]))
    def test_sampling(self):
        """Test the operation from a Misura3 file"""
        # Two equal datasets, but with different sampling
        ax = np.linspace(0, 10, 10)
        ay = ax[:]
        # B is supersampled by 10
        bx = np.linspace(0, 10, 100)
        by = bx[:]
        # SUPERSAMPLING
        # Subtract B to A
        sup = self.do(ax, ay, bx, by, 'A-B')
        logging.debug('Supersampling', sup.sum())
        # Output value should have same length of ref. array, A
        self.assertEqual(len(sup), len(ay))

        # UNDERSAMPLING
        und = self.do(bx, by, ax, ay, 'A-B')
        logging.debug('Undersampling', und.sum())
        # Output value should have same length of ref. array, B
        self.assertEqual(len(und), len(by))
        self.assertAlmostEqual(sup.sum(), 0)
        self.assertAlmostEqual(und.sum(), 0)
Exemplo n.º 17
0
def collect():
    """Collect translatable strings from static source code analysis.
    Returns all collected strings."""

    import misura
    from misura.canon.indexer import indexer

    translations, missing = iterpackage(misura)
    logging.debug('Stats', len(
        translations), len(set(translations)), missing)

    for column in indexer.columns_to_translate:
        translations["dbcol:" + column] = "dbcol:" + column

    out = open('static.txt', 'w')
    for h, tr in translations.iteritems():
        out.write('{}\t{}\n'.format(h, tr))
    out.close()



    return translations
Exemplo n.º 18
0
def update(lang, ctx, base='misura'):
    """Add already translated values to the context `ctx`."""
    c = False
    s = False
    t = False
    m = ''
    ctx = ctx.copy()
    filename = os.path.join(pathLang, base + '_' + lang + '.ts')
    # No previous translations: nothing to update!
    if not os.path.exists(filename):
        logging.debug(lang.upper(), '\tOriginal translation not found:', filename)
        return ctx
    # Update from found filename
    for line in open(filename, 'r'):
        if '<context>' in line:
            c = False
            s = False
            t = False
            m = ''
        if '<message>' in line:
            s = False
            t = False
            m = ''
        c = tag('name', line, c)
        s = tag('source', line, s)
        t = tag('translation', line, t)
        m = tag('translatorcomment', line, m)
        if '</message>' in line and c and s:
            if not ctx.has_key(c):
                ctx[c] = {}
            s = mescape(s)
            if not t:
                t = ''
            t = mescape(t)
# 			print '\tfound translation:',c,s,t
            ctx[c][s] = (t, m)
    return ctx
Exemplo n.º 19
0
def load_tests(loader, tests, pattern):
    """Discover and load all unit tests"""
    suite = unittest.TestSuite()
    lst = []
    d1, foo = os.path.split(d)
    for dirpath, dirnames, filenames in os.walk(d1):
        # Skip hidden folders
        if dirpath.count('/.') > 0:
            continue
        # Allow only "tests" dirs
        if os.path.sep + 'tests' not in dirpath:
            continue
        # Require an __init__.py file to be present
        if '__init__.py' not in filenames:
            continue
        # Normalize dirpath ending
        if not dirpath.endswith(os.path.sep):
            dirpath = dirpath + os.path.sep
        # if not 'conf/tests' in dirpath:
        # 	continue
        # Remember for future use
        lst.append(dirpath)
    d2 = os.path.split(d1)[0]
    d2 = os.path.split(d2)[0]
    os.chdir(d2)
    # 	os.chdir(d1)
    logging.debug('TESTS from:', d2)
    for i, a in enumerate(lst):
        print i, a
    for dirpath in lst:
        logging.debug('Adding main dir', dirpath)
        for pattern in patterns:
            for all_test_suite in unittest.defaultTestLoader.discover(
                    dirpath, pattern=pattern, top_level_dir=d2):
                for test_suite in all_test_suite:
                    logging.debug('adding', dirpath, test_suite)
                    try:
                        suite.addTests(test_suite)
                    except:
                        logging.debug(format_exc())
    return suite
Exemplo n.º 20
0
def iterpackage(package):
    """Scan a package for all subpackages and all modules containing classes defining conf_def attribute.
    Accept an imported module as argument.
    Returns translations dictionary and missing count."""
    prefix = package.__name__ + "."
    translations = {}
    missing = 0
    for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
        if modname.split('.')[-1] in ('client', 'canon', 'libvideodev', 'utils'):
            logging.debug('skipping', modname)
            continue
        logging.debug("Found submodule %s (is a package: %s)" % (modname, ispkg))
        module = __import__(modname, fromlist="dummy")
        logging.debug("Imported", module)
        translations, ms = collect_conf(module, translations)
        missing += ms
        if ispkg:
            iterpackage(module)
    return translations, missing
Exemplo n.º 21
0
def build(server, remObj, prop, parent=None):
    """Build a property widget based on a property dict"""
    # FIXME: horrible! change package layout to fix this!
    from aBoolean import aBoolean
    from aButton import aButton
    from aChooser import aChooser, async_aChooser
    from aDict import aDict
    from aMeta import aMeta
    from aMaterial import aMaterial
    from aNumber import aNumber
    from aProgress import aProgress, RoleProgress
    from aString import aString
    from aScript import aScript
    from aTable import aTable
    from aProfile import aProfile
    from aTime import aTime, aDelay
    from aFileList import aFileList
    from presets import PresetManager
    from role import Role,  RoleIO
    from cycle import ThermalCycleChooser
    arg = (server, remObj, prop, parent)
    A = prop.get('attr', [])
    T = prop['type']
    if 'Hidden' in A + [T]:
        return False
    obj = False
    try:
        if T in ['String', 'ReadOnly', 'Date', 'FilePath']:
            if prop['handle'] == 'material':
                obj = aMaterial(*arg)
            else:
                obj = aString(*arg)
        elif T == 'FileList':
            obj = aFileList(*arg)
        elif T == 'TextArea':
            obj = aString(server, remObj, prop, parent, extended=True)
        elif T == 'Script':
            obj = aScript(server, remObj, prop, parent)
        elif T == 'Boolean':
            obj = aBoolean(*arg)
        elif T in ['Chooser', 'Menu', 'FileList']:
            choosers = {'motorStatus': async_aChooser}
            chooser = choosers.get(prop['handle'], aChooser)
            obj = chooser(*arg)
        elif T == 'Preset':
            obj = PresetManager(remObj, parent=parent)
        elif T in ['Integer', 'Float']:
            obj = aNumber(*arg)
        elif T == 'Time':
            if prop['kid'] == '/delay':
                obj = aDelay(*arg)
            else:
                obj = aTime(*arg)
        elif T == 'Progress':
            obj = aProgress(*arg)
        elif T == 'Meta':
            obj = aMeta(*arg)
        elif T == 'Button':
            obj = aButton(*arg)
        elif T == 'ThermalCycle':
            obj = ThermalCycleChooser(server.kiln, parent=parent)
        elif T == 'Role':
            obj = Role(*arg)
        elif T == 'RoleIO':
            obj = RoleIO(*arg)
        elif T == 'Table':
            obj = aTable(*arg)
        elif T == 'Profile':
            obj = aProfile(*arg)
        elif prop['kid'] == '/progress':
            obj = RoleProgress(*arg)
    except:
        logging.debug('Building ', prop, 'of', remObj, 'error:')
        logging.debug(format_exc())
        if obj:
            obj.hide()
            obj.close()
            del obj
        return False
    return obj
Exemplo n.º 22
0
if __name__ == '__main__':
    import sys
    from misura.client import iutils, network

    iutils.initApp()
    network.getConnection('localhost:3880')
    srv = network.manager.remote
    qb = QtGui.QWidget()
    lay = QtGui.QFormLayout()
    wgs = []
#    wgs.append(build(srv, srv.hsm, srv.hsm.gete('comment')))
#    wgs.append(aString(srv, srv.hsm, srv.hsm.describe()['comment'], extended=True))
#    wgs.append(aBoolean(srv, srv, srv.describe()['eq_hsm']))
#    wgs.append(aChooser(srv, srv.beholder.idx0, srv.beholder.idx0.gete('Pre-Processing:Flip')))
#    wgs.append(aNumber(srv, srv.beholder.idx0, srv.beholder.idx0.gete('brightness')))
#    wgs.append(aDict(srv, srv.hsm,srv.hsm.gete('Test_Softening')))
#    wgs.append(Role(srv, srv.hsm,srv.hsm.gete('camera')))
#    wgs.append(PresetManager(srv))
#    wgs.append(ThermalCycleChooser(srv.kiln))
#    wgs.append(ServerSelector())
#    wgs.append(ConnectionStatus())
#    wgs.append(aTable(srv, srv.simulator.flexion,srv.simulator.flexion.gete('MultiLayer_material')))
    wgs.append(aProfile(srv, srv.hsm.sample0, srv.hsm.sample0.gete('profile')))
    for wg in wgs:
        logging.debug(wg)
        lay.addRow(wg.label, wg)
    qb.setLayout(lay)
    qb.show()
    sys.exit(QtGui.qApp.exec_())
def tearDownModule():
    logging.debug('tearDownModule', __name__)
def setUpModule():
    logging.debug('setUpModule', __name__)
from misura.canon.logger import Log as logging

from misura.client.tests import iutils_testing as iut
from misura.client.plugin import SurfaceTensionPlugin
from misura.client.plugin.SurfaceTensionPlugin import DensityFunction

import numpy as np


import veusz.document as document
import veusz.datasets as datasets
import veusz.plugins

from PyQt4 import QtGui

logging.debug('Importing', __name__)


def setUpModule():
    logging.debug('setUpModule', __name__)


def tearDownModule():
    logging.debug('tearDownModule', __name__)


def insertData(doc, datadict):
    for key, data in datadict.iteritems():
        ds = datasets.Dataset(data)
        doc.setData(key, ds)