本文整理汇总了Python中pynimbusauthz.objects.File.find_files_from_data方法的典型用法代码示例。如果您正苦于以下问题:Python File.find_files_from_data方法的具体用法?Python File.find_files_from_data怎么用?Python File.find_files_from_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynimbusauthz.objects.File
的用法示例。
在下文中一共展示了File.find_files_from_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_change
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import find_files_from_data [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")
示例2: test_find_by_key
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import find_files_from_data [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")
示例3: test_many_change
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import find_files_from_data [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)))
示例4: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import find_files_from_data [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)
old_path = args[0]
new_path = args[1]
pattern = old_path + "%"
files = list(File.find_files_from_data(db_obj, pattern))
for f in files:
old_key = f.get_data_key()
new_key = old_key.replace(old_path, new_path, 1)
f.set_data_key(new_key)
db_obj.commit()
print "done - %d files rebased" % len(files)
except AuthzException, ae:
print ae
return ae.get_rc()