コード例 #1
0
ファイル: views.py プロジェクト: movermeyer/docklr
def newclusterconfig():
    print request
    tokenUrl = "https://discovery.etcd.io/new"
    if request.method == 'POST':
        # save a new config
        nc = Config()
        nc.cluster_name = request.form['cluster_name']
        try:
            # create the new token
            r = requests.get(tokenUrl)
            cluster_etcd_locator_url = r.text
            nc.cluster_etcd_locator_url = cluster_etcd_locator_url
            db.session.add(nc)
            db.session.commit()
        except Exception:
            pass
        return json.dumps({
            'status': 'OK',
            'cluster': {
                'id': nc.id,
                'cluster_name': nc.cluster_name,
                'cluster_etcd_locator_url': nc.cluster_etcd_locator_url
            }
        })
    else:
        return json.dumps({'status': 'Fail'})
コード例 #2
0
ファイル: home.py プロジェクト: micmejia/MultiMonit
    def dash(self, **params):
        config = Config.readconfig()
        # Attempts to read the config.
        if config == 0:
            # Else it uses the Arguements to create a config.
            # organises make config data
            data = {str(key): str(value) for key, value in params.items()}
            url = []
            for i, v in data.items():
                url.append(v)

            # makes config
            Config.mkconfig(url)
        else:
            # If True it saves the data to a variable
            URLS = config["URLS"]
            refresh = config["refresh"]

        # Runs the script in the Parsing Model. Parses the XML Files from URL
        parse = Parsing.system()
        refresh = config["refresh"]

        # Returns the template with Parsed XML Data and The Refresh Integer from the Config.
        return self.render_template('home/dash.html',
                                    template_vars={
                                        'data': parse,
                                        'refresh': refresh
                                    })
コード例 #3
0
ファイル: home.py プロジェクト: desgyz/MultiMonit
    def dash(self, **params):
        config = Config.readconfig()
        # Attempts to read the config.
        if config == 0:
            # Else it uses the Arguements to create a config.
            # organises make config data
            data = {str(key):str(value) for key,value in params.items()}
            url = []
            for i, v in data.items():
                url.append(v)

            # makes config
            Config.mkconfig(url)
        else:
            # If True it saves the data to a variable
            URLS = config["URLS"]
            refresh = config["refresh"]

        # Runs the script in the Parsing Model. Parses the XML Files from URL
        parse = Parsing.system()
        refresh = config["refresh"]


        # Returns the template with Parsed XML Data and The Refresh Integer from the Config.
        return self.render_template('home/dash.html', template_vars={'data': parse, 'refresh': refresh})
コード例 #4
0
ファイル: admin.py プロジェクト: kisspy/abcms
    def get(self):
        user = self.get_current_user()
        if user:
            logger.error(str(user))
            if user['uid'] > MAX_ADMIN_UID:
                raise tornado.web.HTTPError(404, 'Page Not Found!')
        users_total = yield self.get_users_total()

        users = User.select()

        try:
            config = Config.select().where(Config.id == 1).get()
        except Config.DoesNotExist:
            config = Config()

        msg = self.get_argument('msg', '')
        page = int(self.get_argument('page', '1'))
        page_size = 100
        offset = page_size * (page - 1)

        kwargs = {
            'msg': msg,
            'users': users,
            'users_total': users_total,
            'config': config,
        }
        self.render("admin/system.html", **kwargs)
コード例 #5
0
ファイル: run.py プロジェクト: Hatcat123/PortScan
def check_config():
    '''
    第一次初始化的时候,为配置添加一个初始变量
    :return:
    '''
    conf = session.query(Config).first()
    now_time = int(time.time())
    spider_time = int(
        time.mktime(
            time.strptime(time.strftime("%Y-%m-%d", time.localtime(now_time)),
                          "%Y-%m-%d")) + eval(config.LOOP_TIME))

    if not conf:

        conf = Config(create_time=time.strftime("%Y-%m-%d %H:%M:%S",
                                                time.localtime(spider_time)), )
        session.add(conf)
        session.commit()
        return False
    else:
        spider_time = int(
            time.mktime(
                time.strptime(
                    time.strftime("%Y-%m-%d", time.localtime(now_time)),
                    "%Y-%m-%d")) + eval(conf.loop_time))

        conf.create_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.localtime(spider_time))
        session.commit()
        return True
コード例 #6
0
def seed_config(db):
    print("++ Seeding config")
    a = Config(app_name="My reel2bits instance")
    a.app_description = """This is a reel2bits instance"""
    db.session.add(a)
    db.session.commit()
    db.session.commit()
