Beispiel #1
0
def fabric_cmd_completer(self, event):
    completion_log.info("event [{0}]".format(event.__dict__))
    if event.symbol.startswith("-"):
        return []
    if ope("fabfile.py"):
        _fabfile = "fabfile.py"
    elif ope("Fabfile.py"):
        _fabfile = "Fabfile.py"
    else:
        smash_log.info("no fabfile was found")
        return []
    with open(_fabfile, "r") as fhandle:
        src = fhandle.read()
    node = ast.parse(src)
    return list([x.name for x in ast.walk(node) if isinstance(x, ast.FunctionDef)])
def update(project):
    build(project)
    proot = opj(src_root, project)
    output = opj(proot, 'output')
    prod_dir = opj(src_root)
    assert ope(output)
    target = opj(ghio_root, project)
    if not ope(target):
        os.mkdir(target)
    cmd = "cp -rfv {0}/* {1}".format(output, target)
    local(cmd)
    local("git add -A {0}".format(target))
    local("cd {0} && git commit {1} -m \"{2}\"".format(
        ghio_root, project,'update '+project))
    local("git push")
Beispiel #3
0
 def _recent(self):
     """ return a list of the top 10 most recently changed files in the
         current project's directory, where list[0] was changed most
         recently.  this automatically takes into account ignoring dotfiles
         and .gitignore contents.
     """
     gitignore = os.path.join(
         self._project_manager._project_dir,
         '.gitignore')
     patterns = ['*/.*/*']
     if ope(gitignore):
         with open(gitignore) as fhandle:
             patterns += [x.strip() for x in fhandle.readlines()]
     patterns = ' -and '.join(['! -wholename "{0}"'.format(p)
                               for p in patterns])
     if patterns:
         patterns = '\\( {0} \\)'.format(patterns)
     sed = """| sed 's/[^[:space:]]\+ //';"""
     base_find = 'find {0} -type f {1}'.format(
         self._project_manager._project_dir, patterns)
     cmd = '{0} -printf "%T+ %p\n" | sort -n {1}'.format(base_find, sed)
     filenames = self._project_manager.smash.system(cmd, quiet=True)
     filenames = filenames.split('\n')
     filenames.reverse()
     return filenames[:10]
Beispiel #4
0
 def push(self, lines):
     result = super(SmashInputSplitter, self).push(lines)
     lines = lines.strip()
     match = re.compile(r_ed).match(lines)
     if match:
         fname = match.group().split()[1]
         if ope(fname):
             self.source += '\n'
     return result
Beispiel #5
0
def get_tox_envs(_dir=None):
    """ """
    ini_file = "tox.ini" if _dir is None else opj(dir, "tox.ini")
    if ope(ini_file):
        config = ConfigParser.ConfigParser()
        with open("tox.ini") as fhandle:
            config.readfp(fhandle)
        env_list = [x.split(":")[-1] for x in config.sections() if ":" in x]
        return env_list
Beispiel #6
0
def summarize(parameter_s=''):
    _dir = parameter_s or os.getcwd()
    assert ope(_dir)
    tmp = guess_dir_type(_dir)
    print console.red('match types:')
    console.draw_line()
    print ' {0}'.format(tmp)
    print console.red('virttualenvs:')
    console.draw_line()
    print ' {0}'.format(find_venvs(_dir))
    print console.red('sloccount:')
    for report_section in sloccount(_dir):
        console.draw_line()
        print report_section.strip()
    console.draw_line()
Beispiel #7
0
    def deactivate(self):
        try:
            venv = get_venv()
        except KeyError:
            self.warning("no venv to deactivate")
            return False
        else:
            if not venv:
                return False
            self.report("venv_deactivate: " + venv)
            self.publish(C_PRE_DEACTIVATE, venv)

            if not ope(venv):
                self.warning('refusing to deactivate (relocated?) venv')
                return  # raise RuntimeError(err)

            del os.environ['VIRTUAL_ENV']
            path = get_path()
            path = path.split(':')

            # clean $PATH according to bash..
            # TODO: also rehash?
            vbin = to_vbin(venv)
            if vbin in path:
                msg = 'removing old venv bin from PATH: ' + \
                      summarize_fpath(str(vbin))
                self.report(msg)
                path.remove(vbin)
                os.environ['PATH'] = ':'.join(path)

            # clean sys.path according to python..
            # stupid, but this seems to work
            msg = 'clean sys.path'  # ,sys.path_changes)
            self.report(msg)
            smash_log.info(msg)
            reset_path = getattr(self, 'reset_path', None)
            if reset_path is not None:
                msg = str(set(sys.path) ^ set(reset_path))
                msg = 'sys.path difference: {0}'.format(msg)
                self.report(msg)
                smash_log.debug(msg)
                sys.path = reset_path
                self.reset_path = sys.path
            else:
                self.reset_path = sys.path
            self._clean_user_namespace(venv)
            self.publish(C_POST_DEACTIVATE, venv)
            return True
