本文整理汇总了Python中fs.osfs.OSFS.remove方法的典型用法代码示例。如果您正苦于以下问题:Python OSFS.remove方法的具体用法?Python OSFS.remove怎么用?Python OSFS.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.osfs.OSFS
的用法示例。
在下文中一共展示了OSFS.remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_production
# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import remove [as 别名]
def create_production(build_dir, backups, script_dir):
"""Put the staging version to production hosted at
register.geostandaarden.nl
"""
print "Building production..."
logging.info("Building production...")
deploy = OSFS('..')
if deploy.exists(backups) == False:
deploy.makedir(backups)
deploy.copydir('%s/%s' % (script_dir, build_dir), 'register-new', overwrite=True)
if deploy.exists('register') == True:
# server refuses to recursively remove register/staging
# hence we excplicitly remove symbolic link to staging
try:
deploy.remove('register/staging/staging')
except ResourceNotFoundError:
print "Warning, register/staging/staging not found..."
try:
deploy.removedir('register/staging')
except ResourceNotFoundError:
print "Warning, register/staging not found..."
backup_dir = time.strftime('%Y-%m-%d-%H-%M-%S')
# if deploy.exists('backups/%s' % backup_dir):
# deploy.removedir('backups/%s' % backup_dir, force=True)
deploy.copydir('register', 'backups/%s' % backup_dir, overwrite=True)
try:
deploy.movedir('register', 'register-old', overwrite=True)
except ResourceNotFoundError:
pass
deploy.movedir('register-new', 'register', overwrite=True)
# create symbolic link to standalone staging directory
# fails if production is built first...
deploy.makedir('register/staging')
call('cd ../register/staging; ln -s ../../staging', shell=True)
call('cd ../register; ln -s ../%s/log.txt' % script_dir , shell=True)
try:
deploy.removedir('register-old', force=True)
except ResourceNotFoundError:
pass
call('chmod -R a+rx ../register', shell=True)
print "Done building production..."
logging.info("Production built successfully!")
示例2: create_production
# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import remove [as 别名]
def create_production(destination, backups, script_entry_path, production_path):
"""Put the staging version to production hosted at
register.geostandaarden.nl
"""
## TODO: feed this function absolute paths
print "Building production..."
logging.info("Building production...")
production = OSFS(production_path)
# if production.exists(backups) == False:
# production.makedir(backups)
# copy newly baked register/staging to production directory
# NOTE: only build paths within script_dir are currently supported
call ('cp -r %s %s' % (ospath.join(build_path, destination), ospath.join(production_path, destination + '-new')), shell=True)
# production.copydir('%s/%s/%s' % (script_dir, build_path, destination), destination + '-new', overwrite=True)
if production.exists(destination) == True:
# server refuses to recursively remove register/staging
# hence we excplicitly remove symbolic link to staging
try:
production.remove('%s/staging/staging' % destination)
except ResourceNotFoundError:
print "Warning, %s/staging/staging not found..." % destination
try:
production.removedir('%s/staging' % destination)
except ResourceNotFoundError:
print "Warning, %s/staging not found..." % destination
backup_dir = time.strftime('%Y-%m-%d-%H-%M-%S')
# if production.exists('backups/%s' % backup_dir):
# production.removedir('backups/%s' % backup_dir, force=True)
production.copydir(destination, '%s/%s' % (backups, backup_dir), overwrite=True)
try:
production.movedir(destination, destination + '-old', overwrite=True)
except ResourceNotFoundError:
pass
production.movedir(destination + '-new', destination, overwrite=True)
# create symbolic link to standalone staging directory
# fails if production is built first...
production.makedir('%s/staging' % destination)
call('cd %s; ln -s %s' % (ospath.join(production_path, destination, 'staging'), ospath.join(production_path, 'staging')), shell=True)
call('cd %s; ln -s %s' % (ospath.join(production_path, destination), ospath.join(script_entry_path, 'log.txt')), shell=True)
try:
production.removedir(destination + '-old', force=True)
except ResourceNotFoundError:
pass
call('chmod -R a+rx %s/%s' % (production_path, destination), shell=True)
print "Done building production..."
logging.info("Production built successfully!")
示例3: Timeline
# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import remove [as 别名]
class Timeline(object):
"""A timeline is a sequence of timestamped events."""
def __init__(self, path, name, max_events=None):
self.path = path
self.name = name
self.fs = OSFS(path, create=True)
self.max_events = max_events
def __repr__(self):
return "Timeline({!r}, {!r}, max_events={!r})".format(self.path, self.name, self.max_events)
def new_event(self, event_type, timestamp=None, *args, **kwargs):
"""Create and return an event, to be used as a context manager"""
if self.max_events is not None:
size = len(self.fs.listdir(wildcard="*.json"))
if size >= self.max_events:
raise TimelineFullError("The timeline has reached its maximum size")
if timestamp is None:
timestamp = int(time() * 1000.0)
try:
event_cls = _event_registry[event_type]
except KeyError:
raise UnknownEventError("No event type '{}'".format(event_type))
# Make an event id that we can be confident it's unique
token = str(randint(0, 2 ** 31))
event_id = kwargs.pop('event_id', None) or "{}_{}_{}".format(event_type, timestamp, token)
event = event_cls(self, event_id, timestamp, *args, **kwargs)
log.debug('new event {!r}'.format(event))
return event
def new_photo(self, file, filename=None, ext=None, **kwargs):
"""Create a new photo object"""
event = self.new_event('IMAGE', **kwargs)
if hasattr(file, 'getvalue'):
bytes = file.getvalue()
elif file is not None:
if isinstance(file, text_type):
with open(file, 'rb') as f:
bytes = f.read()
else:
bytes = file.read()
else:
if bytes is None:
raise ValueError("A value for 'file' or 'bytes' is required")
event.attach_bytes(bytes, name='photo', filename=filename, ext=ext)
return event
def get_events(self, sort=True):
"""Get all accumulated events"""
events = []
for event_filename in self.fs.listdir(wildcard="*.json"):
with self.fs.open(event_filename, 'rb') as f:
event = loads(f.read().decode('utf-8'))
events.append(event)
if sort:
# sort by timestamp
events.sort(key=itemgetter('timestamp'))
return events
def clear_all(self):
"""Clear all stored events"""
for filename in self.fs.listdir(wildcard="*.json"):
try:
self.fs.remove(filename)
except FSError:
pass
def clear_events(self, event_ids):
"""Clear any events that have been processed"""
for event_id in event_ids:
filename = "{}.json".format(event_id)
try:
self.fs.remove(filename)
except FSError:
pass
def _write_event(self, event_id, event):
if hasattr(event, 'to_data'):
event = event.to_data()
event['event_id'] = event_id
event_json = dumps(event, indent=4).encode('utf-8')
filename = "{}.json".format(event_id)
with self.fs.open(filename, 'wb') as f:
f.write(event_json)