コード例 #7
0
ファイル: guest.py プロジェクト: zhaozlgit/JimV-C
def r_migrate(uuids, destination_host):

    args_rules = [
        Rules.UUIDS.value,
        Rules.DESTINATION_HOST.value
    ]

    try:
        ji.Check.previewing(args_rules, {'uuids': uuids, 'destination_host': destination_host})

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        # 取全部活着的 hosts
        available_hosts = Host.get_available_hosts(nonrandom=None)

        if available_hosts.__len__() == 0:
            ret['state'] = ji.Common.exchange_state(50351)
            return ret

        available_hosts_mapping_by_node_id = dict()

        for host in available_hosts:
            if host['node_id'] not in available_hosts_mapping_by_node_id:
                available_hosts_mapping_by_node_id[host['node_id']] = host

        guest = Guest()
        for uuid in uuids.split(','):
            guest.uuid = uuid
            guest.get_by('uuid')

        config = Config()
        config.id = 1
        config.get()

        for uuid in uuids.split(','):
            guest.uuid = uuid
            guest.get_by('uuid')

            # 忽略宕机计算节点 上面的 虚拟机 迁移请求
            # 忽略目标计算节点 等于 当前所在 计算节点 的虚拟机 迁移请求
            if guest.node_id not in available_hosts_mapping_by_node_id or \
                    available_hosts_mapping_by_node_id[guest.node_id]['hostname'] == destination_host:
                continue

            message = {
                '_object': 'guest',
                'action': 'migrate',
                'uuid': uuid,
                'node_id': guest.node_id,
                'storage_mode': config.storage_mode,
                'duri': 'qemu+ssh://' + destination_host + '/system'
            }

            Utils.emit_instruction(message=json.dumps(message))

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #8
0
ファイル: hooks.py プロジェクト: kafeinnet/kafeinnet-blog
def set_config(name, value):
    config = Config.query.filter(Config.name==name).first()
    if config is None:
        config = Config(name = name, value=value)
    else:
        config.value = value
    db.session.commit()
    return config.value
コード例 #9
0
def is_open_or_close():
    c = Config.query().get()
    if not c:
        c = Config()
        c.is_open = False
        c.put()
        return False
    return c.is_open
コード例 #10
0
def r_delete(ids):
    ret = dict()
    ret['state'] = ji.Common.exchange_state(20000)

    config = Config()
    config.id = 1
    config.get()

    # 取全部活着的 hosts
    available_hosts = Host.get_available_hosts(nonrandom=None)

    if available_hosts.__len__() == 0:
        ret['state'] = ji.Common.exchange_state(50351)
        return ret

    chosen_host = available_hosts[0]
    node_id = chosen_host['node_id']

    os_template_image = OSTemplateImage()

    # TODO: 加入对,是否有被 Guest 引用的判断
    for _id in ids.split(','):
        os_template_image.id = _id
        os_template_image.get()

    for _id in ids.split(','):
        os_template_image.id = _id
        os_template_image.get()

        # 暂时不支持从计算节点上,删除公共镜像
        if os_template_image.kind == OSTemplateImageKind.public.value:
            os_template_image.delete()
            continue

        elif os_template_image.kind == OSTemplateImageKind.custom.value:
            os_template_image.progress = 254

            message = {
                '_object': 'os_template_image',
                'action': 'delete',
                'storage_mode': config.storage_mode,
                'dfs_volume': config.dfs_volume,
                'template_path': os_template_image.path,
                # uuid 这里没有实际意义,仅仅是为了迁就 JimV-C 的个命令格式
                'uuid': None,
                'node_id': node_id,
                'os_template_image_id': os_template_image.id,
                'passback_parameters': {
                    'id': os_template_image.id
                }
            }

            Utils.emit_instruction(message=json.dumps(message))

            os_template_image.update()

    return ret
コード例 #11
0
def r_resize(uuid, size):

    args_rules = [
        Rules.UUID.value,
        Rules.DISK_SIZE_STR.value
    ]

    try:
        ji.Check.previewing(args_rules, {'uuid': uuid, 'size': size})

        disk = Disk()
        disk.uuid = uuid
        disk.get_by('uuid')

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        if disk.size >= int(size):
            ret['state'] = ji.Common.exchange_state(41257)
            return ret

        config = Config()
        config.id = 1
        config.get()

        disk.size = int(size)
        disk.quota(config=config)
        # 将在事件返回层(models/event_processor.py:224 附近),更新数据库中 disk 对象

        message = {
            '_object': 'disk',
            'action': 'resize',
            'uuid': disk.uuid,
            'guest_uuid': disk.guest_uuid,
            'storage_mode': config.storage_mode,
            'size': disk.size,
            'dfs_volume': config.dfs_volume,
            'node_id': disk.node_id,
            'image_path': disk.path,
            'disks': [disk.__dict__],
            'passback_parameters': {'size': disk.size}
        }

        if config.storage_mode in [StorageMode.shared_mount.value, StorageMode.ceph.value,
                                   StorageMode.glusterfs.value]:
            message['node_id'] = Host.get_lightest_host()['node_id']

        if disk.guest_uuid.__len__() == 36:
            message['device_node'] = dev_table[disk.sequence]

        Utils.emit_instruction(message=json.dumps(message, ensure_ascii=False))

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #12
0
ファイル: guest.py プロジェクト: constct/JimV-C
def r_detach_disk(disk_uuid):

    args_rules = [Rules.DISK_UUID.value]

    try:
        ji.Check.previewing(args_rules, {'disk_uuid': disk_uuid})

        disk = Disk()
        disk.uuid = disk_uuid
        disk.get_by('uuid')

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        if disk.state != DiskState.mounted.value or disk.sequence == 0:
            # 表示未被任何实例使用,已被分离
            # 序列为 0 的表示实例系统盘,系统盘不可以被分离
            # TODO: 系统盘单独范围其它状态
            return ret

        guest = Guest()
        guest.uuid = disk.guest_uuid
        guest.get_by('uuid')

        # 判断 Guest 是否处于可用状态
        if guest.status in (status.GuestState.no_state.value,
                            status.GuestState.dirty.value):
            ret['state'] = ji.Common.exchange_state(41259)
            return ret

        config = Config()
        config.id = 1
        config.get()

        guest_xml = GuestXML(guest=guest, disk=disk, config=config)

        message = {
            '_object': 'guest',
            'action': 'detach_disk',
            'uuid': disk.guest_uuid,
            'node_id': guest.node_id,
            'xml': guest_xml.get_disk(),
            'passback_parameters': {
                'disk_uuid': disk.uuid
            }
        }

        Utils.emit_instruction(message=json.dumps(message))

        disk.state = DiskState.unloading.value
        disk.update()

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #13
0
 def calc_step_value(self, *args):
     self._motor.stop()
     revolve_time = time.ticks_diff(time.ticks_ms(), self._found_home_at)
     step_time = revolve_time // 8
     # self._slot_disp = self._motor.position / 8
     self._slot_disp = step_time
     self.log.info("calc slot displacement: %s" % self._slot_disp)
     Config.create(key="black.slot_displacement",
                   value=str(self._slot_disp))
     self._status = self.READY
