def set(self, shell=None, ptask=None): # unset any previous custom env vars self._unset_custom_vars(shell=shell) # cd into the ptask directory os.chdir(self.path) if shell: print shell.cd(self.path) # check for config file self._process_config(shell=shell, ptask=ptask) # set the appropriate environment variables self.env.set(shell=shell) # add this spec to the history if ptask: if self.version: spec = self.spec + PTaskSpec.VERSION + self.version PTaskHistory().add(spec) else: PTaskHistory().add(self.spec) # set the shell prompt if preferred if shell: ptask_prompt = DpaVars.ptask_prompt().get() no_ptask_prompt = DpaVars.no_ptask_prompt().get() if ptask and ptask_prompt: print shell.set_prompt(ptask_prompt) elif no_ptask_prompt: print shell.set_prompt(no_ptask_prompt)
def previous(cls): try: previous_area_spec = PTaskHistory().previous version = None if PTaskSpec.VERSION in previous_area_spec: (previous_area_spec, version) = previous_area_spec.split( PTaskSpec.VERSION) return cls(previous_area_spec, validate=False, version=version) except PTaskAreaError: return cls("")
def latest(cls): try: latest_area_spec = PTaskHistory().latest version = None if PTaskSpec.VERSION in latest_area_spec: (latest_area_spec, version) = latest_area_spec.split( PTaskSpec.VERSION) return cls(latest_area_spec, validate=False, version=version) except PTaskAreaError: return cls("")
def previous(cls): try: previous_area_spec = PTaskHistory().previous version = None if PTaskSpec.VERSION in previous_area_spec: (previous_area_spec, version) = previous_area_spec.split(PTaskSpec.VERSION) return cls(previous_area_spec, validate=False, version=version) except PTaskAreaError: return cls("")
def latest(cls): try: latest_area_spec = PTaskHistory().latest version = None if PTaskSpec.VERSION in latest_area_spec: (latest_area_spec, version) = latest_area_spec.split(PTaskSpec.VERSION) return cls(latest_area_spec, validate=False, version=version) except PTaskAreaError: return cls("")
def _get_ptask_spec_history(self): # reversed so most recent is first in the list specs = reversed(PTaskHistory().get()) # remove duplicates but preserve order: # http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order unique_specs = set() unique_add = unique_specs.add return [s for s in specs if not (s in unique_specs or unique_add(s))]