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


Python Connector.mkdir方法代码示例

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


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

示例1: CloudFS

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import mkdir [as 别名]
class CloudFS(LoggingMixIn, Operations):
	
	def __init__(self):
		# initialize file table
		self.maxFiles = 1024
#		self.files = [dict(path=None, dirty=False, data=None)] * self.maxFiles
		self.files = [None] * self.maxFiles
		for i in range(0, self.maxFiles):
			self.files[i] = dict(path=None, dirty=False, data=None)
		self.conn = Connector()
		
	def chmod(self, path, mode):
		# chmod is not allowed
		raise FuseOSError(EPERM)

	def chown(self, path, uid, gid):
		# chown is not allowed
		raise FuseOSError(EPERM)
	
	def create(self, path, mode):
		# create file
		paths = splitPath(path)
		print path, paths
		if paths[0] == '':
			raise FuseOSError(EPERM)

		# search available fd
		fd = None
		fdNum = -1
		for i in range(0, self.maxFiles):
			fd = self.files[i]
			print i
			if fd['path'] == None:
#				print "MATCH!!!"
#				print fdNum
				fdNum = i
				break

		if fd == None:
			raise FuseOSError(ENOENT)

		fd['path'] = path
		fd['dirty'] = True
		fd['data'] = ''

		paths = splitPath(path)
		self.conn.push(paths[0], paths[1], fd['data'])

		return fdNum
	
	def getattr(self, path, fh=None):
		now = time()
		paths = splitPath(path)
		# if root?
		if paths[0] == '':
			return dict(st_mode=(S_IFDIR | 0755), st_ctime=now, st_mtime=now, st_atime=now, st_nlink=2)

		attr = self.conn.getAttr(paths[0], paths[1])
		if attr != None:
			return attr
		else:
			raise FuseOSError(ENOENT)
	
	def getxattr(self, path, name, position=0):
		return ''

	def listxattr(self, path):
		raise FuseOSError(EPERM)
	
	def mkdir(self, path, mode):
		paths = splitPath(path)
		# mkdir is not allowed under root dir
		if paths[1] == '':
			raise FuseOSError(EPERM)
		if self.conn.mkdir(paths[0], paths[1]) != True:
			raise FuseOSError(EPERM)
	
	def open(self, path, flags):
		paths = splitPath(path)
		# cannot open files under root dir
		print path, paths
		if paths[0] == '':
			raise FuseOSError(EPERM)

		# cache file content from storage
		content = self.conn.pull(paths[0], paths[1])
		if paths[0] == None:
			raise FuseOSError(ENOENT)

		# search available file
		fd = None
		fdNum = -1		
		for i in range(0, self.maxFiles):
			fd = self.files[i]
			if fd['path'] == None:
				fdNum = i
				break

		if fd == None:
			raise FuseOSError(ENOENT)
#.........这里部分代码省略.........
开发者ID:sangla1,项目名称:CloudFS,代码行数:103,代码来源:cloudfs.py


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