コード例 #14
0
def set_auth_secret(secret):
    """
    Sets the auth secret.
    """
    from models import Config
    secret_config = Config()
    secret_config.key = "auth_secret"
    secret_config.value = secret
    secret_config.put()
    return secret_config
コード例 #15
0
ファイル: database.py プロジェクト: codelobber/geotrans
def init_db():
    # Create the fixtures
    point = Point(name='John Smith',
                  latitude='0',
                  longitud='0.1',
                  phone='+79000000000')
    point.save()

    config = Config(version=1, allowedRadius=1000, isDayPeriodAllowed=True)
    config.save()
コード例 #16
0
def config_list(user):
    if request.method == "GET":
        configs = [c.json() for c in user.configs]
        return _json_response(configs)
    elif request.method == "POST":
        if request.json is None:
            return Response(status=400)
        c = Config(user, request.json)
        db.session.add(c)
        db.session.commit()
        return _json_response(c.json())
コード例 #17
0
 def position(self, value):
     try:
         val_exists = any(Config.get_id("motor.position"))
     except KeyError:
         val_exists = False
     self._pos = value
     if not val_exists:
         Config.create(key="motor.position", value=str(value))
         return self._pos
     Config.update({"key": "motor.position"}, value=str(value))
     return self._pos
コード例 #18
0
def r_delete(uuids):

    args_rules = [
        Rules.UUIDS.value
    ]

    try:
        ji.Check.previewing(args_rules, {'uuids': uuids})

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        disk = Disk()

        # 检测所指定的 UUDIs 磁盘都存在
        for uuid in uuids.split(','):
            disk.uuid = uuid
            disk.get_by('uuid')

            # 判断磁盘是否与虚拟机处于离状态
            if disk.state not in [DiskState.idle.value, DiskState.dirty.value]:
                ret['state'] = ji.Common.exchange_state(41256)
                return ret

        config = Config()
        config.id = 1
        config.get()

        # 执行删除操作
        for uuid in uuids.split(','):
            disk.uuid = uuid
            disk.get_by('uuid')

            message = {
                '_object': 'disk',
                'action': 'delete',
                'uuid': disk.uuid,
                'storage_mode': config.storage_mode,
                'dfs_volume': config.dfs_volume,
                'node_id': disk.node_id,
                'image_path': disk.path
            }

            if config.storage_mode in [StorageMode.shared_mount.value, StorageMode.ceph.value,
                                       StorageMode.glusterfs.value]:
                message['node_id'] = Host.get_lightest_host()['node_id']

            Utils.emit_instruction(message=json.dumps(message, ensure_ascii=False))

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #19
0
ファイル: views.py プロジェクト: spiermar/yakin-tracker
def load_instagram():
    access_token = Config.query(Config.name == 'instagram_access_token').order(-Config.date_added).get()

    if access_token is None:
        return Response(json.dumps({ 'error': 'instagram_access_token configuration was not found.' }), status=500, mimetype='application/json');

    client_secret = Config.query(Config.name == 'instagram_client_secret').order(-Config.date_added).get()

    if client_secret is None:
        return Response(json.dumps({ 'error': 'instagram_client_secret configuration was not found.' }), status=500, mimetype='application/json');

    return instagram_import.import_media(access_token.value, client_secret.value)
