Exemple #1
0
    def get(self):

        self.response.headers["Content-Type"] = "text/html"
        user_id = self.request.GET.get("user_id")
        spectator = True
        follow = "Follow"

        if user_id != None:
            myuser_key = ndb.Key("MyUser", user_id)
            myuser = myuser_key.get()

            tweets = Tweet.query(Tweet.user_id == myuser.key.id()).fetch(50)
            if user_id == str(Definitions().get_login_user().key.id()):
                spectator = False
            if user_id in Definitions().get_login_user().following:
                follow = "Unfollow"

        template_values = {
            "myuser": myuser,
            "follow":follow,
            "tweets":tweets,
            "spectator":spectator,
        }

        template = JINJA_ENVIRONMENT.get_template("editpage.html")
        self.response.write(template.render(template_values))
Exemple #2
0
def assemble(target):
    '''Assemble dependencies and contents recursively until target exists.'''
    if cache.get_cache(target):
        return

    defs = Definitions()
    this = defs.get(target)

    with app.timer(this, 'Starting assembly'):
        with sandbox.setup(this):
            for it in this.get('build-depends', []):
                dependency = defs.get(it)
                assemble(dependency)
                sandbox.install(this, dependency)

            for it in this.get('contents', []):
                component = defs.get(it)
                if component.get('build-mode') == 'bootstrap':
                    continue
                assemble(component)
                sandbox.install(this, component)

            if this.get('build-mode') != 'bootstrap':
                sandbox.ldconfig(this)
            else:
                app.log(this, "No ldconfig because bootstrap mode is engaged")

            build(this)

            if this.get('devices'):
                sandbox.create_devices(this)
            cache.cache(this)
Exemple #3
0
def install_artifact(this, component, permit_bootstrap=True):
    component = Definitions().get(component)
    if component.get('build-mode') == 'bootstrap' and permit_bootstrap == False:
        return
    app.log(this, 'Installing %s' % component['cache'])
    unpackdir = cache.unpack(component)
    utils.hardlink_all_files(unpackdir, this['assembly'])
Exemple #4
0
def deploy(target):
    '''Deploy systems and subsystems recursively'''

    defs = Definitions()
    deployment = target if type(target) is dict else defs.get(target)

    with app.timer(deployment, 'Starting deployment'):
        for system in deployment.get('systems', []):
            deploy(system)
            for subsystem in system.get('subsystems', []):
                deploy(subsystem)

        system = defs.get(deployment['path'])
        if system.get('arch') and system['arch'] != app.settings['arch']:
            app.log(target, 'Skipping deployment for', system['arch'])
            return None

        sandbox.setup(system)
        for name, deployment in deployment.get('deploy', {}).iteritems():
            method = os.path.basename(deployment['type'])
            sandbox.run_extension(system, deployment, 'check', method)
            app.log(system, "Extracting system artifact")
            with open(cache.get_cache(system), "r") as artifact:
                call(['tar', 'x', '--directory', system['sandbox']],
                     stdin=artifact)

            for ext in system.get('configuration-extensions', []):
                sandbox.run_extension(system, deployment, 'configure',
                                      os.path.basename(ext))

            os.chmod(system['sandbox'], 0o755)
            sandbox.run_extension(system, deployment, 'write', method)
        sandbox.remove(system)
Exemple #5
0
    def __init__(self, runtime_env, ini_file="config.ini", os=None):
        self.logger = Logger(log_level=0, console_level=3)
        self.sts = Settings(self.logger, runtime_env, ini_file=ini_file)  # sts
        self.logger.set_console_level(self.sts.debug_level)
        self.logger.set_log_level(0)
        self.comfun = CommonFunctions(self.logger)

        if os is None:
            self.os = platform.system()
            if self.os == "Windows":
                self.os = "w"
            elif self.os == "Linux":
                self.os = "l"
            else:
                self.os = None

        # abbreviation for very often used variables, helping with identification the main modules
        self.usr = Users(self)  # usr
        self.prj = Projects(self)  # prj
        self.sch = Schemas(self)  # sch
        self.tsk = Tasks(self)  # tsk
        self.que = Queue(self)  # que
        self.nod = SimNodes(self)  # nod
        self.dfn = Definitions(self)  # dfn
        self.sio = StorageInOut(self)  # sio
        #  abbreviation  END

        self.logger.inf("SimBatch started")
