def run(self, options): basedir = options.basedir stdout = options.stdout service_type = options.service_type service_args = options.service_args swissnum = generateSwissnumber(Tub.NAMEBITS) service_basedir = os.path.join(basedir, "services", swissnum) os.makedirs(service_basedir) try: # validate the service args by instantiating one s = build_service(service_basedir, None, service_type, service_args) del s except: shutil.rmtree(service_basedir) raise f = open(os.path.join(service_basedir, "service_type"), "w") f.write(service_type + "\n") f.close() f = open(os.path.join(service_basedir, "service_args"), "w") f.write(repr(service_args) + "\n") f.close() if options["comment"]: f = open(os.path.join(service_basedir, "comment"), "w") f.write(options["comment"] + "\n") f.close() furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip() furl = furl_prefix + swissnum if not options["quiet"]: print >>stdout, "Service added in %s" % service_basedir print >>stdout, "FURL is %s" % furl return 0
def make_swissnum(): return generateSwissnumber(Tub.NAMEBITS)
def test_length(self): s = generateSwissnumber(160) # 160 bits, 160/5= 32 characters in base32 self.assertEqual(len(s), 32)
def make_swissnum(): return six.ensure_text(generateSwissnumber(Tub.NAMEBITS))