source file: /home/buildslave/tahoe/edgy/build/src/allmydata/scripts/stats_gatherer.py
file stats: 29 lines, 29 executed: 100.0% covered
coverage versus previous test: 0 lines added, 0 lines removed
1.
2. import os
3. from twisted.python import usage
4.
5. class CreateStatsGathererOptions(usage.Options):
6. optParameters = [
7. ["basedir", "C", None, "which directory to create the stats-gatherer in"],
8. ]
9.
10. def parseArgs(self, basedir=None):
11. if basedir is not None:
12. assert self["basedir"] is None
13. self["basedir"] = basedir
14.
15.
16. stats_gatherer_tac = """
17. # -*- python -*-
18.
19. from allmydata import stats
20. from twisted.application import service
21.
22. verbose = True
23. g = stats.StatsGathererService(verbose=verbose)
24.
25. application = service.Application('allmydata_stats_gatherer')
26. g.setServiceParent(application)
27. """
28.
29. def create_stats_gatherer(config):
30. out = config.stdout
31. err = config.stderr
32. basedir = config['basedir']
33. if not basedir:
34. print >>err, "a basedir was not provided, please use --basedir or -C"
35. return -1
36. if os.path.exists(basedir):
37. if os.listdir(basedir):
38. print >>err, "The base directory \"%s\", which is \"%s\" is not empty." % (basedir, os.path.abspath(basedir))
39. print >>err, "To avoid clobbering anything, I am going to quit now."
40. print >>err, "Please use a different directory, or empty this one."
41. return -1
42. # we're willing to use an empty directory
43. else:
44. os.mkdir(basedir)
45. f = open(os.path.join(basedir, "tahoe-stats-gatherer.tac"), "wb")
46. f.write(stats_gatherer_tac)
47. f.close()
48. return 0
49.
50. subCommands = [
51. ["create-stats-gatherer", None, CreateStatsGathererOptions, "Create a stats-gatherer service."],
52. ]
53.
54. dispatch = {
55. "create-stats-gatherer": create_stats_gatherer,
56. }
57.
58.