Exemple #6
0
def clean_env(this):
    env = {}
    extra_path = []
    defs = Definitions()

    if app.settings['no-ccache']:
        ccache_path = []
    else:
        ccache_path = ['/usr/lib/ccache']
        env['CCACHE_DIR'] = '/tmp/ccache'
        env['CCACHE_EXTRAFILES'] = ':'.join(
            f for f in ('/baserock/binutils.meta',
                        '/baserock/eglibc.meta',
                        '/baserock/gcc.meta') if os.path.exists(f))
        if not app.settings.get('no-distcc'):
            env['CCACHE_PREFIX'] = 'distcc'

    prefixes = []

    for name in this.get('build-depends', []):
        dependency = defs.get(name)
        prefixes.append(dependency.get('prefix'))
    prefixes = set(prefixes)
    for prefix in prefixes:
        if prefix:
            bin_path = os.path.join(prefix, 'bin')
            extra_path += [bin_path]

    if this.get('build-mode') == 'bootstrap':
        rel_path = extra_path + ccache_path
        full_path = [os.path.normpath(this['assembly'] + p)
                     for p in rel_path]
        path = full_path + app.settings['base-path']
        env['DESTDIR'] = this.get('install')
    else:
        path = extra_path + ccache_path + app.settings['base-path']
        env['DESTDIR'] = os.path.join('/',
                                      os.path.basename(this.get('install')))

    env['PATH'] = ':'.join(path)
    env['PREFIX'] = this.get('prefix') or '/usr'
    env['MAKEFLAGS'] = '-j%s' % (this.get('max-jobs') or
                                 app.settings['max_jobs'])
    env['TERM'] = 'dumb'
    env['SHELL'] = '/bin/sh'
    env['USER'] = env['USERNAME'] = env['LOGNAME'] = 'tomjon'
    env['LC_ALL'] = 'C'
    env['HOME'] = '/tmp'

    arch = app.settings['arch']
    cpu = 'i686' if arch == 'x86_32' else arch
    abi = 'eabi' if arch.startswith('arm') else ''
    env['TARGET'] = cpu + '-baserock-linux-gnu' + abi
    env['TARGET_STAGE1'] = cpu + '-bootstrap-linux-gnu' + abi
    env['MORPH_ARCH'] = arch

    return env
Exemple #7
0
    def post(self):
        self.response.headers["Content-Type"] = "text/html"

        text_share = self.request.get("text_share")
        share_image = self.request.get("share_image")

        if text_share != None or text_share != "":

            share_type = self.request.get("share_type")

            if share_type == "Update":

                edit_tweet_id = self.request.get("edit_tweet_id")
                edit_tweet = Definitions().get_tweet(tweet_id=edit_tweet_id)
                edit_tweet.text_share = text_share

                edit_tweet.put()

            else:

                myuser = Definitions().get_login_user()
                tweet = Tweet(text_share=text_share,
                              user_id=myuser.key.id(),
                              user_name=myuser.user_name,
                              time=datetime.datetime.now())
                tweet.put()

                myuser.tweets_id.append(tweet.key.id())
                myuser.put()

        self.redirect("/")
Exemple #8
0
def main():

    print("Reads a Wikidictionary XML dump and extracts verbs defintions")
    init_logging()
    start_time = datetime.datetime.now()

    definitions = Definitions()
    definitions.generate('definitions/cawiktionary-latest-pages-meta-current.xml')

    msg = 'Time {0}'.format(datetime.datetime.now() - start_time)
    logging.info(msg)
Exemple #9
0
def install(this, component, permit_bootstrap=True):
    component = Definitions().get(component)
    
    for subcomponent in component.get('contents', []):
        if component.get('build-mode') == 'bootstrap':
            continue
        install(this, subcomponent, False)

    for dependency in component.get('build-depends', []):
        install(this, dependency, False)
    install_artifact(this, component, permit_bootstrap)
    def test_generate(self):

        with tempfile.TemporaryDirectory() as dirpath:
            definitions = Definitions()
            definitions.generate("test/data/definitions.xml", infinitives = 'test/data/infinitives.txt', save_dir = dirpath)

            def_gen = self._hash_file(os.path.join(dirpath, "definitions.txt"))
            def_ref = self._hash_file("test/data/definitions.txt")
            defj_gen = self._hash_file(os.path.join(dirpath, "definitions.json"))
            defj_ref = self._hash_file("test/data/definitions.json")

        self.assertEquals(def_ref, def_gen)
        self.assertEquals(defj_ref, defj_gen)
    def __init__(self, *args, **kwargs):
        self.exit = kwargs.pop('exit', False)
        self.inputs_path = kwargs.pop('inputs_path', None)
        super(StillCanvas, self).__init__(*args, **kwargs)
        gloo.set_state(clear_color='black', blend=True, blend_func=('src_alpha', 'one_minus_src_alpha'))

        self.inputs = None

        if self.inputs_path is not None:
            self.input_manager = FileStoredInput(self.inputs_path)
            self.time = self.input_manager.stored_time
            definition = Definitions[self.input_manager.stored_definition_name]
        else:
            self.input_manager = RandomInput()
            self.time = float(random.randint(0, 345212312))
            definition = Definitions[random.choice(Definitions.keys())]

        self.fractal = FractalProgram(definition, mask=False)

        self.apply_zoom()
        self._timer = app.Timer(1.0 / 5, connect=self.update, start=True)
        if self.exit:
            app.Timer(1, connect=self.write_and_exit, start=True, iterations=1)
        # self.update(None)
        # self.update(None)
        self.show()
Exemple #12
0
 def open_fixes(self):
     ROOT_DIR = Definitions().ROOT_DIR
     location = open(ROOT_DIR + '/icd10_fixes/icd10.txt')
     for line in location:
         if line.startswith('urn'):
             icd_codes = line.split('\t')
             self.fixes[icd_codes[0]] = icd_codes[1].strip('\n').split(',')
 def __init__(self, director, background_match):
     '''
     Constructor
     '''
     Scene.__init__(self, director, background_match)        
     self.definitions = Definitions()
     
     
     for buttom in self.common_buttoms.itervalues():
         buttom.is_visible = True
