本文整理匯總了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")
示例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"
示例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))
示例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
示例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")
"""
示例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')
示例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
示例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')
示例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()
示例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')
示例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')
示例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