Beispiel #8
0
    def on_file_input(self, fpath):
        def doit(_fpath, _suffix, _opener, _rest):
            if ope(_fpath) and not isdir(_fpath):
                if _opener is not None:
                    self.report(
                        'Using _opener "{0}" for "{1}"'.format(_opener, _suffix))
                    return '{0} {1}'.format(_opener, _fpath + _rest)
                else:
                    msg = "Legit file input, but no _suffix alias could be found for " + \
                        _suffix
                    self.report(msg)
                    if is_editable(_fpath):
                        self.report(
                            "File looks like ASCII text, assuming I should edit it")
                        return doit(_fpath, _suffix, 'ed', _rest)
            else:
                msg = 'Attempted file input, but path "{0}" does not exist'
                msg = msg.format(fpath)
                smash_log.info(msg)

        fpath = abspath(expanduser(fpath))

        if isdir(fpath) and self.automatic_cd:
            self.report('cd ' + fpath)
            self.smash.shell.magic('pushd ' + fpath)
            return True

        # handle input like .foo/bin/python,
        # this shouldn't really even get here but
        # ipython throws a syntax error
        if os.access(fpath, os.X_OK):
            return self.smash.shell.system(fpath)

        # isolate file:col:row syntax
        if not ope(fpath) and ':' in fpath:
            tmp = fpath
            fpath = tmp[:tmp.find(':')]
            rest = tmp[tmp.find(':'):]
        else:
            rest = ''

        # isolate file suffix, guess an opener
        suffix = splitext(fpath)[-1][1:].lower()
        opener = self.suffix_aliases.get(suffix, None)
        cmd = doit(fpath, suffix, opener, rest)
        if cmd:
            self.smash.shell.run_cell(cmd)
            return True
Beispiel #9
0
 def check(self, line_info):
     """ note: the way that line_info splitting happens means
         that for a command like "apt-get foo", first/rest will
         be apt/-get foo.  it's better to just use line_info.line
     """
     if line_info.continue_prompt or not line_info.line.strip():
         return None
     l0 = line_info.line[0]
     dhandler = self.prefilter_manager.get_handler_by_name(DOT_HANDLER_NAME)
     split_line = line_info.line.split()
     if l0 in '~/.':
         #l1 = line[1]
         # if l1 is whitespace, this is probably some special syntax,
         # not something intended as instructions for the system shell
         # thus we will not mess with the input (perhaps the dot_prefilter
         # is interested in it.  see smashlib.dot_prefilter)
         if l0 == '.' and not ope(split_line[0]):
             return dhandler
Beispiel #10
0
 def doit(_fpath, _suffix, _opener, _rest):
     if ope(_fpath) and not isdir(_fpath):
         if _opener is not None:
             self.report(
                 'Using _opener "{0}" for "{1}"'.format(_opener, _suffix))
             return '{0} {1}'.format(_opener, _fpath + _rest)
         else:
             msg = "Legit file input, but no _suffix alias could be found for " + \
                 _suffix
             self.report(msg)
             if is_editable(_fpath):
                 self.report(
                     "File looks like ASCII text, assuming I should edit it")
                 return doit(_fpath, _suffix, 'ed', _rest)
     else:
         msg = 'Attempted file input, but path "{0}" does not exist'
         msg = msg.format(fpath)
         smash_log.info(msg)
Beispiel #11
0
 def _bind_project(name, path):
     """ NOTE: be aware this is also used for re-binding """
     if not ope(path):
         self.report("bound project {0} to nonexistent {1}".format(
             name, path))
     self.update_interface()
Beispiel #12
0
def has_tox(pdir):
    return ope(opj(pdir, "tox.ini"))
Beispiel #13
0
""" smashlib._logging
"""
import os
import logging
from logging.config import dictConfig

from goulash.python import ope


from smashlib.data import (
    D_SMASH_LOGS, LOG_HANDLER_DEFAULTS, LOG_FORMAT_DEFAULT)
from goulash._os import touch_file
from IPython.utils.coloransi import TermColors

if not ope(D_SMASH_LOGS):
    os.makedirs(D_SMASH_LOGS)

def _get_file(_name):
    log_file = os.path.join(D_SMASH_LOGS, '{0}.log'.format(_name))
    touch_file(log_file)
    return log_file

def _get_handler(_file):
    _handler = LOG_HANDLER_DEFAULTS.copy()
    _handler['filename'] = _file
    return _handler

#Empty string here corresponds to default (smash.log)
MAIN_LOGS = ['', 'events','scheduler', 'completion']

LOG_HANDLERS = dict([
 def newf(*args, **kargs):
     project = args[0]
     proot = opj(src_root, project)
     assert ope(proot), "{0} does not exist".format(proot)
     return fxn(*args, **kargs)
Beispiel #15
0
 def ensure():
     canonical_user_prof = os.path.join(
         SMASHLIB_DIR, 'user_config.py')
     if not ope(USER_CONFIG_PATH):
         shutil.copy(canonical_user_prof, USER_CONFIG_PATH)