コード例 #20
0
ファイル: guest.py プロジェクト: zhaozlgit/JimV-C
def r_delete(uuids):

    args_rules = [
        Rules.UUIDS.value
    ]

    # TODO: 加入是否删除使用的数据磁盘开关,如果为True,则顺便删除使用的磁盘。否则解除该磁盘被使用的状态。
    try:
        ji.Check.previewing(args_rules, {'uuids': uuids})

        guest = Guest()
        # 检测所指定的 UUDIs 实例都存在
        for uuid in uuids.split(','):
            guest.uuid = uuid
            guest.get_by('uuid')

        config = Config()
        config.id = 1
        config.get()

        # 执行删除操作
        for uuid in uuids.split(','):
            guest.uuid = uuid
            guest.get_by('uuid')

            message = {
                '_object': 'guest',
                'action': 'delete',
                'uuid': uuid,
                'storage_mode': config.storage_mode,
                'dfs_volume': config.dfs_volume,
                'node_id': guest.node_id
            }

            Utils.emit_instruction(message=json.dumps(message))

            # 删除创建失败的 Guest
            if guest.status == status.GuestState.dirty.value:
                disk = Disk()
                disk.uuid = guest.uuid
                disk.get_by('uuid')

                if disk.state == status.DiskState.pending.value:
                    disk.delete()
                    guest.delete()
                    SSHKeyGuestMapping.delete_by_filter(filter_str=':'.join(['guest_uuid', 'eq', guest.uuid]))

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)
        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #21
0
def r_delete(uuids):

    args_rules = [Rules.UUIDS.value]

    try:
        ji.Check.previewing(args_rules, {'uuids': uuids})

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        disk = Disk()

        # 检测所指定的 UUDIs 磁盘都存在
        for uuid in uuids.split(','):
            disk.uuid = uuid
            disk.get_by('uuid')

            if disk.state != DiskState.idle.value:
                ret['state'] = ji.Common.exchange_state(41256)
                return ret

        config = Config()
        config.id = 1
        config.get()

        # 执行删除操作
        for uuid in uuids.split(','):
            disk.uuid = uuid
            disk.get_by('uuid')

            message = {
                '_object': 'disk',
                'action': 'delete',
                'uuid': disk.uuid,
                'storage_mode': config.storage_mode,
                'dfs_volume': config.dfs_volume,
                'hostname': disk.on_host,
                'image_path': disk.path
            }

            if disk.on_host == 'shared_storage':
                message['hostname'] = Guest.get_lightest_host()['hostname']

            Guest.emit_instruction(
                message=json.dumps(message, ensure_ascii=False))

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #22
0
def r_get():

    config = Config()

    try:
        config.id = 1
        config.get()

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)
        ret['data'] = config.__dict__
        return ret
    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #23
0
ファイル: views.py プロジェクト: drichner/docklr
def addclusterconfig():
    print request
    if request.method == 'POST':
        # save a new config
        nc = Config()
        nc.cluster_name = request.form['cluster_name']
        nc.cluster_etcd_locator_url = request.form['cluster_etcd_locator_url']
        nc.private_key = request.form['primary_key']
        db.session.add(nc)
        db.session.commit()
        return json.dumps({'status': 'OK', 'cluster': {'id': nc.id, 'cluster_name': nc.cluster_name,
                                                       'cluster_etcd_locator_url': nc.cluster_etcd_locator_url}})
    else:
        print request
コード例 #24
0
def r_resize(uuid, size):

    args_rules = [Rules.UUID.value, Rules.DISK_SIZE_STR.value]

    try:
        ji.Check.previewing(args_rules, {'uuid': uuid, 'size': size})

        disk = Disk()
        disk.uuid = uuid
        disk.get_by('uuid')

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)

        if disk.size >= size:
            ret['state'] = ji.Common.exchange_state(41257)
            return ret

        config = Config()
        config.id = 1
        config.get()

        message = {
            '_object': 'disk',
            'action': 'resize',
            'uuid': disk.uuid,
            'guest_uuid': disk.guest_uuid,
            'storage_mode': config.storage_mode,
            'size': int(size),
            'dfs_volume': config.dfs_volume,
            'hostname': disk.on_host,
            'image_path': disk.path,
            'passback_parameters': {
                'size': size
            }
        }

        if disk.on_host == 'shared_storage':
            message['hostname'] = Guest.get_lightest_host()['hostname']

        if disk.guest_uuid.__len__() == 36:
            message['device_node'] = dev_table[disk.sequence]

        Guest.emit_instruction(message=json.dumps(message, ensure_ascii=False))

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #25
0
def update_config(req, resp):
    """Update configuration variables."""
    req.parse_qs()
    ssid = req.form.get("ssid", None)
    power = req.form.get("power", None)
    if ssid:
        Log.info("wifi config update inbound: " + ssid)
        Config.create(key="wifi.ssid", value=ssid)
        Config.create(key="wifi.passwd", value=req.form.get("pass", ""))
        Log.info("config saved! rebooting...")
        machine.reset()
    if power:
        Log.info("power toggle update inbound: %s" % power)
        app.black.set_power(enabled=int(power))
        yield from json_response(resp, power=power)
コード例 #26
0
ファイル: views.py プロジェクト: jmangi13/yakin-tracker
def load_tracker():
    tracker_url = Config.query(Config.name == 'tracker_url').order(-Config.date_added).get()
    if tracker_url is None:
        return Response(json.dumps({ 'error': 'tracker_url configuration was not found.' }), status=500, mimetype='application/json');

    tracker_type = Config.query(Config.name == 'tracker_type').order(-Config.date_added).get()
    if tracker_type is None:
        return Response(json.dumps({ 'error': 'tracker_type configuration was not found.' }), status=500, mimetype='application/json');

    if tracker_type.value == 'delorme':
        return delorme.load_data(tracker_url.value)
    elif tracker_type.value == 'spot':
        return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
    else:
        return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