Exemple #14
0
def assemble(target):
    '''Assemble dependencies and contents recursively until target exists.'''

    if cache.get_cache(target):
        return cache.cache_key(target)

    defs = Definitions()
    this = defs.get(target)

    if this.get('arch') and this['arch'] != app.settings['arch']:
        app.log(target, 'Skipping assembly for', this['arch'])
        return None

    with app.timer(this, 'Starting assembly'):
        sandbox.setup(this)
        for it in this.get('systems', []):
            system = defs.get(it)
            assemble(system)
            for subsystem in this.get('subsystems', []):
                assemble(subsystem)

        dependencies = this.get('build-depends', [])
        random.shuffle(dependencies)
        for it in dependencies:
            dependency = defs.get(it)
            assemble(dependency)
            sandbox.install(this, dependency)

        contents = this.get('contents', [])
        random.shuffle(contents)
        for it in contents:
            component = defs.get(it)
            if component.get('build-mode') != 'bootstrap':
                assemble(component)
                sandbox.install(this, component)

        build(this)
        do_manifest(this)
        cache.cache(this, full_root=this.get('kind', None) == "system")
        sandbox.remove(this)

    return cache.cache_key(this)
Exemple #15
0
def _install(this, component):
    if os.path.exists(os.path.join(this['sandbox'], 'baserock',
                                   component['name'] + '.meta')):
        return

    for it in component.get('build-depends', []):
        dependency = Definitions().get(it)
        if (dependency.get('build-mode', 'staging') ==
                component.get('build-mode', 'staging')):
            _install(this, dependency)

    for it in component.get('contents', []):
        subcomponent = Definitions().get(it)
        if subcomponent.get('build-mode', 'staging') != 'bootstrap':
            _install(this, subcomponent)

    unpackdir = cache.unpack(component)
    if this.get('kind') is 'system':
        utils.copy_all_files(unpackdir, this['sandbox'])
    else:
        utils.hardlink_all_files(unpackdir, this['sandbox'])
Exemple #16
0
    def rotate(self, event=None):
        definition = Definitions[Definitions.keys()[self.definition_position % len(Definitions.keys())]]
        self.fractal = FractalProgram(definition, mask=self.show_mask)

        if self.inputs:
            self.fractal.adjust(self.inputs)
        self.apply_zoom()

        # Only rotate the user tracker if there aren't users actively interacting
        if (not self.input_manager) or not self.input_manager.tracking_users:
            if self.fake_inputs:
                self.input_manager = FakeInput()
            else:
                input_manager_index = (self.input_position / 2) % len(KIOSK_INPUTS) # random.choice(range(len(KIOSK_INPUTS)))
                self.input_manager = KIOSK_INPUTS[input_manager_index]()
                self.mask['tipColorSelector'] = input_manager_index / float(len(KIOSK_INPUTS))

            print "Rotated to %s feeding %s" % (self.input_manager, definition['name'])

        self.definition_position += 1
        self.input_position += 1
class Sce_Definitions(Scene):
    '''
    classdocs
    '''

    def __init__(self, director, background_match):
        '''
        Constructor
        '''
        Scene.__init__(self, director, background_match)        
        self.definitions = Definitions()
        
        
        for buttom in self.common_buttoms.itervalues():
            buttom.is_visible = True

    def on_update(self):
        self.time = self.director.time 
        self.update()
        for key, option in self.definitions.options.iteritems():
            if option.is_pressed:
                self.definitions.load_pages(key, self.director)
                
        self.pages = self.definitions.pages_listed
        if self.pages: self.page = self.definitions.current_page

    def on_event(self, event):
        self.event(event)        
        if event.type == pygame.MOUSEBUTTONDOWN:
            for option in self.definitions.options.itervalues():
                mouse_pos = pygame.mouse.get_pos()
                option.pressed(mouse_pos)
                        

    def on_draw(self, screen):
        self.draw(screen)
        #self.definitions.draw(screen)
        
        
Exemple #18
0
def build(this):
    '''Actually create an artifact and add it to the cache

    This is what actually runs ./configure, make, make install (for example)
    By the time we get here, all dependencies for 'this' have been assembled.
    '''

    app.log(this, 'Start build')
    defs = Definitions()
    if this.get('repo'):
        repos.checkout(this['name'], this['repo'], this['ref'], this['build'])

    get_build_system_commands(defs, this)
    for build_step in buildsystem.build_steps:
        if this.get(build_step):
            app.log(this, 'Running', build_step)
        for command in this.get(build_step, []):
            sandbox.run_sandboxed(this, command)
Exemple #19
0
import sandboxlib

import os
import sys

import app
from assembly import assemble, deploy
from definitions import Definitions
import cache
import sandbox


print('')
app.setup(sys.argv)
with app.timer('TOTAL', '%s starts, version %s' % (app.settings['program'],
               app.settings['program-version'])):
    target = os.path.join(app.settings['defdir'], app.settings['target'])
    app.log('TARGET', 'Target is %s' % target, app.settings['arch'])
    with app.timer('DEFINITIONS', 'Parsing %s' % app.settings['def-version']):
        defs = Definitions()
    with app.timer('CACHE-KEYS', 'Calculating'):
        cache.get_cache(defs, app.settings['target'])
    defs.save_trees()

    sandbox.executor = sandboxlib.executor_for_platform()
    app.log(app.settings['target'], 'Sandbox using %s' % sandbox.executor)

    assemble(defs, app.settings['target'])
    deploy(defs, app.settings['target'])
