当前位置: 首页>>代码示例>>Python>>正文


Python Base.exists方法代码示例

本文整理汇总了Python中pydblite.Base.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Base.exists方法的具体用法?Python Base.exists怎么用?Python Base.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydblite.Base的用法示例。


在下文中一共展示了Base.exists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: printdb

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
def printdb(dbpath):  # Prints the contents of a PyDBLite database to the console
    db = Base(dbpath)
    if db.exists():
        db.open()
        retstr = ""
        for obj in db:
            retstr += str(obj)
            retstr += "\n"
        encoded = retstr.encode("utf-8", errors="ignore")
        print(encoded)
    else:
        print("The database does not exist or is corrupt.\n")
开发者ID:agincel,项目名称:AdamTestBot,代码行数:14,代码来源:utils.py

示例2: printdb

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
def printdb(dbpath): #Prints the contents of a PyDBLite database to the console
    db = Base(dbpath)
    if db.exists():
        db.open()
        retstr = ""
        for obj in db:
            retstr += str(obj)
            retstr += "\n"
        print retstr
        return retstr
    else:
        print "The database does not exist or is corrupt.\n"
开发者ID:magomez96,项目名称:AdamTestBot,代码行数:14,代码来源:utils.py

示例3: setup

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
def setup(args):
    if os.path.isfile(path):
        backup_path = path + '.bak'
        shutil.copy(path, backup_path)

    db = Base(path)

    if args.overwrite:
        while 1:
            confirm = input('Do you really want to overwrite the database ? (y/n) ')
            if confirm in ['y', 'n']:
                break
        if confirm == 'y':
            db.create('name', 'cost', 'date', 'tags', mode='override')
            print('Data base in {} has been overwritten!'.format(path))
    else:
        if db.exists():
            print('{} already exists and is a database. If you want to recreate'
                  ' it, use the -o flag.'.format(path))
        else:
            db.create('name', 'cost', 'date', 'tags', mode='open')
            print('Created database at {}!'.format(path))
开发者ID:BeWe11,项目名称:expenses,代码行数:24,代码来源:expenses.py

示例4: get_results_db

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
def get_results_db(clear_cache=False, skip=[]):
    cache_file = 'cache/results.pdl'
    db = Base(cache_file)

    if clear_cache or not db.exists() or os.path.getmtime(cache_file) < os.path.getmtime(results_dir):
        warnings.warn('Rebuilding results cache...')
        columns = set()
        rows = []
        p = pathlib.Path(results_dir)
        for config_file in p.glob('*.config'):
            with config_file.open() as config_fh:
                settings_hash = config_file.stem
                row = json.loads(config_fh.read())
            if settings_hash in skip:
                continue
            row['hash'] = settings_hash
            tests_count = analyze.count(config_file.parent, settings_hash)
            row['iostat_cpu'], len_cpu_values = analyze.iostat_cpu(config_file.parent, settings_hash)
            row['iperf_result'], len_iperf_values = getattr(analyze, row['iperf_name'])(config_file.parent, settings_hash, row)
            if tests_count != len_cpu_values or tests_count != len_iperf_values:
                raise analyze.AnalysisException('For test {}, mismatch in cardinality of tests between count ({}), iostat ({}) and iperf ({})'.format(settings_hash, tests_count, len_cpu_values, len_iperf_values), settings_hash)
            if len_iperf_values > 0:
                min_fairness = row['iperf_result']['fairness'][0] - row['iperf_result']['fairness'][1]
                if min_fairness < (1 - 1 / (2 * row['parallelism'])):
                    warnings.warn('For test {}, fairness has a critical value: {}.'.format(settings_hash, row['iperf_result']['fairness']), RuntimeWarning)
            columns = columns | set(row.keys())
            rows.append(row)

        db.create(*columns, mode='override')
        for r in rows:
            db.insert(**r)
        db.commit()
        warnings.warn('Results cache built.')
    else:
        warnings.warn('Reusing results cache.')
        db.open()

    return db
开发者ID:serl,项目名称:topoblocktest,代码行数:40,代码来源:test_master.py

