Ejemplo n.º 1
0
def git_branch():
    result = qlocal('''git branch|grep \*''', capture=True).strip().split()
    result = result[-1] if result else ''
    changes=qlocal('git ls-files -m', capture=True).strip()
    if changes:
        return '{color.Red}' + result + '{color.Normal}'
    else:
        return '{color.Green}' + result + '{color.Normal}'
    return result
Ejemplo n.º 2
0
 def __call__(self):
     if self.type == 'python':
         fxn = from_dotpath(self.value)
         if not callable(fxn):
             err = ("prompt component {0} references "
                    "something that's not callable!")
             err = err.format(dict(self))
             raise PromptError(err)
         result = fxn()
     elif self.type == 'literal':
         result = self.value
     elif self.type == 'shell':
         result = qlocal(self.value, capture=True).strip()
     elif self.type == 'env':
         if self.value.startswith('$'):
             value = self.value[1:]
         else:
             value = self.value
         result = os.environ.get(value, '')
     else:
         err = 'invalid prompt component: {0}'
         err = err.format(self)
         raise Exception(err)
     # post-processing
     if result and self.space_margins:
         if self.space_margins == True or \
                 self.space_margins.lower() == 'true':
             result = ' {0} '.format(result)
     if self.color:
         # have to use IPython's formatting rules so that IPython
         # can correctly calculate terminal width w/ invisible chars
         return '{color.' + self.color.title() + '}' + result + '{color.Normal}'
     else:
         return result
Ejemplo n.º 3
0
 def which(self, query):
     #system_result = self.smash.system('which {0}'.format(query)).strip()
     system_result = qlocal('which {0}'.format(query), capture=True).strip()
     try:
         python_result = __import__(query)  # sys.modules.get(query, None)
     except ImportError, e:
         #self.report("error importing: "+str(e))
         python_result = None
Ejemplo n.º 4
0
def is_editable(_fpath):
    """ guess whether _fpath can be edited, based on
        the output of the file(1) utility.  this function
        refuses to guess if file(1) is not available.

        FIXME: check if its small
    """
    # flimit = 712020
    # if flimit < os.path.getsize(line):
    #   msg = ("warning: maybe you wanted to edit"
    #          " that file but it looks big")
    #   self.report(msg)
    if has_bin('file'):
        file_result = qlocal('file {0}'.format(_fpath), capture=True).strip()
        if 'ASCII text' in file_result or \
           'Unicode text' in file_result or \
           file_result.endswith('empty'):
            return True
        else:
            return False
Ejemplo n.º 5
0
 def system(self, cmd, quiet=False):
     return qlocal(cmd, capture=True)
Ejemplo n.º 6
0
 def test_qlocal(self):
     tmp = gfabric.qlocal('date', capture=True)
     self.assertTrue(tmp)
     self.assertTrue(tmp.succeeded)