예제 #1
0
    def _link_sub(self, sub, app):

        area = PTaskArea(self.ptask.spec, version=self.version)

        product_ver = sub.product_version

        try:
            product_ver_area = PTaskArea(product_ver.spec)
        except PTaskAreaError as e:
            raise ActionError("Unable to locate product directory for: " +
                              product_ver.spec)

        product_ver_path = product_ver_area.path

        product = product_ver.product

        product_ver_import_dir = os.path.join('import', app, product.name)

        try:
            area.provision(product_ver_import_dir)
        except PTaskAreaError as e:
            raise ActionError("Failed to provision product import dir: " +
                              str(e))

        link_name = os.path.join(area.path, product_ver_import_dir,
                                 product.category)

        print "Creating subscription {a} link for: {pv}".format(
            a=app, pv=product_ver.spec)

        os.symlink(product_ver_path, link_name)

        product_ver_area = PTaskArea(product_ver.spec)
예제 #2
0
    def _complete(self, spec, relative_to=None):

        in_spec = self.spec.strip().strip(PTaskSpec.SEPARATOR)
        full_spec = PTaskSpec.get(in_spec, relative_to=relative_to)
        ptask_area = None

        # is the supplied spec a ptask area? if so, print sub directories
        # if not, get the parent spec and print its sub directories
        try:
            ptask_area = PTaskArea(full_spec)
        except PTaskAreaError:
            in_spec = PTaskSpec.parent(in_spec)
            full_spec = PTaskSpec.parent(full_spec)
            try:
                ptask_area = PTaskArea(full_spec)
            except PTaskAreaError:
                pass

        if not ptask_area:
            return

        # append the child name to the input spec and print them out for completion
        match_specs = []
        for area_dir in ptask_area.dirs(children=True, product_dirs=True):
            if in_spec:
                match_specs.append(in_spec + PTaskSpec.SEPARATOR + area_dir)
            else:
                match_specs.append(area_dir)

        return [m + PTaskSpec.SEPARATOR for m in match_specs]
예제 #3
0
    def area(self):
        """:returns: PTaskArea for this ptask."""

        if not hasattr(self, '_area'):
            self._area = PTaskArea(self.spec)

        return self._area
예제 #4
0
    def import_path(self, app='global'):
        product = self.product_version.product
        area = PTaskArea(self.ptask_version.ptask.spec)
        import_dir = area.dir(dir_name="import", verify=False, path=True)

        path = os.path.join(import_dir, app, product.name, product.category)
        
        if not os.path.exists(path):
            raise ProductSubscriptionError("Import path does not exist.")

        return path
예제 #5
0
파일: create.py 프로젝트: liudger/dpa-pipe
    def _create_ptask_area(self):

        # ---- create the directory path if it doesn't exist

        try:
            self._ptask_area = PTaskArea(self.ptask.spec)
        except PTaskAreaError:
            pass
        else:
            if not self.force:
                raise ActionError("PTask area already exists.")

        if not self.ptask_area:
            try:
                self._ptask_area = PTaskArea.create(self.ptask)
            except PTaskAreaError as e:
                raise ActionError("Failed to create ptask area: " + str(e))
예제 #6
0
파일: sync.py 프로젝트: liudger/dpa-pipe
    def _get_filter_rules(self, ptask):

        ptask_area = PTaskArea(ptask.spec, validate=False) 
        filter_config = ptask_area.config(
            FILTER_RULES_CONFIG_PATH,
            composite_ancestors=True,
        )
        
        includes = []
        excludes = []

        if 'includes' in filter_config:
            includes = filter_config.includes

        if 'excludes' in filter_config:
            excludes = filter_config.excludes
    
        return (includes, excludes)
예제 #7
0
    def _prep_import_dir(self):

        area = PTaskArea(self.ptask.spec, version=self.version)
        import_dir = area.dir(dir_name="import", verify=False, path=True)

        if os.path.exists(import_dir):
            print "Cleaning up existing import directory."
            try:
                shutil.rmtree(import_dir)
            except Exception as e:
                raise ActionError("Failed to remove old import dir: " + str(e))

        global_import_dir = os.path.join('import', 'global')

        try:
            print "Provisioning new import directory."
            area.provision('import')
            area.provision(global_import_dir)
        except PTaskAreaError as e:
            raise ActionError("Failed to provision global import directory: " +
                              str(e))

        return area.dir(dir_name=global_import_dir, path=True)
