Beispiel #1
0
 def _chdir_testdir(self, old_dir=""):
     if not old_dir:
         old_dir = os.getcwd()
         print "Changing to pybrat test dir '{}'...".format(self.test_dir)
         pv_mkdirs(self.test_dir)
         os.chdir(self.test_dir)
         return old_dir
     else:
         print "Changing back to your dir '{}'...".format(old_dir)
         os.chdir(old_dir)
         shutil.rmtree(self.test_dir)
         return None
Beispiel #2
0
    def run_command(self, args):

        proj_name = basename(args.project)
        proj_dir = abspath(args.project)
        print "Making new project '%s' [%s]..." % (proj_dir, args.python)

        # check that project dir and venv don't exist
        if not args.brew:
            if exists(proj_dir):
                print "Make Error: '{}' already exists.".format(proj_dir)
                return False

        # make pythonbrew venv
        venv_dir = pv_mkvenv(proj_name, args.python, args.site)
        if not venv_dir:
            print "Make Error: unable to create venv {}.".format(proj_name)
            return False
        if args.brew:
            return True

        # make project dir
        if not pv_mkdirs(proj_dir):
            print "Make Error: unable to create {}.".format(proj_dir)
            return False

        # else everything set so link venv in project dir
        if not pv_link_projs(venv_dir, proj_dir):
            print "Init Error: venv not linked to '{}'.".format(proj_name)
            return False

        # add project link to .pybrat_projects/
        return pv_add_proj(proj_dir)
Beispiel #3
0
def _install_pybrat(install_path):
    # makedirs
    for p in PYBRAT_PATHS:
        if not exists(p):
            print "Creating directory at: {}".format(p)
            if not pv_mkdirs(p):
                return False

    # copy python scripts to user's ~/.config/pybrat/scripts/
    fdict = {}
    for root, dirs, files in os.walk(install_path):
        # in /scripts/ dir
        if basename(root) == 'scripts':
            del dirs[dirs.index('installer')]
            fdict['scripts'] = {}
            for f in files:
                fname, fext = splitext(f)
                if 'install' not in fname:
                    if fext == '.py':
                        fdict['scripts'][f] = {'cpfrom': join(root, f), 
                                               'cpto': PYBRAT_PROGD}
        if basename(root) == 'etc':
            fdict['etc'] = {}
            for f in files:
                fname, fext = splitext(f)
                if fext == '' and fname == 'bashrc':
                    fdict['etc'][f] = {'cpfrom': join(root, f), 
                                       'cpto': PYBRAT_ETCD}
        if basename(root) == 'hooks':
            fdict['hooks'] = {}
            for f in files:
                fname, fext = splitext(f)
                if fext == '.skel':
                    fdict['hooks'][f] = {'cpfrom': join(root, f),
                                         'cpto': PYBRAT_HOOKSD}
        # ...in the /scripts/pybrat/ dir
        if basename(root) == 'pybrat':
            fdict['pybrat'] = {}
            for f in files:
                fname, fext = splitext(f)
                if fext == '.py':
                    fdict['pybrat'][f] = {'cpfrom': join(root, f),
                                          'cpto': PYBRAT_PROGD}
        # ...in /scripts/pybrat/subcommands dir
        if basename(root) == 'subcommands':
            fdict['subcommands'] = {}
            for f in files:
                fname, fext = splitext(f)
                if fext == '.py':
                    fdict['subcommands'][f] = {'cpfrom': join(root, f),
                                               'cpto': PYBRAT_SUBCMDD}
    # fix 'pybrat_main.py' target
    fdict['scripts'][PYBRAT_MAINF]['cpto'] = join(PYBRAT_MAIND, PYBRAT_MAINF)

    # copy the files!
    for file_d in fdict.values():
        for f in file_d.values(): 
            if isfile(f['cpfrom']):
                copy2(f['cpfrom'], f['cpto'])
                print "Copied:\t" + f['cpfrom'] + "\n\t==> " + f['cpto']

    # make command script and link into user path
    if not isfile(PYBRAT_CMD):
        print "Installing Pybrat command at:"
        print "\t{}".format(PYBRAT_CMD)

        if not pv_mkfile(PYBRAT_CMD, 0755, PYBRAT_CMD_STR):
            return False