Ejemplo n.º 1
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    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 comment:
        f = open(os.path.join(service_basedir, "comment"), "w")
        f.write(comment + "\n")
        f.close()
    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Ejemplo n.º 2
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    services_data = load_service_data(basedir)
    relative_service_basedir = find_next_service_basedir(basedir)
    service_basedir = os.path.join(basedir, relative_service_basedir)
    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

    services_data["services"][swissnum] = {
        "relative_basedir": relative_service_basedir,
        "type": service_type,
        "args": service_args,
        "comment": comment,
        }
    save_service_data(basedir, services_data)

    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Ejemplo n.º 3
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    services_data = load_service_data(basedir)
    relative_service_basedir = find_next_service_basedir(basedir)
    service_basedir = os.path.join(basedir, relative_service_basedir)
    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

    services_data["services"][swissnum] = {
        "relative_basedir": relative_service_basedir,
        "type": service_type,
        "args": service_args,
        "comment": comment,
    }
    save_service_data(basedir, services_data)

    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Ejemplo n.º 4
0
def add_service(basedir, service_type, service_args, comment, swissnum=None):
    if not swissnum:
        swissnum = make_swissnum()
    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 comment:
        f = open(os.path.join(service_basedir, "comment"), "w")
        f.write(comment + "\n")
        f.close()
    furl_prefix = open(os.path.join(basedir, "furl_prefix")).read().strip()
    furl = furl_prefix + swissnum
    return furl, service_basedir
Ejemplo n.º 5
0
 def lookup(self, name):
     # walk through our configured services, see if we know about this one
     service_basedir = os.path.join(self.basedir, "services", name)
     if not os.path.exists(service_basedir):
         return None
     service_type_f = os.path.join(service_basedir, "service_type")
     service_type = open(service_type_f).read().strip()
     service_args_f = os.path.join(service_basedir, "service_args")
     service_args = eval(open(service_args_f).read().strip())
     s = build_service(service_basedir, self.tub, service_type, service_args)
     s.setServiceParent(self)
     return s
Ejemplo n.º 6
0
 def lookup(self, name):
     # walk through our configured services, see if we know about this one
     services = load_service_data(self.basedir)["services"]
     s = services.get(name)
     if not s:
         return None
     service_basedir = os.path.join(self.basedir, s["relative_basedir"])
     service_type = s["type"]
     service_args = s["args"]
     s = build_service(service_basedir, self.tub, service_type, service_args)
     s.setServiceParent(self)
     return s
Ejemplo n.º 7
0
 def lookup(self, name):
     # walk through our configured services, see if we know about this one
     services = load_service_data(self.basedir)["services"]
     s = services.get(name)
     if not s:
         return None
     service_basedir = os.path.join(self.basedir, s["relative_basedir"])
     service_type = s["type"]
     service_args = s["args"] # text
     s = build_service(service_basedir, self.tub, service_type, service_args)
     s.setServiceParent(self)
     return s
Ejemplo n.º 8
0
 def lookup(self, name):
     # walk through our configured services, see if we know about this one
     service_basedir = os.path.join(self.basedir, "services", name)
     if not os.path.exists(service_basedir):
         return None
     service_type_f = os.path.join(service_basedir, "service_type")
     service_type = open(service_type_f).read().strip()
     service_args_f = os.path.join(service_basedir, "service_args")
     service_args = eval(open(service_args_f).read().strip())
     s = build_service(service_basedir, self.tub, service_type,
                       service_args)
     s.setServiceParent(self)
     return s
Ejemplo n.º 9
0
    def lookup(self, name):
        # walk through our configured services, see if we know about this one
        services = load_service_data(self.basedir)["services"]

        service_desc = services.get(name)

        if service_desc:
            service_basedir = os.path.join(self.basedir,
                                           service_desc["relative_basedir"])
            service_type = service_desc["type"]
            service_args = [arg for arg in service_desc["args"]]

            service = build_service(service_basedir, self.tub, service_type,
                                    service_args)
            service.setServiceParent(self)

            return service
Ejemplo n.º 10
0
    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