示例5: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from pathlib import Path
from pydblite import Base

if not Path("db").exists():
    Path("db").mkdir()

"""
Base for client's application on service via client_id
"""
client_base = Base("db/client_base.pdl")
if client_base.exists():
    client_base.open()
else:
    client_base.create("secret", "redirect_uri", "name")
"""
Base for keeping authorization codes while oauth
"""
authorization_code = Base("db/authorization_code.pdl")
if authorization_code.exists():
    authorization_code.open()
else:
    authorization_code.create("user_id", "code", "expire_time")
"""
Base for access_tokens for authorized users
"""
access_token = Base("db/access_token.pdl")
if access_token.exists():
    access_token.open()
else:
    access_token.create("user_id", "access", "expire_time", "refresh")
"""
开发者ID:GaidukStan,项目名称:rsoi_lab2,代码行数:33,代码来源:db.py

示例6: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from pathlib import Path
from pydblite import Base

if not Path('db').exists():
    Path('db').mkdir()

client = Base('db/client.pdl')
if client.exists():
    client.open()
else:
    client.create('secret', 'redirect_uri', 'name')

authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
    authorization_code.open()
else:
    authorization_code.create('user_id', 'code', 'expire_time')

token = Base('db/token.pdl')
if token.exists():
    token.open()
else:
    token.create('user_id', 'access', 'expire_time', 'refresh')

user = Base('db/user.pdl')
if user.exists():
    user.open()
else:
    user.create('login', 'password_hash', 'name', 'email', 'phone')

clothes = Base('db/clothes.pdl')
开发者ID:SanSanch5,项目名称:rsoi_lab2,代码行数:33,代码来源:db.py

示例7: Base

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
# -*- coding: utf-8 -*-
from pydblite import Base
'''
序列化采用cPickle
'''

db = Base("test.db", save_to_file=False)

if db.exists():
    db.open()
else:
    db.create("name", "age")

db.insert("bob", 10)
index = db.insert(name="alice", age=20)

print db[index] # 按照主键访问record

record = db[1]

db.update(record, name="dellian")

#db.delete(record)

# db.records (所有记录)

# query
for r in db("age") > 10:
    print r

开发者ID:lazywhite,项目名称:python,代码行数:31,代码来源:pydblite_t.py

示例8: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from pydblite import Base
from pathlib import Path

if not Path('database').exists():
    Path('database').mkdir()

client = Base('database/client.pdl')
if client.exists():
    client.open()
else:
    client.create('client_id', 'client_secret', 'redirect_uri')

auth_code = Base('database/auth_code.pdl')
if auth_code.exists():
    auth_code.open()
else:
    auth_code.create('user_id', 'code', 'expired')

token = Base('database/token.pdl')
if token.exists():
    token.open()
else:
    token.create('user_id', 'access', 'expired', 'refresh')

user = Base('database/user.pdl')
if user.exists():
    user.open()
else:
    user.create('login', 'password', 'name', 'email', 'phone')

item = Base('database/item1.pdl')
开发者ID:akuznetsov94,项目名称:rsoi_lab2,代码行数:33,代码来源:database.py

示例9: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from pathlib import Path
from pydblite import Base

if not Path('database').exists():
    Path('database').mkdir()

client = Base('database/client.pdl')
if client.exists():
    client.open()
else:
    client.create('secret', 'redirect_uri', 'name')

authorization_code = Base('database/authorization_code.pdl')
if authorization_code.exists():
    authorization_code.open()
else:
    authorization_code.create('user_id', 'code', 'expire_time')

token = Base('database/token.pdl')
if token.exists():
    token.open()
else:
    token.create('user_id', 'access', 'expire_time', 'refresh')

if len(client) == 0:
    client.insert(secret='test_secret', redirect_uri='http://example.com', name='app1')
    client.commit()
开发者ID:srgevs93,项目名称:rsoi2,代码行数:29,代码来源:db.py

示例10: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from datetime import datetime
from pathlib import Path
from pydblite import Base

if not Path('db').exists():
    Path('db').mkdir()

client = Base('db/client.pdl')
if client.exists():
    client.open()
else:
    client.create('secret', 'redirect_uri', 'name')

authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
    authorization_code.open()
else:
    authorization_code.create('user_id', 'code', 'expire_time')

token = Base('db/token.pdl')
if token.exists():
    token.open()
else:
    token.create('user_id', 'access', 'expire_time', 'refresh')

user = Base('db/user.pdl')
if user.exists():
    user.open()
else:
    user.create('login', 'password_hash', 'name', 'email', 'phone')
开发者ID:kirillovsky,项目名称:rsoi_lab2,代码行数:32,代码来源:db_load_or_install.py

示例11: Path

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
from pathlib import Path
from pydblite import Base

if not Path('db').exists():
    Path('db').mkdir()

client = Base('db/client.pdl')
if client.exists():
    client.open()
else:
    client.create('secret', 'redirect_uri', 'name')

authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
    authorization_code.open()
else:
    authorization_code.create('user_id', 'code', 'expire_time')

token = Base('db/token.pdl')
if token.exists():
    token.open()
else:
    token.create('user_id', 'access', 'expire_time', 'refresh')

user = Base('db/user.pdl')
if user.exists():
    user.open()
else:
    user.create('login', 'password_hash', 'name', 'email')

event = Base('db/event.pdl')
开发者ID:liders,项目名称:rsoi_lab2,代码行数:33,代码来源:db.py

示例12: run_every_10_seconds

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import exists [as 别名]
def run_every_10_seconds():
	print 'run_every_10_seconds'
	now = datetime.datetime.now()
	#record = db(user="")
	#now = now.replace(hour=20, minute=0, second=1, microsecond=0)
	print now;
	db = Base(schedule_table_name)
	if db.exists():
		db.open()
	
	records = db.records
	'''
	list_of_records = [];
	for record in records:
		list_of_records.append(records[record]);
		
	db.delete(list_of_records);
	db.commit();
	'''
	for record in records:
		schedule_time = records[record]['schedule_time']
		user = records[record]['user']
		chat_id = records[record]['chat_id']
		enable = records[record]['enable']
		print schedule_time,user,chat_id,enable
		if enable=='no':
			continue
		try:
			if schedule_time==AM8:
				today8am0min = now.replace(hour=8, minute=0, second=0, microsecond=0)
				today8am1min = now.replace(hour=8, minute=1, second=0, microsecond=0)
				if now >= today8am0min and now <= today8am1min:
					kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 8AM")])
		except:
			pass
		try:
			if schedule_time==PM8:
				print "In 8PM";
				
				today8pm0min = now.replace(hour=20, minute=0, second=0, microsecond=0)
				today8pm1min = now.replace(hour=20, minute=1, second=0, microsecond=0)
				print today8pm0min;
				print today8pm0min;
				if now > today8pm0min and now < today8pm1min:
					print "Condition matched. Sending message to " + str(user);
					kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 8PM")])
		except Exception as e:
			print (e);
			pass
		try:
			if schedule_time==AM10:
				today10am0min = now.replace(hour=10, minute=0, second=0, microsecond=0)
				today10am1min = now.replace(hour=10, minute=1, second=0, microsecond=0)
				if now > today10am0min and now < today10am1min:
					kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 10AM")])
		except:
			pass
		try:
			if schedule_time==PM10:
				today10pm0min = now.replace(hour=22, minute=0, second=0, microsecond=0)
				today10pm1min = now.replace(hour=22, minute=1, second=0, microsecond=0)
				if now > today10pm0min and now < today10pm1min:
					kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 10PM")])
		except:
			pass
		try:
			if schedule_time=='Default':
				todaydefault0 = now.replace(hour=DEFAULT_TIME, minute=0, second=0, microsecond=0)
				todaydefault1 = now.replace(hour=DEFAULT_TIME, minute=1, second=0, microsecond=0)
				if now > todaydefault0 and now < todaydefault1:
					kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message default")])
		except:
			pass
开发者ID:skagrawal10,项目名称:kikMessengerDemo,代码行数:75,代码来源:demo.py


注:本文中的pydblite.Base.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。