Exemple #20
0
        component = defs.get(it)
        if component.get('repo'):
            log('AGGREGATE', 'Adding aggregate for', component['name'])
            aggregate += [{'get': component['name']}]
        else:
            log('PASSED', 'Adding passed for', component['name'])
            aggregate += [{'get': component['name']}]
            passed += [component['name']]

    plan = [{'task': 'Build', 'config': config}, {'aggregate': aggregate}]
    job = {'name': target['name'], 'plan': plan, 'passed': passed}
    pipeline = {'resources': inputs(defs, target), 'jobs': [job]}

    output = './pipeline.yml'
    with open(output, 'w') as f:
        f.write(yaml.dump(pipeline, default_flow_style=False))

    exit('CONCOURSE', 'pipeline is at', output)


setup(sys.argv)

with timer('TOTAL'):
    target = os.path.join(config['defdir'], config['target'])
    log('TARGET', 'Target is %s' % target, config['arch'])
    with timer('DEFINITIONS', 'parsing %s' % config['def-version']):
        defs = Definitions()
    with timer('CACHE-KEYS', 'cache-key calculations'):
        cache.cache_key(defs, config['target'])
    write_pipeline(defs, config['target'])
 def test_article_contents_mocked(self, mock_method):
     mock_method.return_value = "A robot is mechanical"
     article = Definitions.article("Robot")
     self.assertIn("mechanical", article)
Exemple #22
0
class SimBatch:
    s = None
    comfun = None
    logger = None
    os = None

    def __init__(self, runtime_env, ini_file="config.ini", os=None):
        self.logger = Logger(log_level=0, console_level=3)
        self.sts = Settings(self.logger, runtime_env, ini_file=ini_file)  # sts
        self.logger.set_console_level(self.sts.debug_level)
        self.logger.set_log_level(0)
        self.comfun = CommonFunctions(self.logger)

        if os is None:
            self.os = platform.system()
            if self.os == "Windows":
                self.os = "w"
            elif self.os == "Linux":
                self.os = "l"
            else:
                self.os = None

        # abbreviation for very often used variables, helping with identification the main modules
        self.usr = Users(self)  # usr
        self.prj = Projects(self)  # prj
        self.sch = Schemas(self)  # sch
        self.tsk = Tasks(self)  # tsk
        self.que = Queue(self)  # que
        self.nod = SimNodes(self)  # nod
        self.dfn = Definitions(self)  # dfn
        self.sio = StorageInOut(self)  # sio
        #  abbreviation  END

        self.logger.inf("SimBatch started")

    def print_data(self):
        self.prj.print_all()

    def print_important_values(self):
        print "  \n\n  Current runtime_env: {}", self.sts.runtime_env

        # projects
        print "\n PROJECTS: "
        self.prj.print_current()

        # schemas
        print "\n SCHEMAS: "
        self.sch.print_current()

        # tasks
        print "\n TASKS: "
        self.tsk.print_current()

        # queue
        print "\n QUEUE: "
        self.que.print_current()

        # nodes
        print "\n NODES: "
        self.nod.print_current()

        # nodes
        print "\n DEFINITIONS: "
        self.dfn.print_current()

        print "\n\n"

    def print_current_detailed_values(self, index):
        print "  \n\n"
        if self.sts.ui_edition_mode == 0:  # open source hide wizard tab
            index += 1  # index compensation

        if index == 0:
            print " WIZARD: "
        if index == 1:
            self.prj.print_all()
            self.prj.print_current()
        if index == 2:
            print " SCHEMAS: "
            self.sch.print_all()
            self.sch.print_current()
        if index == 3:
            print " TASKS: "
            self.tsk.print_all()
            self.tsk.print_current()
        if index == 4:
            print " QUEUE: "
            self.que.print_all()
            self.que.print_current()
        # if index == 5:
        # TODO NODES !!!!
        # self.nod.print_all()
        # self.nod.print_current()

        if index == 5:  # TODO NODES  index 4 vs 5 !
            print " SETTINGS: "
            self.sts.print_all()

        print "\n\n"

    def clear_all_stored_data(self):
        self.prj.clear_all_projects_data(clear_stored_data=True)
        self.sch.clear_all_schemas_data(clear_stored_data=True)

    def clear_all_memory_data(self):
        self.prj.clear_all_projects_data()
        self.sch.clear_all_schemas_data()

    def loading_errors(self, check_this, counter, msg):
        if self.comfun.is_int(check_this):
            counter += check_this
            self.logger.err(
                "Loading error! File: ({}) file errors count:{}".format(
                    msg, check_this))
        return counter

    def load_data(self):
        if self.sts.loading_state >= 3:
            ret_def = self.dfn.load_definitions()
            ret_prj = self.prj.load_projects()
            if ret_prj is not False:
                self.prj.init_default_proj()
                ret_sch = self.sch.load_schemas()
                if ret_sch is not False:
                    ret_tsk = self.tsk.load_tasks()
                    if ret_tsk is not False:
                        ret_que = self.que.load_queue()
                        if ret_que is not False:
                            ret_nod = self.nod.load_nodes()
                            if ret_tsk is not False:
                                loading_err_count = 0  # count number errors while of loading external data
                                loading_err_count = self.loading_errors(
                                    ret_def, loading_err_count, "definitions")
                                loading_err_count = self.loading_errors(
                                    ret_prj, loading_err_count, "project")
                                loading_err_count = self.loading_errors(
                                    ret_sch, loading_err_count, "schemas")
                                loading_err_count = self.loading_errors(
                                    ret_tsk, loading_err_count, "tasks")

                                if loading_err_count == 0:
                                    return True
                                else:
                                    return loading_err_count
                            else:
                                return -5
                        else:
                            return -4
                    else:
                        return -1
                else:
                    return -2
            else:
                return -3
        else:
            return False

    def create_example_data(self):
        self.prj.create_example_project_data()
 def test_article_contents_mocked(self, mock_method):
     mock_method.return_value = "A robot is mechanical"
     article = Definitions.article("Robot")
     self.assertIn("mechanical", article)
