raise Exception("unknown user type %s" % t)
def add_user_type(user):
- """ All users that are not specifically marked as something else
+ """ All users that are not specifically marked as something else
are treated as canonical users"""
for atype in ALL_ACL_TYPES:
if (user[:len(atype)] == atype):
permission_elem.text = g.permission
return etree.tostring(root, encoding="UTF-8")
def translate_users(self, xusers):
- # owner ids are always expressed in terms of canonical user id
- if (xusers.has_key(ACL_TYPE_CANON_USER + self.owner_id)):
- self.owner_id = \
- strip_user_type(xusers[ACL_TYPE_CANON_USER + self.owner_id])
- # It's not clear what the new pretty-name should be, so just leave it blank.
- # It's not necessary when doing PUT/POST anyway.
- self.owner_display_name = ""
+ self.owner_id = opts.owner
+ self.owner_display_name = ""
for g in self.grants:
g.translate_users(xusers)
parser.add_option("-x", "--xuser", type="string", nargs=1, action="callback", \
dest="SRC=DST", callback=xuser_cb, help="set up a user tranlation. You \
can specify multiple user translations with multiple --xuser arguments.")
+parser.add_option("-O", "--owner", dest="owner", help="set who will \
+own the objects you create.")
parser.add_option("--unit", action="store_true", \
dest="run_unit_tests", help="run unit tests and quit")
xuser = {}
if (opts.run_unit_tests):
test_acl_policy()
sys.exit(0)
+if (not opts.owner):
+ raise Exception("You must specify who will own the objects you create. \
+Please specify the owner as -O [OWNER].\n\
+It's not enough to have the access key, since a single account can have many \
+users.")
+
opts.preserve_acls = not opts.no_preserve_acls
if (opts.create and opts.dry_run):
raise Exception("You can't run with both --create-dest and --dry-run! \
global opts
global tdir
+global user
###### Helper functions #######
def getenv(e):
else:
return None
+user = getenv("USER")
+
def obsync(src, dst, misc):
full = ["./obsync.py"]
e = {}
e["DST_SKEY"] = dst.skey
else:
full.append(dst)
+ has_owner = False
+ for m in misc:
+ if m == "-O" or m == "--owner":
+ has_owner = True
+ if (has_owner == False):
+ full.append("--owner")
+ full.append(user)
full.extend(misc)
if (opts.more_verbose):
for f in full:
compare_directories("%s/dir1" % tdir, "%s/dir1a" % tdir)
# we should fail here, because we didn't supply -c
-ret = subprocess.call(["./obsync.py", "file://%s/dir1" % tdir,
- "file://%s/dir2" % tdir], stderr=opts.error_out)
+ret = obsync("file://%s/dir1" % tdir, "file://%s/dir2" % tdir, [])
if (ret == 0):
raise RuntimeError("expected this call to obsync to fail, because \
we didn't supply -c. But it succeeded.")
print "first call failed as expected."
# now supply -c and it should work
-ret = subprocess.check_call(["./obsync.py", "-c", "file://%s/dir1" % tdir,
- "file://%s/dir2" % tdir], stderr=opts.error_out)
+obsync_check("file://%s/dir1" % tdir, "file://%s/dir2" % tdir, ["-c"])
compare_directories("%s/dir1" % tdir, "%s/dir2" % tdir)
# test the alternate syntax where we leave off the file://, and it is assumed
# because the url begins with / or ./
-ret = subprocess.check_call(["./obsync.py", "-c", "file://%s/dir1" % tdir,
- "/%s/dir2" % tdir], stderr=opts.error_out)
+obsync_check("file://%s/dir1" % tdir, "/%s/dir2" % tdir, ["-c"])
+
compare_directories("%s/dir1" % tdir, "%s/dir2" % tdir)
if (opts.verbose):