Exemple #1
0
 def pack(self, output_path, verbose=False, workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Exemple #2
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(
         Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace,
                                                  self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path,
                                          self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
Exemple #3
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace, self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path, self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
             "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument(
        "--project",
        help="create a new package based on the project at the specified "
             "location. If not specified will assume current directory '{}'"
             .format(os.getcwd()),
        required=False)

    parser.add_argument(
        "-d", "--destination",
        help="create the package on the specified location",
        required=False)

    parser.add_argument(
        "-n", "--name",
        help="create the package with the specific name",
        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    prj_root = args.project if args.project else os.getcwd()

    # Validate given arguments
    path_ids = dict()
    path_ids[ws_root] = Workspace.__descriptor_name__
    path_ids[prj_root] = Project.__descriptor_name__
    if not __validate_directory__(paths=path_ids):
        return

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)
    project = Project.__create_from_descriptor__(workspace, prj_root)

    pck = Packager(workspace, project, dst_path=args.destination)
    pck.generate_package(args.name)
Exemple #5
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
        "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    parser.add_argument(
        "--project",
        help="create a new package based on the project at the specified "
        "location. If not specified will assume current directory '{}'".format(
            os.getcwd()),
        required=False)

    parser.add_argument("-d",
                        "--destination",
                        help="create the package on the specified location",
                        required=False)

    parser.add_argument("-n",
                        "--name",
                        help="create the package with the specific name",
                        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    prj_root = args.project if args.project else os.getcwd()

    # Validate given arguments
    path_ids = dict()
    path_ids[ws_root] = Workspace.__descriptor_name__
    path_ids[prj_root] = Project.__descriptor_name__
    if not __validate_directory__(paths=path_ids):
        return

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)
    project = Project.__create_from_descriptor__(workspace, prj_root)

    pck = Packager(workspace, project, dst_path=args.destination)
    pck.generate_package(args.name)
Exemple #6
0
 def pack(self,
          output_path,
          verbose=False,
          workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Exemple #7
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
        "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    exclusive_parser = parser.add_mutually_exclusive_group(required=True)

    exclusive_parser.add_argument(
        "--project",
        dest="project",
        help="create a new package based on the project at the specified "
        "location. If not specified will assume current directory '{}'".format(
            os.getcwd()),
        required=False)

    exclusive_parser.add_argument(
        "--custom",
        dest="custom",
        help="Create a custom package. Contents and descriptors can be added "
        "using the '--service' and '--function' arguments.",
        action="store_true",
        required=False)
    parser.add_argument(
        "--service",
        dest="service",
        nargs='*',
        help="Only applicable to custom packages. Add a service descriptor "
        "to the package. Multiple services may be specified separated "
        "with a space",
        required=False)
    parser.add_argument(
        "--function",
        dest="function",
        nargs='*',
        help="Only applicable to custom packages. Add a function descriptor "
        "to the package. Multiple functions may be specified separated "
        "with a space",
        required=False)
    parser.add_argument("-d",
                        "--destination",
                        help="create the package on the specified location",
                        required=False)

    parser.add_argument("-n",
                        "--name",
                        help="create the package with the specific name",
                        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)

    prj_root = args.project if args.project else os.getcwd()

    if args.project:

        # Validate given arguments
        path_ids = dict()
        path_ids[ws_root] = Workspace.__descriptor_name__
        path_ids[prj_root] = Project.__descriptor_name__
        if not __validate_directory__(paths=path_ids):
            return

        project = Project.__create_from_descriptor__(workspace, prj_root)

        pck = Packager(workspace, project=project, dst_path=args.destination)
        pck.generate_package(args.name)

    elif args.custom:

        if not (args.service or args.function):
            log.error("To create a custom package, the arguments '--service' "
                      "and/or '--function' must be used.")
            exit(1)

        pck = Packager(workspace,
                       services=args.service,
                       functions=args.function,
                       dst_path=args.destination)
        pck.generate_package(args.name)
Exemple #8
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Generate new sonata package")

    parser.add_argument(
        "--workspace",
        help="Specify workspace to generate the package. If not specified "
             "will assume '{}'".format(Workspace.DEFAULT_WORKSPACE_DIR),
        required=False)

    exclusive_parser = parser.add_mutually_exclusive_group(
        required=True
    )

    exclusive_parser.add_argument(
        "--project",
        dest="project",
        help="create a new package based on the project at the specified "
             "location. If not specified will assume current directory '{}'"
             .format(os.getcwd()),
        required=False)

    exclusive_parser.add_argument(
        "--custom",
        dest="custom",
        help="Create a custom package. Contents and descriptors can be added "
             "using the '--service' and '--function' arguments.",
        action="store_true",
        required=False
    )
    parser.add_argument(
        "--service",
        dest="service",
        nargs='*',
        help="Only applicable to custom packages. Add a service descriptor "
             "to the package. Multiple services may be specified separated "
             "with a space",
        required=False
    )
    parser.add_argument(
        "--function",
        dest="function",
        nargs='*',
        help="Only applicable to custom packages. Add a function descriptor "
             "to the package. Multiple functions may be specified separated "
             "with a space",
        required=False
    )
    parser.add_argument(
        "-d", "--destination",
        help="create the package on the specified location",
        required=False)

    parser.add_argument(
        "-n", "--name",
        help="create the package with the specific name",
        required=False)

    args = parser.parse_args()

    if args.workspace:
        ws_root = args.workspace
    else:
        ws_root = Workspace.DEFAULT_WORKSPACE_DIR

    # Obtain Workspace object
    workspace = Workspace.__create_from_descriptor__(ws_root)

    prj_root = args.project if args.project else os.getcwd()

    if args.project:

        # Validate given arguments
        path_ids = dict()
        path_ids[ws_root] = Workspace.__descriptor_name__
        path_ids[prj_root] = Project.__descriptor_name__
        if not __validate_directory__(paths=path_ids):
            return

        project = Project.__create_from_descriptor__(workspace, prj_root)

        pck = Packager(workspace, project=project, dst_path=args.destination)
        pck.generate_package(args.name)

    elif args.custom:

        if not (args.service or args.function):
            log.error("To create a custom package, the arguments '--service' "
                      "and/or '--function' must be used.")
            exit(1)

        pck = Packager(workspace, services=args.service,
                       functions=args.function, dst_path=args.destination)
        pck.generate_package(args.name)