source file: /home/buildslave/tahoe/edgy/build/src/allmydata/scripts/tahoe_mkdir.py
file stats: 30 lines, 27 executed: 90.0% covered
1.
2. import urllib
3. from allmydata.scripts.common_http import do_http, check_http_error
4. from allmydata.scripts.common import get_alias, DEFAULT_ALIAS
5.
6. def mkdir(options):
7. nodeurl = options['node-url']
8. aliases = options.aliases
9. where = options.where
10. stdout = options.stdout
11. stderr = options.stderr
12. if not nodeurl.endswith("/"):
13. nodeurl += "/"
14. if where:
15. rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
16.
17. if not where or not path:
18. # create a new unlinked directory
19. url = nodeurl + "uri?t=mkdir"
20. resp = do_http("POST", url)
21. rc = check_http_error(resp, stderr)
22. if rc:
23. return rc
24. new_uri = resp.read().strip()
25. # emit its write-cap
26. print >>stdout, new_uri
27. return 0
28.
29. # create a new directory at the given location
30. if path.endswith("/"):
31. path = path[:-1]
32. # path (in argv) must be "/".join([s.encode("utf-8") for s in segments])
33. url = nodeurl + "uri/%s/%s?t=mkdir" % (urllib.quote(rootcap),
34. urllib.quote(path))
35. resp = do_http("POST", url)
36. check_http_error(resp, stderr)
37. new_uri = resp.read().strip()
38. print >>stdout, new_uri
39. return 0