本文整理汇总了Python中MaKaC.common.utils.OSSpecific类的典型用法代码示例。如果您正苦于以下问题:Python OSSpecific类的具体用法?Python OSSpecific怎么用?Python OSSpecific使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OSSpecific类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCachePage
def getCachePage( self ):
if os.path.isfile(self.getFilePath()):
fp = open(self.getFilePath(),"r")
OSSpecific.lockFile(fp, 'LOCK_SH')
page = fp.read()
return page
return ""
示例2: set
def set(self, key, val, ttl=0):
f = open(self._getFilePath(key), 'wb')
OSSpecific.lockFile(f, 'LOCK_EX')
try:
expiry = int(time.time()) + ttl if ttl else None
data = (expiry, val)
pickle.dump(data, f)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
return 1
示例3: lockCache
def lockCache( self, file, flag=True):
global fp
if flag:
fp = open(file,"a")
OSSpecific.lockFile(fp, 'LOCK_EX')
else:
if not fp:
return
OSSpecific.lockFile(fp, 'LOCK_UN')
fp.close()
fp = None
示例4: save
def save(self, path, name, data):
fsPath = os.path.join(self._dir, path)
if not os.path.exists(fsPath):
os.makedirs(fsPath)
filePath = os.path.join(fsPath, name)
f = open(filePath, 'wb')
OSSpecific.lockFile(f, 'LOCK_EX')
try:
pickle.dump(data, f)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
示例5: load
def load(self, path, name, default=None):
filePath = os.path.join(self._dir, path, name)
if not os.path.exists(filePath):
return default, None
f = open(filePath, 'rb')
OSSpecific.lockFile(f, 'LOCK_SH')
try:
obj = pickle.load(f)
mtime = os.path.getmtime(filePath)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
return obj, mtime
示例6: get
def get(self, key):
path = self._getFilePath(key)
if not os.path.exists(path):
return None
f = open(path, 'rb')
OSSpecific.lockFile(f, 'LOCK_SH')
expiry = val = None
try:
expiry, val = pickle.load(f)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
if expiry and time.time() > expiry:
return None
return val
示例7: set
def set(self, key, val, ttl=0):
try:
f = open(self._getFilePath(key), 'wb')
OSSpecific.lockFile(f, 'LOCK_EX')
try:
expiry = int(time.time()) + ttl if ttl else None
data = (expiry, val)
pickle.dump(data, f)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
except (IOError, OSError):
Logger.get('FileCache').exception('Error setting value in cache')
return 0
return 1
示例8: get
def get(self, key):
try:
path = self._getFilePath(key)
if not os.path.exists(path):
return None
f = open(path, 'rb')
OSSpecific.lockFile(f, 'LOCK_SH')
expiry = val = None
try:
expiry, val = pickle.load(f)
finally:
OSSpecific.lockFile(f, 'LOCK_UN')
f.close()
if expiry and time.time() > expiry:
return None
except (IOError, OSError):
Logger.get('FileCache').exception('Error getting cached value')
return None
except (EOFError, pickle.UnpicklingError):
Logger.get('FileCache').exception('Cached information seems corrupted. Overwriting it.')
return None
return val