コード例 #27
0
ファイル: views.py プロジェクト: fspot/zenfeed
def api_edit_config():
    config = Config.get()
    # update all fields, no checks (TODO)
    config_fields = config.fields_set(exclude_fields=['id', 'password'])
    fields = config_fields & set(request.json.keys())
    for field in fields:
        setattr(config, field, request.json[field])
    # change password if the "pw" field isnt empty
    pw = request.json.get('pw')
    if pw:
        Config.change_password(pw)
    db.session.merge(config)
    db.session.commit()
    Config.refresh_instance()  # not necessary ?
    return jsonify({'msg': 'Success !'})
コード例 #28
0
ファイル: utils.py プロジェクト: easyctf/openctf-docker
def get_ssh_keys():
	private_key = get_config("private_key")
	public_key = get_config("public_key")
	if not (private_key and public_key):
		key = RSA.generate(2048)
		private_key = key.exportKey("PEM")
		public_key = key.publickey().exportKey("OpenSSH")
		with app.app_context():
			private = Config("private_key", private_key)
			public = Config("public_key", public_key)
			db.session.add(private)
			db.session.add(public)
			db.session.commit()
			db.session.close()
	return private_key, public_key
コード例 #29
0
 def reload_config(self):
     try:
         config=Config.select().where(Config.id==1).get()
     except:
         config=Config(sitename='ABCcms', siteurl='http://localhost')
     config_keys=config._meta.fields.keys()
     print config_keys
     config_keys.remove('id')
     config_keys.remove('created_at')
     config_keys.remove('updated_at')
     for key in config_keys:
         if not hasattr(self,key):
             setattr(self,key,getattr(config, key))
         else:
             setattr(self,key,getattr(config, key))
コード例 #30
0
ファイル: views.py プロジェクト: fspot/zenfeed
def api_edit_config():
    config = Config.get()
    # update all fields, no checks (TODO)
    config_fields = config.fields_set(exclude_fields=['id', 'password'])
    fields = config_fields & set(request.json.keys())
    for field in fields:
        setattr(config, field, request.json[field])
    # change password if the "pw" field isnt empty
    pw = request.json.get('pw')
    if pw:
        Config.change_password(pw)
    db.session.merge(config)
    db.session.commit()
    Config.refresh_instance()  # not necessary ?
    return jsonify({'msg': 'Success !'})
コード例 #31
0
ファイル: views.py プロジェクト: heidsoft/bk_log_search
def query_config(request):
    """
    @summary:配置记录
    """
    form = QueryForm(request.GET)
    if not form.is_valid():
        return render_json({"data": [], "total_count": 0, "status": False})

    sort = form.cleaned_data['sort']
    if not sort:
        sort = "-id"

    config_list = Config.objects.filter(
        app_id=form.cleaned_data["app_id"]).order_by(sort, "-id")
    total = config_list.count()

    start = form.cleaned_data['offset']
    end = start + form.cleaned_data['length']

    config_json = Config.to_json(config_list[start:end])

    return render_json({
        "status": True,
        'data': config_json,
        'total_count': total,
    })
コード例 #32
0
ファイル: logger.py プロジェクト: micmejia/MultiMonit
    def logall():
        config = Config.readconfig()
        while config != 0:
            url = config["URLS"]

            if os.path.exists("logs"):
                pass
            else:
                os.mkdir("logs")

            thread_list = []

            for m in url:
                # Instantiates the thread
                # (i) does not make a sequence, so (i,)
                t = threading.Thread(target=logs.log, args=(m, ))
                # Sticks the thread in a list so that it remains accessible
                thread_list.append(t)

            # Starts threads
            for thread in thread_list:
                thread.start()

            # This blocks the calling thread until the thread whose join() method is called is terminated.
            # From http://docs.python.org/2/library/threading.html#thread-objects
            for thread in thread_list:
                thread.join()
コード例 #33
0
def admin_settings_update():
	params = utils.flat_multi(request.form)
	params.pop("csrf_token")
	with app.app_context():
		for key in params:
			config = Config.query.filter_by(key=key).first()
			if config is None:
				config = Config(key, params[key])
			else:
				new = params[key]
				if config.value != new:
					config.value = params[key]
			db.session.add(config)
		db.session.commit()

	return { "success": 1, "message": "Success!" }
コード例 #34
0
def index(req, resp):
    try:
        ssid = Config.get_id("wifi.ssid")[0].value
    except KeyError:
        ssid = "300black Anneal8tor (AP)"
    yield from picoweb.start_response(resp)
    yield from app.render_template(resp, "index.tpl", ("ON", ssid))
