本文整理汇总了Python中messages.Messages.inventoryNotFound方法的典型用法代码示例。如果您正苦于以下问题:Python Messages.inventoryNotFound方法的具体用法?Python Messages.inventoryNotFound怎么用?Python Messages.inventoryNotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messages.Messages
的用法示例。
在下文中一共展示了Messages.inventoryNotFound方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restart
# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import inventoryNotFound [as 别名]
def restart(): # this really could be health
lock = None
try:
lock = LockFile('json/health.json', 'r')
lock.acquire()
with open('json/health.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8')
if request.method == 'POST':
status = request.args.get('status', type=str)
if status is None:
print 'no status given, defaults to true'
status = 'true'
data['restart'] = status
with open('json/health.json', 'w') as json_file:
json_file.write(json.dumps(data))
lock.release()
return 'restart set to %s' % status
if request.method == 'GET':
lock.release()
return data['restart']
except IOError:
if lock is not None:
lock.release()
return Messages.inventoryNotFound()
示例2: get_inventory
# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import inventoryNotFound [as 别名]
def get_inventory():
"""
TODO loop through inventory to make sure uuid of every item is unique
only send invenotory if all unique
"""
lock = None
try:
lock = LockFile('json/inventory.json')
lock.acquire()
with open('json/inventory.json', 'r') as json_file:
data = json.load(json_file) # this will throw correct errors
lock.release()
return json.dumps(data)
except IOError:
if lock is not None:
lock.release()
return Messages.inventoryNotFound()
示例3: health
# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import inventoryNotFound [as 别名]
def health(part):
lock = None
try:
lock = LockFile('json/health.json')
lock.acquire()
# TODO need to check if scanner is actually on, file is not enough
with open('json/health.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8')
#status = request.args.get('status', type=str)
if request.method == 'POST':
status = request.args.get('status', type=str)
data[part] = status
# print status
with open('json/health.json', 'w') as json_file:
json_file.write(json.dumps(data))
lock.release()
return ''
if request.method == 'GET':
if part == 'scanner': # check if process is running
running = RestUtils.find_process('barcode_scanner', False)
if not running:
data[part] = 'critical'
with open('json/health.json', 'w') as json_file:
json_file.write(json.dumps(data))
lock.release()
return data[part]
except IOError:
if lock is not None:
lock.release()
return Messages.inventoryNotFound()
示例4: inventory
# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import inventoryNotFound [as 别名]
def inventory(uuid_var):
"""
DELETE will remove first item with given barcode from inventory
GET will return first item with this barcode in inventory
POST will add to inventory
will increment quantity of pre existing items
:param uuid: string representation of uuid
:param days_till_expire: defaults to None which will set it 30 days from todays date
:return:
:usage: http://localhost:5000/inventory/1e4658dc-03d5-11e6-b402-7831c1d2d04e?expire=30
"""
lock = LockFile('json/inventory.json')
if request.method == 'DELETE':
try:
lock.acquire()
with open('json/inventory.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8') # Get the current inventory.
json_file.close()
lock.release()
index = RestUtils.find_elem(data, 'uuid', uuid_var)
if index is not None:
del data[index]
lock.acquire()
with open('json/inventory.json', 'w+') as json_file:
json_file.write(json.dumps(data))
json_file.close()
lock.release()
else:
print 'nothing to delete'
return '' # TODO should tell you if it actually deleted something?
except (IOError, KeyError):
if lock is not None:
lock.release()
print "file doesnt exist or keyerror"
if request.method == 'GET':
try:
lock.acquire()
with open('json/inventory.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8')
json_file.close()
index = RestUtils.find_elem(data, 'uuid', uuid_var)
if index is not None:
lock.release()
return jsonify(data[index])
else:
lock.release()
return jsonify({}) # TODO what should this return if item doesnt exist?
except IOError:
if lock is not None:
lock.release()
Messages.inventoryNotFound()
if request.method == 'POST':
expiration = request.args.get('expire', type=int)
added_date = datetime.datetime.today().strftime("%m/%d/%Y %H:%M:%S")
expire_date = RestUtils.set_expiration(expiration)
try:
lock.acquire()
with open('json/inventory.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8')
json_file.close()
lock.release()
barcode = uuid_var # this is needed to not break pre-existing method calls from scanner
d = {u'barcode': unicode(barcode),
u'added': unicode(added_date),
u'expiration': unicode(expire_date),
u'name': "",
u'uuid': unicode(uuid.uuid1())} # generates unique id for help with deleting items
data.append(d)
# open up file again to write to it
lock.acquire()
with open('json/inventory.json', 'w+') as json_file:
json_file.write(json.dumps(data, encoding='utf-8'))
json_file.close()
lock.release()
return jsonify(data)
except (IOError, KeyError) as e:
if lock is not None:
lock.release()
print e
return ''
if request.method == 'PUT':
try:
#.........这里部分代码省略.........