#!/usr/bin/env python

import sys

from definitions import Definitions
from html2text import html2text

title = len(sys.argv) == 2 and sys.argv[1] or ""

definition = Definitions.article(title)
txt = html2text(definition)
print txt.encode('utf-8')
 def test_article_success_decorator_mocked(self, mock_method):
     article = Definitions.article("Robot")
     mock_method.assert_called_once_with("Robot")
Exemple #26
0
class SimBatch:
    s = None
    comfun = None
    logger = None
    os = None

    def __init__(self, runtime_env, ini_file="config.ini", os=None):
        self.logger = Logger(log_level=0, console_level=3)
        self.sts = Settings(self.logger, runtime_env, ini_file=ini_file)  # sts
        self.logger.set_console_level(self.sts.debug_level)
        self.logger.set_log_level(0)
        self.comfun = CommonFunctions(self.logger)

        if os is None:
            self.os = platform.system()
            if self.os == "Windows":
                self.os = "w"
            elif self.os == "Linux":
                self.os = "l"
            else:
                self.os = None

        # abbreviation for very often used variables, helping with identification the main modules
        self.usr = Users(
            self,
            mode=1)  # usr  """ users are fully implemented in Pro version """
        self.prj = Projects(self)  # prj
        self.sch = Schemas(self)  # sch
        self.tsk = Tasks(self)  # tsk
        self.que = Queue(self)  # que
        self.nod = SimNodes(self)  # nod
        self.dfn = Definitions(self)  # dfn
        self.sio = StorageInOut(self)  # sio
        self.pat = Patterns()  # pat
        #  abbreviation  END

        self.logger.inf("SimBatch {} started".format(self.sts.get_version()),
                        nl=True,
                        nl_after=True)

    def print_data(self):
        self.prj.print_all()

    def print_important_values(self):
        print "  \n\n  Current runtime_env: {}".format(self.sts.runtime_env)

        # projects
        print "\n PROJECTS: "
        self.prj.print_current()

        # schemas
        print "\n SCHEMAS: "
        self.sch.print_current()

        # tasks
        print "\n TASKS: "
        self.tsk.print_current()

        # queue
        print "\n QUEUE: "
        self.que.print_current()

        # nodes
        print "\n NODES: "
        self.nod.print_current()

        # nodes
        print "\n DEFINITIONS: "
        self.dfn.print_current()

        print "\n\n"

    def print_current_detailed_values(self, index):
        print "  \n\n"
        if self.sts.ui_edition_mode == 0:  # open source no wizard tab
            index += 1  # index compensation

        if index == 0:
            print " WIZARD: "
        if index == 1:
            print " PROJECTS: "
            self.prj.print_all()
            self.prj.print_current()
        if index == 2:
            print " SCHEMAS: "
            self.sch.print_all()
            self.sch.print_current()
        if index == 3:
            print " TASKS: "
            self.tsk.print_all()
            self.tsk.print_current()
        if index == 4:
            print " QUEUE: "
            self.que.print_all()
            self.que.print_current()
        if index == 5:
            print " SIMNODES: "
            self.nod.print_all()
            self.nod.print_current()
        if index == 6:
            print " DEFINITIONS: "
            self.dfn.print_all()
            self.dfn.print_current()
        if index == 7:
            print " SETTINGS: "
            self.sts.print_all()

        print "\n\n"

    def clear_all_stored_data(self):
        self.prj.clear_all_projects_data(clear_stored_data=True)
        self.sch.clear_all_schemas_data(clear_stored_data=True)

    def clear_all_memory_data(self):
        self.prj.clear_all_projects_data()
        self.sch.clear_all_schemas_data()

    def loading_errors(self, check_this, counter, msg):
        if self.comfun.is_int(check_this):
            counter += check_this
            self.logger.err(
                "Loading error! File: ({}) file errors count:{}".format(
                    msg, check_this))
        return counter

    def load_data(self):
        if self.sts.loading_state >= 4:
            ret_def = self.dfn.load_definitions()
            if self.sio.check_any_data_to_load_exist():
                ret_prj = self.prj.load_projects()
                if ret_prj is not False:
                    self.prj.init_default_proj()
                    ret_sch = self.sch.load_schemas()
                    if ret_sch is not False:
                        ret_tsk = self.tsk.load_tasks()
                        if ret_tsk is not False:
                            ret_que = self.que.load_queue()
                            if ret_que is not False:
                                ret_nod = self.nod.load_nodes()
                                if ret_nod is not False:
                                    loading_err_count = 0  # count number errors while of loading external data
                                    loading_err_count = self.loading_errors(
                                        ret_def, loading_err_count,
                                        "definitions")
                                    loading_err_count = self.loading_errors(
                                        ret_prj, loading_err_count, "project")
                                    loading_err_count = self.loading_errors(
                                        ret_sch, loading_err_count, "schemas")
                                    loading_err_count = self.loading_errors(
                                        ret_tsk, loading_err_count, "tasks")
                                    loading_err_count = self.loading_errors(
                                        ret_tsk, loading_err_count, "queue")
                                    loading_err_count = self.loading_errors(
                                        ret_tsk, loading_err_count, "simnodes")
                                    if loading_err_count == 0:
                                        return True, ""
                                    else:
                                        return loading_err_count, "error info in log"
                                else:
                                    return -5, "SimNodes not loaded"
                            else:
                                return -4, "Queue items not loaded"
                        else:
                            return -1, "Tasks data not loaded"
                    else:
                        return -2, "Schemas data not loaded"
                else:
                    return -3, "Projects data not loaded"
            else:
                return -100, "No data exist"
        else:
            return False, "config.ini not loaded"
 def test_article_success_decorator_mocked(self, mock_method):
     article = Definitions.article("Robot")        
     mock_method.assert_called_once_with("Robot")