コード例 #35
0
ファイル: main.py プロジェクト: zhaozlgit/JimV-C
def r_before_request():
    try:
        g.ts = ji.Common.ts()
        if not is_not_need_to_auth(request.endpoint) and request.blueprint is not None and request.method != 'OPTIONS':
            g.config = Config()
            g.config.id = 1
            g.config.get()

            token = session.get('token', '')
            g.token = Utils.verify_token(token)

            user = User()
            user.id = g.token['uid']

            try:
                user.get()
            except ji.PreviewingError, e:
                # 如果该用户获取失败,则清除该用户对应的session。因为该用户可能已经被删除。
                for key in session.keys():
                    session.pop(key=key)
                return json.loads(e.message)

    except ji.JITError, e:
        ret = json.loads(e.message)

        if ret['state']['code'] == '404':
            return redirect(location=url_for('v_config.create'), Response=Response)

        if ret['state']['sub']['code'] in ['41208']:
            return redirect(location=url_for('v_misc.login'), Response=Response)

        return ret
コード例 #36
0
def new_feed_worker(url, favicon_dir, answer_box, manager_box):
    logger.info("Fetching feed... [%s]", url)
    try:
        fetched = fetch_and_parse_feed(url)
        feed_dict, real_url = fetched['feed'], fetched['real_url']
    except FetchingException:
        return answer_box.put(Exception("Error with feed: " + url))

    feed = FeedFromDict(feed_dict, Config.get())
    feed.url = sanitize_url(real_url)  # set the real feed url
    logger.info("Fetching favicon... [%s]", feed.url)
    feed.favicon_path = save_favicon(fetch_favicon(feed.url), favicon_dir)
    db.session.add(feed)
    for e in feed_dict['entries'][::-1]:
        entry = EntryFromDict(e, feed.url)
        entry.feed = feed  # set the corresponding feed
        db.session.add(entry)
    db.session.commit()

    most_recent_entry = feed.entries.order_by(Entry.updated.desc()).first()
    feed.updated = most_recent_entry.updated
    db.session.commit()

    answer_box.put(feed)
    manager_box.put({'type': 'new-deadline-worker', 'feed_id': feed.id})
    manager_box.put({'type': 'refresh-cache', 'feed_id': feed.id})
コード例 #37
0
ファイル: logger.py プロジェクト: desgyz/MultiMonit
    def logall():
        config = Config.readconfig()
        while config != 0:
            url = config["URLS"]

            if os.path.exists("logs"):
                pass
            else:
                os.mkdir("logs")

            thread_list = []

            for m in url:
                # Instantiates the thread
                # (i) does not make a sequence, so (i,)
                t = threading.Thread(target=logs.log, args=(m,))
                # Sticks the thread in a list so that it remains accessible
                thread_list.append(t)

            # Starts threads
            for thread in thread_list:
                thread.start()

            # This blocks the calling thread until the thread whose join() method is called is terminated.
            # From http://docs.python.org/2/library/threading.html#thread-objects
            for thread in thread_list:
                thread.join()
コード例 #38
0
ファイル: home.py プロジェクト: desgyz/MultiMonit
    def confirmed(self, **params):
        url = []
        # setup update config data
        for k, v in params.items():
            if k != "refresh" and k != "time":
                url.append(v)
            elif k == "refresh":
                refresh = v
            elif k == "time":
                time = v

        # update config
        Config.updateconfig(url, refresh, time)

        # redirect to dashboard
        raise cherrypy.HTTPRedirect("dash")
コード例 #39
0
ファイル: workers.py プロジェクト: fspot/zenfeed
def new_feed_worker(url, favicon_dir, answer_box, manager_box):
    logger.info("Fetching feed... [%s]", url)
    try:
        fetched = fetch_and_parse_feed(url)
        feed_dict, real_url = fetched['feed'], fetched['real_url']
    except FetchingException:
        return answer_box.put(Exception("Error with feed: " + url))

    feed = FeedFromDict(feed_dict, Config.get())
    feed.url = sanitize_url(real_url) # set the real feed url
    logger.info("Fetching favicon... [%s]", feed.url)
    feed.favicon_path = save_favicon(fetch_favicon(feed.url), favicon_dir)
    db.session.add(feed)
    for e in feed_dict['entries'][::-1]:
        entry = EntryFromDict(e, feed.url)
        entry.feed = feed # set the corresponding feed
        db.session.add(entry)
    db.session.commit()

    most_recent_entry = feed.entries.order_by(Entry.updated.desc()).first()
    feed.updated = most_recent_entry.updated
    db.session.commit()

    answer_box.put(feed)
    manager_box.put({'type': 'new-deadline-worker', 'feed_id': feed.id})
    manager_box.put({'type': 'refresh-cache', 'feed_id': feed.id})
コード例 #40
0
def run():
    if len(sys.argv) < 3:
        print("** Usage: python3 " + sys.argv[0] +
              " <<Model Directory>> <<Test Set>>")
        sys.exit(1)

    np.random.seed(42)
    model_dir = sys.argv[1]
    config = Config.load(
        ['./default.conf',
         os.path.join(model_dir, 'model.conf')])
    model = create_model(config)
    test_data = load_data(sys.argv[2], config.dictionary, config.grammar,
                          config.max_length)
    print("unknown", unknown_tokens)

    with tf.Graph().as_default():
        tf.set_random_seed(1234)
        with tf.device('/cpu:0'):
            model.build()

            test_eval = Seq2SeqEvaluator(model,
                                         config.grammar,
                                         test_data,
                                         'test',
                                         config.reverse_dictionary,
                                         beam_size=config.beam_size,
                                         batch_size=config.batch_size)
            loader = tf.train.Saver()

            with tf.Session() as sess:
                loader.restore(sess, os.path.join(model_dir, 'best'))
                test_eval.eval(sess, save_to_file=True)
