Пример #1
0
    def run_command(self, args):
        # make list of pybrat projects
        if hasattr(args, 'command'):
            del args.command
        args_d = vars(args)

        # get the list for the given project & set list type
        proj_d = get_project_list(args_d)
        if not proj_d:
            print "No projects or venvs found."
            return True
        proj_t = ['venv',] if args_d['venv'] else [t for t in args_d.keys() 
                                               if args_d[t] is True]
        if not proj_t:
            proj_t = ['pybrat',]

        # list the projects and respect. pythons, venvs
        for proj in proj_d:
            if 'srcpath' in proj_d[proj]:
                print "{}".format(PYBRAT_SHGREEN) + "%-24s " % proj ,
                print "{}".format(PYBRAT_SHGRAY) + "(%s)" % proj_d[proj]['srcpath']
            for vname, venv in proj_d[proj]['venv'].iteritems():
                print "{}".format(PYBRAT_SHWHITE) ,
                print "%24s" % ("%s [%-5s]" % (vname, venv['python'])) ,
                print "{0}({1})".format(PYBRAT_SHGRAY, venv['vpath'])

        # all done?
        return True
Пример #2
0
    def run_command(self, args):
        # rm venv 'project' ONLY
        if args.brew:
            vname = args.project
            print "Deleting given pythonbrew virtualenv '{}' ONLY...".format(vname)
            # check if target venv is linked in pybrat project
            proj_d = get_project_list({'pybrat': True,})
            for proj in proj_d.keys():
                if vname in proj_d[proj]['venv'].keys():
                    pv_proj_dir = proj_d[proj]['srcpath']
                    print "Venv '{0}' is being used by project '{1}'.".format(vname, proj)
                    print "Deleting it will break a link unless you delete the link too."
                    if get_input_bool("Cleanup the pybrat project as well? [y/N] ",
                                      default_answer=False):
                        # rm venv and cleanup project
                        if not pb_rmvenv(vname, pv_proj_dir):
                            print "Remove Error: {} was not deleted".format(args.project)
                            return False
                        return True

            # venv not in any pybrat project so no worries...
            if not pb_rmvenv(vname):
                print "Remove Error: {} was not deleted".format(args.project)
                return False
            return True


        # still here? then delete the rest of the pybrat project...
        pv_projd = join(PYBRAT_PROJD, args.project)

        if not lexists(pv_projd):
            print "Warning: {} does not exist".format(pv_projd)
            return False

        print "==> Removing project '{}'...".format(args.project)

        # if 'pythonbrew venv delete project'...?
        if args.venv:
            print "Deleting linked virtualenv(s)..." 
            if not pv_rmvenv(pv_projd):
                print "Remove Error: {} was not deleted".format(pv_projd)
                return False

        # remove .pybrat dir in user's project dir
        pv_subd = join(readlink(pv_projd), ".{}".format(PYBRAT_PROG))

        if not lexists(pv_subd):
            print "Warning: {} does not exist.".format(pv_subd)
        else:
            rmtree(pv_subd, ignore_errors=True)
            print "Removed .pybrat subdirectory {}".format(pv_subd)

        # remove pybrat project link in .pybrat_projects/
        remove(pv_projd)
        print "Removed pybrat project {}".format(pv_projd)

        # all done deleting shit? ok...
        return True
Пример #3
0
    def run_command(self, args):
        # validate the project dir to target for ln in .pybrat/projects
        proj_dir = abspath(args.project)
        vname = args.virtualenv if not args.venv else basename(args.virtualenv)
        print "Initializing project '{}'...".format(proj_dir)
        if not exists(proj_dir):
            print "Init Error: project directory '{}' not found.".format(proj_dir)
            return False

        # do we need to import given venv to pythonbrew first?
        if args.wrap or args.venv:
            if args.wrap:
                venv_d = (get_project_list({'wrap':True,}))['wrap']['venv']
            elif args.venv:
                venv_d = (get_project_list({'venv':args.virtualenv,}))['venv']['venv']
                args.virtualenv = basename(args.virtualenv)
            if vname in venv_d.keys():
                venv = venv_d[vname]
                # make pythonbrew venv
                print "Importing ({}) [{}] to pythonbrew...".format(vname, venv['python'])
                venv_dir = pv_mkvenv(vname, venv['python'])
                if not venv_dir:
                    print "Make Error: unable to create venv {}.".format(proj_name)
                    return False

        # safe to get pythonbrew venv dict now...
        venv_d = (get_project_list({'brew':True,}))['brew']['venv']
        if args.virtualenv not in venv_d.keys():
            print "Init Error: venv '{}' not found.".format(args.virtualenv)
            return False
        venv_dir = venv_d[args.virtualenv]

        # send to linking function
        if not pv_link_projs(venv_dir, proj_dir):
            print "Init Error: pythonbrew venv not linked to '{}'.".format(proj_dir)
            return False

        # add project link to .pybrat_projects/
        return pv_add_proj(proj_dir)