Exemple #28
0
            os.chdir(os.path.join(os.getcwd(), 'definitions'))
        else:
            if os.path.isdir(os.path.join(os.getcwd(), '..', 'definitions')):
                os.chdir(os.path.join(os.getcwd(), '..', 'definitions'))

app.setup(sys.argv)
app.cleanup(app.config['tmp'])

with app.timer('TOTAL'):
    tmp_lock = open(os.path.join(app.config['tmp'], 'lock'), 'r')
    fcntl.flock(tmp_lock, fcntl.LOCK_SH | fcntl.LOCK_NB)

    target = os.path.join(app.config['defdir'], app.config['target'])
    app.log('TARGET', 'Target is %s' % target, app.config['arch'])
    with app.timer('DEFINITIONS', 'parsing %s' % app.config['def-version']):
        defs = Definitions()
    with app.timer('CACHE-KEYS', 'cache-key calculations'):
        cache.cache_key(defs, app.config['target'])

    cache.cull(app.config['artifacts'])
    target = defs.get(app.config['target'])
    if app.config['total'] == 0 or (app.config['total'] == 1
                                    and target.get('kind') == 'cluster'):
        app.exit('ARCH', 'ERROR: no definitions found for', app.config['arch'])

    defs.save_trees()
    if app.config.get('mode', 'normal') == 'keys-only':
        with open(app.config['result-file'], 'w') as f:
            f.write(target['cache'] + '\n')
        app.log('RESULT', 'Cache-key for target is at',
                app.config['result-file'])
Exemple #29
0
#!/usr/bin/env python

import sys

from definitions import Definitions

title = sys.argv[1]

print Definitions.article(title).encode('utf-8')

Exemple #30
0
"""
Create A Machine, called Product for clarity reasons
	Machine will contain all information about:
		Parts
		Directives that apply
"""
Product = Machine()
Logic = LOGIC(Product)
"""
Load several known definitions
definitions can either be printed as txt, or displayed as html

Idea is, that user can look at definitions and decide if they apply
	#TODO: (machine parts should be able to softly activate definitions)
"""
defs = Definitions()