コード例 #41
0
ファイル: home.py プロジェクト: micmejia/MultiMonit
    def confirmed(self, **params):
        url = []
        # setup update config data
        for k, v in params.items():
            if k != "refresh" and k != "time":
                url.append(v)
            elif k == "refresh":
                refresh = v
            elif k == "time":
                time = v

        # update config
        Config.updateconfig(url, refresh, time)

        # redirect to dashboard
        raise cherrypy.HTTPRedirect("dash")
コード例 #42
0
    def run(self):
        logger.info('Starting alcazard with state at {}.', self.state_path)

        if not os.path.isfile(self.db_path):
            print('Missing state DB at {}! Exiting.'.format(self.db_path))
            exit(1)

        DB.init(self.db_path)
        DB.connect()
        self._init_db()

        config = Config.get()
        config.db_path = self.db_path
        config.state_path = self.state_path

        orchestrator = None
        if config.is_fully_configured:
            orchestrator = AlcazarOrchestrator(config)
            orchestrator.attach()

        api = AlcazarAPI(config, orchestrator)
        api.run()

        if orchestrator:
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            loop.run_until_complete(orchestrator.shutdown())

        DB.close()

        logger.info('Graceful shutdown done.')
コード例 #43
0
ファイル: views.py プロジェクト: agvergara/HotelDiscover
def register(request):
	if request.method == "GET":
		template = get_template('registration/register.html')
		context = RequestContext(request, {})
		return HttpResponse(template.render(context))
	elif request.method == "POST":
		username = strip_tags(request.POST.get('username'))
		password = make_password(request.POST.get('password'))
		title = "Pagina de " + username
		user = User(username=username, password=password)
		user.save()
		user = User.objects.get(username=username)
		config = Config(user=user, title=title, color='#D7C4B7', size=14)
		config.save()
		return HttpResponseRedirect("/")
	else:
		template = get_template('notfound.html')
		return HttpResponseNotFound(template.render())
コード例 #44
0
ファイル: home.py プロジェクト: desgyz/MultiMonit
    def settings(self):
        # get config data
        config = Config.readconfig()
        URLS = config["URLS"]
        refresh = config["refresh"]
        times = config["time"]

        # Return the template
        return self.render_template('home/settings.html', template_vars={'refresh': refresh, 'urls': URLS, 'time': times})
コード例 #45
0
ファイル: home.py プロジェクト: desgyz/MultiMonit
 def index(self):
     config = Config.readconfig()
     # Check if there is a config.
     if config != 0:
         # Else redirect the User to the Dashboard
         raise cherrypy.HTTPRedirect("Home/dash")
     else:
         # If True Return the template
         return self.render_template('home/index.html')
コード例 #46
0
ファイル: server.py プロジェクト: no2key/PyF5
 def config(self):
     if not hasattr(self, '_config'):
         path = config_path()
         if os.path.exists(path):
             self._config = Config.load(path)
         else:
             self._config = Config()
             self._config.path = path
     return self._config
コード例 #47
0
ファイル: service.py プロジェクト: palestamp/owl
 def set_working_tree(self, working_tree):
     self.unset_current_working_tree()
     new_working_tree, created = Config.get_or_create(**{
         'type': 'working_tree',
         'status': 0,
         'data': working_tree.replace('%', '*')
     })
     new_working_tree.status = 1
     new_working_tree.save()
コード例 #48
0
def lists(candidate_studies, user, annotation_class = None):
    from models import Config

    study_list = (hasattr(user, 'study_list') and user.study_list) or Config.get_solo().default_study_list
    # if no lists are configured, just pass thru
    if not study_list:
        return candidate_studies

    studies = study_list.studies.exclude(radiologystudyreview__user_id = user.id)
    return studies
コード例 #49
0
    def post(self):
        pivotal_project_id = self.request.get('pivotal_project_id')
        pivotal_auth_token = self.request.get('pivotal_auth_token')

        config = Config.get_app_config()
        config.pivotal_project_id = pivotal_project_id
        config.pivotal_auth_token = pivotal_auth_token
        config.put()
        
        self.render_template(config)
コード例 #50
0
ファイル: service.py プロジェクト: palestamp/owl
    def build_config_records_filter():
        mapping = {'working_tree': 'nest'}
        query_str = ''
        for filter_ in Config.select().where(
                        Config.status == 1 & Config.type << ['working_tree']):

            mapping_result = mapping.get(filter_.type)
            if mapping_result:
                query_str += mapping_result + '::' + filter_.data
        return query_str
コード例 #51
0
def get_auth_secret():
    """
    Returns the secret required to update the click counter configuration.

    If no secret is configured, a random secret is generated and persisted.
    """
    from models import Config
    secret_config = Config.query(Config.key == "auth_secret").get()
    if not secret_config:
        secret_config = set_auth_secret(''.join(random.choice(string.lowercase) for i in range(10)))
    return secret_config.value