Пример #4
0
 def run_tests(self, args):
     print "for '{}'...{}".format(args.project, PYBRAT_SHGRAY)
     testout = self.run_subcmd(args)
     if args.verbose > 1:
         print testout.getvalue()
     if args.project in get_venv_dict({'brew':True}).keys():
         if args.verbose:
             print "==> Found '{}' venv.".format(args.project)
         result = True
     else:
         result = False
     if not args.brew:
         if args.project in get_project_list({'pybrat':True}).keys():
             if args.verbose:
                 print "==> Found '{}' project.".format(args.project)
         else:
             result = False
     return result
Пример #5
0
 def run_tests(self, args):
     print "for '{}'...{}".format(args.project, PYBRAT_SHGRAY)
     testout = self.run_subcmd(args)
     if args.verbose > 1:
         print testout.getvalue()
     proj_d = get_project_list({'pybrat':True})
     result = True
     if args.project in proj_d.keys():
         if args.verbose:
             print "==> Found '{}' project.".format(args.project)
     else:
         result = False
     if args.virtualenv in proj_d[args.project]['venv']:
         if args.verbose:
             print "==> Found '{}' venv.".format(args.virtualenv)
     else:
         result = False
     return result
Пример #6
0
 def run_tests(self, args):
     print "for '{}'...{}".format(args.project, PYBRAT_SHGRAY)
     if not args.brew:
         pre_venv_d = get_venv_dict({'pybrat':args.project})
     testout = self.run_subcmd(args)
     if args.verbose > 1:
         print testout.getvalue()
     if args.brew:
         if args.project not in get_venv_dict({'brew':True}).keys():
             if args.verbose:
                 print "==> '{}' removed.".format(args.project)
             return True
         else:
             return False
     post_venv_d = get_venv_dict({'pybrat':args.project})
     for vname in pre_venv_d.keys():
         if vname not in post_venv_d.keys():
             if args.verbose:
                 print "==> '{}' removed.".format(vname)
         else:
             return False
     if args.project in get_project_list({'pybrat':True}).keys():
         return False
     return True
Пример #7
0
    def run_command(self, args):
        # check for PYTHONPATH in environ
        if not "PYTHONPATH" in environ:
            return print_err("could not find PYTHONPATH in the environ.")

        # check if given project name is pybrat project else treat as python version
        if args.python:
            venv = {'python':[args.project,]}
        else:
            proj_d = get_project_list({'pybrat':True,})
            if not args.project in proj_d.keys():
                return print_err("pybrat project '{}' not found.".format(args.project))

            proj = proj_d[args.project]
            # check project/.pybrat subdir integrity
            pv_subd = join(proj['srcpath'], ".{}".format(PYBRAT_PROG))
            pv_check_subd(pv_subd, args={'all':True})
            # check if project is multi-venv
            if not args.venv and len(proj['venv']) > 1:
                return print_err("use '-v VENV' option to use multi-venv project")
            # if multi-venv, check for the venv
            if not args.venv:
                venv = proj['venv'].values()[0]
            else:
                if args.venv not in proj['venv']:
                    return print_err("VENV '{}' not found".format(args.venv))
                venv = proj['venv'][args.venv]

        # venv_d all set? then set pythonbrew PYTHONPATH base...
        new_pypath = join( PYBRAT_PYBREW_PYD, 
                           "Python-{}".format(venv['python']) )
        if not exists(new_pypath):
            return print_err("could not find 'Python-{}'.".format(venv['python']))
        # ... and PATH setting...
        path_l = environ['PATH'].split(':')
        for p in path_l:
            if PYBRAT_PYBREW_PYD in p:
                del path_l[path_l.index(p)]
        path_l.insert(0, join(new_pypath, "bin"))
        new_path = ":".join(path_l)

        # set up environ variables dict (all subshells)
        envdict = { 'PYBRAT_PYTHONPATH':join(new_pypath, "lib"), 
                    'PYBRAT_PATHS':new_path,'PYBRAT_PYTHON':venv['python'], }
        # if activating a venv as well as a python...
        if not args.python:
            hooksd = join(pv_subd, "hooks")
            envdict.update({ 'PYBRAT_WORKD':proj['srcpath'],
                             'PYBRAT_VENV':basename(venv['vpath']), 
                             'PYBRAT_PROJ_HOOKSD':hooksd, })

        # execute subshell
        runok = pv_run_processes(exelist=[], envdict=envdict, bash=True)
        if not runok:
            return print_err("subshell process error")
        # if postdeactivate run in parent shell 
        if exists(join(hooksd, "postdeactivate")):
            if not pv_run_processes([[join(hooksd, "postdeactivate")],]):
                return print_err("postdeactivate subprocess failed")

        # all done?
        return True