本文整理汇总了Python中pynimbusauthz.objects.File.create_file方法的典型用法代码示例。如果您正苦于以下问题:Python File.create_file方法的具体用法?Python File.create_file怎么用?Python File.create_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynimbusauthz.objects.File
的用法示例。
在下文中一共展示了File.create_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def main(argv=sys.argv[1:]):
try:
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
(opts, args) = setup_options(argv)
if len(args) != 3:
raise AuthzException("CLI_PARAMETER", "You must specify a username filename and a datakey\nTry --help")
user_name = args[0]
object_name = args[1]
data = args[2]
user = User(db_obj, uu=user_name)
parent = None
if opts.parent != None:
parent = File.get_file(db_obj, opts.parent, opts.type)
if parent == None:
raise AuthzException("FILE_EXISTS", "parent %s not found" % (opts.parent))
File.create_file(db_obj, object_name, user, data, opts.type, parent=parent)
except AuthzException, ae:
print ae
return ae.get_rc()
示例2: test_bucket
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_bucket(self):
# create a file and a bucket
b1 = File.create_file(self.db, "bucket", self.user1, self.data, pynimbusauthz.object_type_s3)
f2 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3, parent=b1)
self.db.commit()
new_perms = "WR"
rc = pynimbusauthz.chmod.main(["-t", f2.get_object_type(), "-p", b1.get_name(), self.user1.get_id(), f2.get_name(), new_perms])
self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
示例3: test_single_change
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_single_change(self):
name = "/file/name"
old_base = "/OLD"
new_base = "/NEW"
data = "/etc/group"
key = old_base + data
file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3)
self.db.commit()
rc = pynimbusauthz.rebase.main([old_base, new_base])
self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc))
f2a = File.find_files_from_data(self.db, key)
f2a = list(f2a)
self.assertEqual(len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a)))
key = new_base + data
f2a = File.find_files_from_data(self.db, key)
f2a = list(f2a)
self.assertNotEqual(len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a)))
found = False
for f2 in f2a:
tst_key = f2.get_data_key()
if tst_key == key:
found = True
self.assertTrue(found, "key not found")
示例4: test_file_and_bucket
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_file_and_bucket(self):
user1 = User(self.db)
fname = "NAME"
data = "data"
b1 = File.create_file(self.db, "bucket", user1, data, pynimbusauthz.object_type_s3)
f1 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3, parent=b1)
f2 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3)
self.db.commit()
self.assertNotEqual(f1.get_id(), f2.get_id())
f3 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1)
f4 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
self.assertEqual(f1.get_id(), f3.get_id())
self.assertEqual(f2.get_id(), f4.get_id())
self.assertNotEqual(f3.get_id(), f4.get_id())
self.db.commit()
示例5: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def main(argv=sys.argv[1:]):
try:
repo_dir = argv[0]
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
user = User(db_obj, uu="CumulusPublicUser")
if user == None:
raise Exception("No public user")
File.create_file(db_obj, repo_dir, user, repo_dir, pynimbusauthz.alias_type_s3)
db_obj.commit()
except:
raise
return 0
示例6: test_many_change
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_many_change(self):
name = "/file/name"
old_base = "/OLD"
new_base = "/NEW"
count = 10
for i in range(0, count):
keyname = str(uuid.uuid1())
oldkey = old_base + "/" + keyname
File.create_file(self.db, name+oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3)
self.db.commit()
rc = pynimbusauthz.rebase.main([old_base, new_base])
self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc))
f2a = File.find_files_from_data(self.db, new_base + "%")
f2a = list(f2a)
self.assertEqual(len(f2a), count, "length of the new items should be %d is %s" % (count, len(f2a)))
示例7: setUp
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def setUp(self):
# os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
con = pynimbusauthz.db.make_test_database()
self.db = DB(con=con)
self.user1 = User(self.db)
self.name = "/file/name"
self.data = "/etc/group"
self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
self.uf = UserFile(self.file1)
示例8: test_add_file_usage_one_file
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_add_file_usage_one_file(self):
size1 = 100
name = "/file/name"
data = "/etc/group"
file1 = File.create_file(self.db, name, self.user, data, pynimbusauthz.object_type_s3, size=size1)
self.db.commit()
u = self.user.get_quota_usage()
self.assertEqual(u, size1)
示例9: test_children
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_children(self):
child1 = File.create_file(self.db, "kid", self.user1, self.data, pynimbusauthz.object_type_s3, parent=self.file1)
self.db.commit()
x = child1.get_all_children()
self.assertEqual(len(list(x)), 0, "The file should have no children")
x = self.uf.get_all_children()
found = False
for f in x:
if f.get_file() == child1:
found = True
self.assertTrue(found, "We should have found that kid!")
示例10: setUp
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def setUp(self):
(osf, self.fname) = tempfile.mkstemp()
os.close(osf)
# os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
os.environ["NIMBUS_AUTHZ_DB"] = self.fname
pynimbusauthz.db.make_test_database(self.fname)
self.db = DB(con_str=self.fname)
self.user1 = User(self.db)
self.name = "/file/name"
self.data = "/etc/group"
self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
self.uf = UserFile(self.file1)
self.db.commit()
示例11: test_add_file_usage_many_files
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_add_file_usage_many_files(self):
size1 = 100
name = "/file/name"
data = "/etc/group"
total = 0
for i in range(0, 10):
file1 = File.create_file(self.db, name+str(i), self.user, data, pynimbusauthz.object_type_s3, size=size1)
total = total + size1
self.db.commit()
u = self.user.get_quota_usage()
self.assertEqual(u, total)
示例12: test_file_children
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_file_children(self):
user1 = User(self.db)
name = "/file/name"
data = "/etc/group"
file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3)
self.db.commit()
child1 = File.create_file(self.db, "kid", user1, data, pynimbusauthz.object_type_s3, parent=file1)
self.db.commit()
p2 = child1.get_parent()
self.assertEqual(p2, file1, "parent not set properly")
x = child1.get_all_children()
self.assertEqual(len(list(x)), 0, "The file should have no children")
x = file1.get_all_children()
found = False
for f in x:
if f == child1:
found = True
self.assertTrue(found, "We should have found that kid!")
示例13: test_find_by_key
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_find_by_key(self):
user1 = User(self.db)
name = "/file/name"
key = "/old/path/base"
f = File.create_file(self.db, name, user1, key, pynimbusauthz.object_type_s3)
self.db.commit()
f2a = File.find_files_from_data(self.db, key)
found = False
for f2 in f2a:
tst_key = f2.get_data_key()
if tst_key == key:
found = True
self.assertTrue(found, "key not found")
示例14: put_object
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def put_object(self, data_obj, bucketName, objectName):
data_key = data_obj.get_data_key()
md5sum = data_obj.get_md5()
fsize = data_obj.get_size()
try:
# it is ok for someone to put to an existing object
# we just need to delete the existing one
file = self.get_file_obj(bucketName, objectName)
if file != None:
pycb.config.bucket.delete_object(file.get_data_key())
file.delete()
bf = self.get_file_obj(bucketName)
f = File.create_file(self.db_obj, objectName, self.user, data_key, pynimbusauthz.alias_type_s3, parent=bf, size=fsize, md5sum=md5sum)
finally:
self.db_obj.commit()
示例15: test_basic_file
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import create_file [as 别名]
def test_basic_file(self):
user1 = User(self.db)
name = "/file/name"
data = "/etc/group"
file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3)
self.db.commit()
x = file1.get_all_children()
self.assertEqual(len(list(x)), 0, "The file should have no children")
n2 = file1.get_name()
self.assertEqual(name, n2, "Names not equal")
d2 = file1.get_data_key()
self.assertEqual(data, d2, "Data not equal")
o2 = file1.get_owner()
self.assertEqual(user1, o2, "Owner not equal")
p2 = file1.get_parent()
self.assertEqual(None, p2, "There should be no parent")
b2 = file1.get_object_type()
self.assertEqual(pynimbusauthz.object_type_s3, b2, "Type wrong")