machineDef_txt, machineDef_html = defs.maschine()
ausweAusr_txt, ausweAusr_html = defs.ausweAusr()
sichBaut_txt, sichBaut_html = defs.sichBaut()
lastMit_txt, lastMit_html = defs.lastMit()
ketten_txt, ketten_html = defs.ketten()
abnGel_txt, abnGel_html = defs.abnGel()
unvMasch_txt, unvMasch_html = defs.unvMasch()
"""
load json
"""
jsonPath = 'json/_exampleMachine.json'
parser = Parser()
data = parser.parse(jsonPath)
"""
Exemple #31
0
def process_instrument(row=None,
                       db=None,
                       refresh=False,
                       tree=None,
                       latest=False,
                       strategy={'links': process_instrument_links}):
    current_app.logger.info('Processing: %s' % row.get('title'))
    if not tree:
        tree = etree.fromstring(row.get('document'), parser=large_parser)
    if not row.get('latest', True):
        tree.attrib['old-version'] = 'true'

    definitions = Definitions()

    extra_formatting(tree, row.get('version'))
    start = time.time()
    tree = strategy['links'](tree, db)
    current_app.logger.debug('Populated Links in %.2f seconds' %
                             (time.time() - start))
    title = unicode(row.get('title').decode('utf-8'))
    start = time.time()
    tree, definitions = populate_definitions(tree,
                                             definitions=definitions,
                                             title=title,
                                             expire=True,
                                             document_id=row.get('id'))

    current_app.logger.debug('Populated Definitions in %.2f seconds' %
                             (time.time() - start))
    definitions = add_parent_definitions(row,
                                         definitions=definitions,
                                         db=db,
                                         strategy=strategy)
    # now mark them

    start = time.time()
    tree, definitions = process_definitions(tree, definitions)
    current_app.logger.debug('Found Definitions in %.2f seconds' %
                             (time.time() - start))

    with (db or get_db()).cursor() as cur:
        query = """UPDATE documents d SET processed_document =  %(doc)s
                    WHERE  d.id =  %(id)s """
        cur.execute(
            query, {
                'id': row.get('id'),
                'doc': etree.tostring(tree, encoding='UTF-8', method="html"),
            })
        defs = definitions.render(document_id=row.get('id'))
        if len(defs):
            current_app.logger.info('New Definitions: %d' % len(defs))
            args_str = ','.join(
                cur.mogrify("(%s,%s,%s,%s,%s,%s,%s)", (
                    row.get('id'), x['id'], x['full_word'], x['keys'],
                    x['html'], x['expiry_tags'], x['priority'])) for x in defs)
            cur.execute("DELETE FROM definitions where document_id = %(id)s",
                        {'id': row.get('id')})
            cur.execute(
                "INSERT INTO definitions (document_id, id, full_word, words, html, expiry_tags, priority) VALUES "
                + args_str)
        if refresh:
            cur.execute("select update_views()")
    (db or get_db()).commit()
    return tree, definitions
Exemple #32
0
def env_vars_for_build(this):
    env = {}
    extra_path = []
    defs = Definitions()
    arch_dict = {
        'i686': "x86_32",
        'armv8l64': "aarch64",
        'armv8b64': "aarch64_be"
    }

    if app.settings['no-ccache']:
        ccache_path = []
    else:
        ccache_path = ['/usr/lib/ccache']
        env['CCACHE_DIR'] = '/tmp/ccache'
        env['CCACHE_EXTRAFILES'] = ':'.join(
            f for f in ('/baserock/binutils.meta',
                        '/baserock/eglibc.meta',
                        '/baserock/gcc.meta') if os.path.exists(f))
        if not app.settings.get('no-distcc'):
            env['CCACHE_PREFIX'] = 'distcc'

    prefixes = []

    for name in this.get('build-depends', []):
        dependency = defs.get(name)
        prefixes.append(dependency.get('prefix', '/usr'))
    prefixes = set(prefixes)
    for prefix in prefixes:
        if prefix:
            bin_path = os.path.join(prefix, 'bin')
            extra_path += [bin_path]

    if this.get('build-mode') == 'bootstrap':
        rel_path = extra_path + ccache_path
        full_path = [os.path.normpath(this['sandbox'] + p)
                     for p in rel_path]
        path = full_path + app.settings['base-path']
        env['DESTDIR'] = this.get('install')
    else:
        path = extra_path + ccache_path + app.settings['base-path']
        env['DESTDIR'] = os.path.join('/',
                                      os.path.basename(this.get('install')))

    env['PATH'] = ':'.join(path)
    env['PREFIX'] = this.get('prefix') or '/usr'
    env['MAKEFLAGS'] = '-j%s' % (this.get('max-jobs') or
                                 app.settings['max-jobs'])
    env['TERM'] = 'dumb'
    env['SHELL'] = '/bin/sh'
    env['USER'] = env['USERNAME'] = env['LOGNAME'] = 'tomjon'
    env['LC_ALL'] = 'C'
    env['HOME'] = '/tmp'
    env['TZ'] = 'UTC'

    arch = app.settings['arch']
    cpu = arch_dict.get(arch, arch)
    abi = 'eabi' if arch.startswith(('armv7', 'armv5')) else ''
    env['TARGET'] = cpu + '-baserock-linux-gnu' + abi
    env['TARGET_STAGE1'] = cpu + '-bootstrap-linux-gnu' + abi
    env['MORPH_ARCH'] = arch
    env['DEFINITIONS_REF'] = app.settings['def-ver']
    env['YBD_REF'] = app.settings['ybd-version']

    return env
Exemple #33
0
            os.chdir(os.path.join(os.getcwd(), 'definitions'))
        else:
            if os.path.isdir(os.path.join(os.getcwd(), '..', 'definitions')):
                os.chdir(os.path.join(os.getcwd(), '..', 'definitions'))

app.setup(sys.argv)
app.cleanup(app.config['tmp'])

with app.timer('TOTAL'):
    tmp_lock = open(os.path.join(app.config['tmp'], 'lock'), 'r')
    fcntl.flock(tmp_lock, fcntl.LOCK_SH | fcntl.LOCK_NB)

    target = os.path.join(app.config['defdir'], app.config['target'])
    app.log('TARGET', 'Target is %s' % target, app.config['arch'])
    with app.timer('DEFINITIONS', 'parsing %s' % app.config['def-version']):
        defs = Definitions()
    with app.timer('CACHE-KEYS', 'cache-key calculations'):
        cache.cache_key(defs, app.config['target'])

    cache.cull(app.config['artifacts'])
    target = defs.get(app.config['target'])
    if app.config['total'] == 0 or (app.config['total'] == 1 and
                                    target.get('kind') == 'cluster'):
        app.exit('ARCH', 'ERROR: no definitions found for', app.config['arch'])

    defs.save_trees()
    if app.config.get('mode', 'normal') == 'keys-only':
        with open('./ybd.result', 'w') as f:
            f.write(target['cache'] + '\n')
        os._exit(0)
 def test_article_failure_decorator_mocked(self, mock_method):
     title = 'lksjdflksjdl'
     article = Definitions.article(title)
     mock_method.assertRaises(ParseError, article, "Your search for {} did not return any results.".format(title))
Exemple #35
0
 def test_article_success(self):
     article = Definitions.article("Robot")
     self.assertIn("mechanical", article)
 def test_article_success_context_manager_mocked(self):
     with patch.object(Wikipedia, 'article') as mock_method:
         article = Definitions.article("Robot")        
         mock_method.assert_called_once_with("Robot")
 def test_article_success(self):
     article = Definitions.article("Robot")        
     self.assertIn("mechanical", article)
Exemple #38
0
    def get(self):

        self.response.headers["Content-Type"] = "text/html"
        user = Definitions().get_current_user()
        myuser = None
        tweets = None
        edit_tweet = None

        if user:

            url = users.create_logout_url(self.request.uri)
            myuser_key = ndb.Key("MyUser", Definitions().get_current_user_id())
            myuser = myuser_key.get()
            user_name = self.request.GET.get("user_name")
            bio = self.request.GET.get("bio")

            if myuser == None:
                myuser = Definitions().create_user(user_id=user.user_id(),
                                                   email_address=user.email())

            if user_name != None and user_name != "" and bio != None and bio != "":

                user_query = MyUser.query(
                    MyUser.user_name == user_name).fetch()

                if len(user_query) > 0:
                    self.redirect("/")
                    return

                myuser.user_name = user_name
                myuser.bio = bio
                myuser.put()

            tweets = Tweet.query().order(-Tweet.time)
            search = self.request.GET.get("query")

            if search == "user" or search == "post":

                search_text = self.request.GET.get("search_text")

                if len(search_text) > 0:

                    if search == "user":
                        tweets = Definitions().search_by_user(text=search_text)
                    else:
                        tweets = Definitions().search_by_tweet(
                            text=search_text)

            elif search == "Delete" or search == "Edit":

                query = self.request.GET.get("query")
                tweet_id = self.request.GET.get("tweet_id")

                if query == "Edit":
                    edit_tweet = Definitions().get_tweet(tweet_id=tweet_id)
                else:
                    Definitions().delete_tweet(tweet_id=tweet_id)

            else:
                tweets = []
                for tweet in Tweet.query().order(-Tweet.time).fetch():
                    if tweet.user_id in myuser.following or tweet.user_id == myuser.key.id(
                    ):
                        tweets.append(tweet)

        else:
            url = users.create_login_url(self.request.uri)

        template_values = {
            "url": url,
            "myuser": myuser,
            "edit_tweet": edit_tweet,
            "tweets": tweets,
            "upload_url": blobstore.create_upload_url('/upload_photo')
        }

        template = JINJA_ENVIRONMENT.get_template("main.html")
        self.response.write(template.render(template_values))
 def test_article_success_context_manager_mocked(self):
     with patch.object(Wikipedia, 'article') as mock_method:
         article = Definitions.article("Robot")
         mock_method.assert_called_once_with("Robot")
Exemple #40
0
#!/usr/bin/env python

import sys

from definitions import Definitions
from html2text import html2text

title = len(sys.argv) == 2 and sys.argv[1] or ""


definition = Definitions.article(title)
txt = html2text(definition)
print txt.encode('utf-8')

Exemple #41
0
    def post(self):

        self.response.headers["Content-Type"] = "text/html"

        user_id = self.request.get("user_id")

        if self.request.get("update") == "Update":

            # if self.request.get("date") =="" or user_id == "":
            #     self.redirect("/editpage")
            #     return

            myuser = Definitions().get_login_user()
            user_first_name = self.request.get("user_first_name")
            user_last_name = self.request.get("user_last_name")
            myuser.first_name = user_first_name
            myuser.last_name = user_last_name
            myuser.put()
            self.redirect("/")

        elif self.request.get("followusers") == "Follow" or self.request.get("followusers") == "Unfollow":

            myuser = Definitions().get_login_user()

            if self.request.get("followusers") == "Follow":
                myuser.following.append(user_id)

            else:
                following = myuser.following
                following.remove(user_id)
                myuser.following = following

            myuser.put()
            self.redirect("/editpage?user_id={}".format(user_id))

        if self.request.get("cancel"):
            self.redirect("/")
Exemple #42
0
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# =*= License: GPL-2 =*=
'''A module to build a definition.'''

import os
import sys
from definitions import Definitions
import cache
import app
from assembly import assemble
import sandbox

target = os.path.splitext(os.path.basename(sys.argv[1]))[0]
arch = sys.argv[2]
with app.setup(target, arch):
    with app.timer('TOTAL', 'YBD starts'):
        defs = Definitions()
        definition = defs.get(target)
        with app.timer('CACHE-KEYS', 'Calculating'):
            cache.get_cache(target)
        defs.save_trees()
        assemble(definition)