예제 #8
0
파일: env.py 프로젝트: liudger/dpa-pipe
    def _print_ptask_env(self):

        # remove any whitespace on the head/tail of the spec
        spec = self.spec.strip()
        ptask_area = None

        if self.version:
            spec = PTaskSpec.VERSION.join([spec, str(self.version)])

        replace_match = re.match("\.?/([=\w]+)/([=\w]+)/", spec)

        # handle 'none' as a valid spec - unset current ptask (set it to root)
        if spec.lower() == 'none':
            spec = ""
            full_spec = PTaskSpec.get(spec)
            try:
                ptask_area = PTaskArea(full_spec)
            except:
                pass

        # special character '-' indicates use the last set ptask spec
        elif spec == "-":
            ptask_area = PTaskArea.previous()

        # set to a similar ptask with text replacement
        elif replace_match:

            cur_area_spec = PTaskArea.current().spec
            repl_spec = cur_area_spec.replace(replace_match.group(1),
                                              replace_match.group(2))
            try:
                ptask_area = PTaskArea(repl_spec)
            except:
                pass

        # use the supplied spec relative to the current ptask
        else:

            relative_to = PTaskArea.current().spec

            while ptask_area is None:

                try:
                    full_spec = PTaskSpec.get(spec, relative_to=relative_to)
                except PTaskSpecError as e:
                    raise ActionError(str(e))

                try:
                    # if this is successful, we'll break out of the while
                    ptask_area = PTaskArea(full_spec)
                except PTaskAreaError as e:
                    # no match, check the parent relative spec
                    relative_to = PTaskSpec.parent(relative_to)
                    # there is no parent, break out of the while
                    if relative_to is None:
                        break

        # dump out commands used for setting the environment for the supplied
        # spec.

        if not ptask_area:
            raise ActionError(
                "Could not determine ptask area from: " + str(spec), )

        ptask = None

        # delay the db query to this point to prevent multiple, unnecessary db
        # queries. if we're at this point, we know there's at least a
        # corresponding directory on disk.
        if ptask_area.base_spec:
            try:
                ptask = PTask.get(ptask_area.base_spec)
            except PTaskError as e:
                pass

        if not ptask and ptask_area.spec != "":
            raise ActionError("Could not determine ptask from: " + str(spec))

        ptask_area.set(shell=self.shell, ptask=ptask)
예제 #9
0
파일: create.py 프로젝트: liudger/dpa-pipe
    def prompt(self):

        parent_spec = PTaskSpec.parent(self.spec)
        template_options = []

        if parent_spec:
            par_ptask = PTask.get(parent_spec)
            par_ptask_type = par_ptask.ptask_type
        else:
            par_ptask_type = 'none'

        ptask_area = PTaskArea(parent_spec, validate=False)
        master_config = ptask_area.config(
            PROJECT_MASTER_CONFIG_PATH,
            composite_ancestors=True,
        )

        if not master_config or not hasattr(master_config, 'hierarchy'):
            raise ActionError("Unable to find project master config.")

        if not self.ptask_type in master_config.hierarchy[par_ptask_type]:
            raise ActionError(
                "Cannot create '{t}' ptask inside '{p}' ptask".format(
                    t=self.ptask_type,
                    p=par_ptask_type,
                ))

        # ---- prompt for missing fields
        if not self.source and self.ptask_type in master_config.templates:
            for template_spec in master_config.templates[self.ptask_type]:
                trimmed_spec = re.sub("^templates?=",
                                      "",
                                      template_spec,
                                      flags=re.IGNORECASE)
                template_options.append(
                    (re.sub("[=_-]+", " ",
                            trimmed_spec).title(), template_spec))

            self._source = Output.prompt_menu(
                "Select a template to source",
                prompt_str="Selection",
                options=template_options,
                help_str="Please choose from the templates listed.",
                none_option=True,
                custom_prompt="Custom Source",
                custom_blank=False)

        # see if the ptask already exists
        if not self.ptask:
            try:
                self._ptask = PTask.get(self.spec)
            except PTaskError:
                pass
            else:
                if not self.force:
                    raise ActionAborted("PTask already exists.")
                else:
                    if not self._description:
                        self._description = self.ptask.description
                    if not self._start_date:
                        self._start_date = self.ptask.start_date
                    if not self._due_date:
                        self._due_date = self.ptask.due_date

        if (not self.description or not self.start_date or not self.due_date):

            if self.force:
                raise ActionError(
                    "Cannot force creation without required fields.")
            else:
                print "\nPlease enter information about this new {b}{t}{r}:".\
                    format(
                        b=Style.bright,
                        t=self.ptask_type,
                        r=Style.reset,
                    )

        ptask_display = " [{pt}] {b}{s}{r}".format(
            pt=self.ptask_type,
            b=Style.bright,
            s=self.spec,
            r=Style.reset,
        )

        if not self.description:
            self._description = Output.prompt(
                '{pd} description'.format(pd=ptask_display),
                blank=False,
            )

        if not self.start_date:
            self._start_date = Output.prompt_date(
                '{pd} start date'.format(pd=ptask_display),
                blank=False,
            )

        if not self.due_date:
            self._due_date = Output.prompt_date(
                '{pd} due date'.format(pd=ptask_display),
                blank=False,
            )
예제 #10
0
 def area(self):
     from dpa.ptask.area import PTaskArea    
     return PTaskArea(self.spec, validate=False)
예제 #11
0
 def directory(self):
     from dpa.ptask.area import PTaskArea    
     area = PTaskArea(self.spec, validate=False)
     return area.path