コード例 #52
0
ファイル: views.py プロジェクト: drichner/docklr
def newclusterconfig():
    print request
    tokenUrl = "https://discovery.etcd.io/new"
    if request.method == 'POST':
        # save a new config
        nc = Config()
        nc.cluster_name = request.form['cluster_name']
        try:
            # create the new token
            r = requests.get(tokenUrl)
            cluster_etcd_locator_url = r.text
            nc.cluster_etcd_locator_url = cluster_etcd_locator_url
            db.session.add(nc)
            db.session.commit()
        except Exception:
            pass
        return json.dumps({'status': 'OK','cluster': {'id': nc.id, 'cluster_name': nc.cluster_name,
                                                       'cluster_etcd_locator_url': nc.cluster_etcd_locator_url}})
    else:
        return json.dumps({'status': 'Fail'})
コード例 #53
0
ファイル: service.py プロジェクト: palestamp/owl
    def load_function(self, name, function_source):
        if not is_identifier(name):
            raise NameError('{} invalid identifier for python module'.format(name))

        new_function, created = Config.get_or_create(**{
            'type': 'function',
            'status': 0,
            'name': name,
            'data': function_source
        })
        return new_function, created
コード例 #54
0
ファイル: pipeline.py プロジェクト: Teectac/twevents
def create_default_configs(request, user, is_new, **kwargs):
    if is_new:
        cf = Config()
        cf.name = "Default config"
        cf.user = user
        cf.sv_motd = 'Standard capture the flag game'
        cf.save()
コード例 #55
0
def config_item(user, cid):
    config = Config.query.filter(Config.user_id == user.id).filter(Config.id == cid)
    if request.method == "PUT":
        if request.json is None:
            return Response(status=400)
        try:
            config = config.one()
            config.update(request.json)
        except NoResultFound:
            config = Config(user, request.json)
            db.session.add(config)
        db.session.commit()
        return _json_response(config.json())
    elif request.method == "DELETE":
        try:
            db.session.delete(config.one())
            db.session.commit()
        except NoResultFound:
            pass
        return Response(status=200)
    elif request.method == "GET":
        return _json_response(config.first_or_404().json())
コード例 #56
0
ファイル: views.py プロジェクト: jmangi13/yakin-tracker
def load_flickr():
    user_id = Config.query(Config.name == 'flickr_username').order(-Config.date_added).get()

    if user_id is None:
        return Response(json.dumps({ 'error': 'flickr_username configuration was not found.' }), status=500, mimetype='application/json');

    photoset_id = Config.query(Config.name == 'flickr_photoset_title').order(-Config.date_added).get()

    if photoset_id is None:
        return Response(json.dumps({ 'error': 'flickr_photoset_title configuration was not found.' }), status=500, mimetype='application/json');

    api_key = Config.query(Config.name == 'flickr_api_key').order(-Config.date_added).get()

    if api_key is None:
        return Response(json.dumps({ 'error': 'flickr_api_key configuration was not found.' }), status=500, mimetype='application/json');

    api_secret = Config.query(Config.name == 'flickr_api_secret').order(-Config.date_added).get()

    if api_secret is None:
        return Response(json.dumps({ 'error': 'flickr_api_secret configuration was not found.' }), status=500, mimetype='application/json');

    return flickr.import_photos(user_id.value, photoset_id.value, api_key.value, api_secret.value)
コード例 #57
0
ファイル: views.py プロジェクト: jmangi13/yakin-tracker
def save_config():
    try:
        data = json.loads(request.data)
        name = data['name']
        value = data['value']
        config = Config(
            name=name,
            value=value
        )
        config.put()
    except CapabilityDisabledError:
        logging.error(u'App Engine Datastore is currently in read-only mode.')
        abort(500)
    except BadValueError:
        abort(400)
    except TypeError:
        abort(400)
    except Exception as e:
        logging.error(e.args[0])
        abort(500)

    return Response(json.dumps(config.to_dict()), mimetype='application/json');
コード例 #58
0
ファイル: HomeController.py プロジェクト: Tim-B/ENGG4810_PC
    def homeAction(self):

        self.pyo = Server(audio="offline", nchnls=1, sr=44100).boot()
        self.pyo.recordOptions(dur=5, filename=None, fileformat=0, sampletype=3)

        self.config = Config()
        root = Tk()
        self.samples = []
        self.sampleCnt = 0
        self.homeView = HomeView(root, self)
        self.effect1 = 'None'
        self.effect2 = 'None'
        self.tempo = 10
        root.mainloop()
コード例 #59
0
def sendMailResult():
    # TODO: test this
    message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>",
                                subject="Risultati")
    users = User.query().fetch()
    to = ""
    for user in users:
        to += user.email + ";"
    message.to = to
    calls_open = Call.query(Call.status == "OPEN").fetch()
    status = Config.query().get()
    if not status:
        status = Config()
    status.is_open = True
    status.put()
    if len(calls_open) > 0:
        path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_results.html')
        params = dict(open=[e.to_dict() for e in calls_open])
        res = template.render(path, params)
        for o in calls_open:
            o.status = "CLOSED"
            o.put()
        message.html = res
        message.send()