Ejemplo n.º 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))
Ejemplo n.º 2
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("/")
Ejemplo n.º 3
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")
Ejemplo n.º 4
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)
Ejemplo n.º 5
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'])
Ejemplo n.º 6
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(',')
Ejemplo n.º 7
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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
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("/")
Ejemplo n.º 12
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)
Ejemplo n.º 13
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'])
Ejemplo n.º 14
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))
Ejemplo n.º 15
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