Example #1
0
def get(strings):
    hub = path('~/hub')
    jab = path('~/jab')
    jab_bin = jab / 'bin'
    jab_src = jab / 'src'
    jab_python = jab_src / 'python'
    jab_todo = jab / 'todo.txt'
    config = path('~/.config')
    abbreviations = {
        '2': [
            jab_todo,
            jab_python / 'todo.py',
        ], 'scripts': [
            jab_python / 'scripts.py',
            jab_python / 'site/script_paths.py',
        ], 'v': [
            jab_python / 'vim.py',
            jab_python / 'vim_script.py',
            jab_python / 'site/script_paths.py',
        ], 'rf': [
            jab_python / 'rf.py',
            config / 'rf/config',
        ], 'jpm': [
            hub / 'jpm/jpm/jpm.py',
            hub / 'jpm/bin/jpm',
        ], 'kd':  [
            hub / 'kd/kd.sh',
            hub / 'kd/kd.py',
            config / 'kd',
        ], 'locate': [
            jab_bin / 'locate',
            jab_python / 'site/locate.py',
        ], 'main': [
            hub / 'main.py',
        ], 'paths': [
            hub / 'dotsite/dotpaths.py',
        ], 'whap': [
            hub / 'what/whap.py',
        ], 'what': [
            hub / 'what/what.sh',
            hub / 'what/what.py',
        ],
        # ], '': [
        #    hub / '',
        # ],
    }
    if strings:
        lists_of_paths = [abbreviations[s] for s in strings
                          if s in abbreviations]
    else:
        lists_of_paths = abbreviations.values()
    paths_ = list(itertools.chain(*lists_of_paths))
    return [_ for _ in paths_ if _.isfile()]
Example #2
0
def _get_path_stems(strings, recursive):
    """A list of any paths in strings

    If there is a "/" in the strings then it is used in the list
    Otherwise it is appended to the current working directory
    """
    if not strings:
        strings = []
    here = path('.')
    paths = ['/' in string and path(string) or here / string for string in strings]
    if recursive:
        return add_sub_dirs(paths)
    return paths
Example #3
0
 def remove(self, item):
     """Remove the item from sys.path"""
     directory = path(item).directory()
     if directory in self.paths:
         self.paths.remove(directory)
         if directory in sys.path:
             sys.path.remove(directory)
Example #4
0
 def add(self, item):
     """Add the item to sys.path"""
     directory = path(item).directory()
     if directory not in self.paths:
         self.paths.insert(0, directory)
         if directory not in sys.path:
             sys.path.insert(0, str(directory))
Example #5
0
File: try.py Project: jalanb/dotjab
 def add(self, item):
     """Add the item to sys.path"""
     directory = path(item).directory()
     if directory not in self.paths:
         self.paths.insert(0, directory)
         if directory not in sys.path:
             sys.path.insert(0, str(directory))
Example #6
0
File: try.py Project: jalanb/dotjab
 def remove(self, item):
     """Remove the item from sys.path"""
     directory = path(item).directory()
     if directory in self.paths:
         self.paths.remove(directory)
         if directory in sys.path:
             sys.path.remove(directory)
Example #7
0
 def __init__(self, that):
     self.here = path('.')
     self.home = path('~')
     self.username = os.environ['USER']
     try:
         self.host = os.environ['HOST']
     except KeyError:
         try:
             self.host = os.environ['HOSTNAME']
         except KeyError:
             self.host = None
             if self.home.startswith('/Users'):
                 self.host = 'jab.ook'
     self.user = '******' % (self.username, self.host)
     self.path = self.here.relpathto(that)
     base, _ext = self.path.splitext()
     [self.add_path(base, _) for _ in ['py', 'test', 'tests', 'fail']]
Example #8
0
 def __init__(self, path):
     try:
         self.name = path.namebase
     except AttributeError:
         path = paths.path(path)
     Tag.__init__(self, path, {'address': '1'})
     self.name = path.namebase
     self.address = '1'
Example #9
0
 def add_path(self, base, ext):
     """Add a path for base.ext as an attribute to self"""
     name = 'path_to_%s' % ext
     if hasattr(self, name):
         return
     path_to_ext = path('%s.%s' % (base, ext))
     if path_to_ext.isfile() or ext == 'fail':
         setattr(self, name, path_to_ext)
Example #10
0
 def __init__(self, path):
     try:
         self.name = path.namebase
     except AttributeError:
         path = paths.path(path)
     Tag.__init__(self, path, {'address': '1'})
     self.name = path.namebase
     self.address = '1'
Example #11
0
File: try.py Project: jalanb/dotjab
 def add_path(self, base, ext):
     """Add a path for base.ext as an attribute to self"""
     name = 'path_to_%s' % ext
     if hasattr(self, name):
         return
     path_to_ext = path('%s.%s' % (base, ext))
     if path_to_ext.isfile() or ext == 'fail':
         setattr(self, name, path_to_ext)
Example #12
0
File: try.py Project: jalanb/dotjab
 def __init__(self, that):
     self.here = path('.')
     self.home = path('~')
     self.username = os.environ['USER']
     try:
         self.host = os.environ['HOST']
     except KeyError:
         try:
             self.host = os.environ['HOSTNAME']
         except KeyError:
             self.host = None
             if self.home.startswith('/Users'):
                 self.host = 'jab.ook'
     self.user = '******' % (self.username, self.host)
     self.path = self.here.relpathto(that)
     base, _ext = self.path.splitext()
     [self.add_path(base, _) for _ in ['py', 'test', 'tests', 'fail']]
Example #13
0
def tag_directory_recursively(source):
    """Write tags from the files in/under the directory"""
    path_to_directory = paths.path(source)
    tags = read_dirs_tags(path_to_directory)
    write_tags(path_to_directory, tags)
    for path_to_sub_directory in path_to_directory.walkdirs():
        if repository.is_repository_path(path_to_sub_directory):
            continue
        tag_directory(path_to_directory)
Example #14
0
def tag_directory_recursively(source):
    """Write tags from the files in/under the directory"""
    path_to_directory = paths.path(source)
    tags = read_dirs_tags(path_to_directory)
    write_tags(path_to_directory, tags)
    for path_to_sub_directory in path_to_directory.walkdirs():
        if repository.is_repository_path(path_to_sub_directory):
            continue
        tag_directory(path_to_directory)
Example #15
0
def todo_file():
    """Get the filename from the environment"""
    # Tell pylint not to warn that this is a todo
    # pylint: disable-msg=W0511
    if sys.argv[1:]:
        arg = sys.argv[1]
        if os.path.isfile(arg):
            return arg
    jab = path('~/jab')
    return jab / 'todo.txt'
Example #16
0
def write_dir(path_to_directory, tags):
    """Write the given tags to a tags file in the given directory"""
    out = paths.path('%s/tags' % path_to_directory)
    if out.isdir():
        message = 'Wrote no tags to %s' % out
    else:
        text = tags_to_text(tags)
        out.write_text(text)
        message = 'Wrote tags to %s' % out
    if scripts.args.Verbose:
        print(message)
Example #17
0
def write_tags(path_to_directory, tags):
    """Write the given tags to a tags file in the given directory"""
    out = paths.path('%s/tags' % path_to_directory)
    if out.isdir():
        message = 'Wrote no tags to %s' % out
    else:
        text = tags_to_text(tags)
        out.write_text(text)
        message = 'Wrote tags to %s' % out
    if scripts.args.Verbose:
        print(message)
Example #18
0
def _get_scripts_here(recursive):
    """Find all test scripts in the current working directory"""
    here = path('.')
    result = []
    for python_file in all_possible_test_files_in(here, recursive):
        if has_python_source_extension(python_file):
            text = python_file.text()
            if has_doctests(text):
                result.append(python_file)
        else:
            result.append(python_file)
    return result
Example #19
0
def _get_path_to_test_directory(strings):
    """Get a path to the root directory that we'll be testing in

    We will test in the first directory in strings
        or the directory of the first file in strings
    """
    for string in strings:
        path_to_string = path(string)
        if path_to_string.isdir():
            result = path_to_string
            break
    else:
        for string in strings:
            path_to_string = path(string)
            if path_to_string.parent and path_to_string.isfile():
                result = path_to_string.parent
                break
        else:
            raise UserMessage('No doctests found in %r' % strings)
    if not result.files('*.test*') and not result.files('*.py'):
        raise UserMessage('No doctests found in %r' % strings)
    return result
Example #20
0
def read_write_dirs(source=None):
    """Write tags from the files in/under the directory"""
    if not source:
        if scripts.args.directories:
            [read_write_dirs(d) for d in scripts.args.directories]
        else:
            source = paths.pwd()
    path_to_directory = paths.path(source)
    tags = read_dirs(path_to_directory)
    write_dir(path_to_directory, tags)
    for path_to_sub_directory in path_to_directory.walkdirs():
        if repository.is_repository_path(path_to_sub_directory):
            continue
        tags = read_dirs(path_to_sub_directory)
        write_dir(path_to_sub_directory, tags)
Example #21
0
def get_significant_status(path_to_directory):
    """Get the svn status for that directory

    Stop if any immediates have a significant status
        otherwise recurse into sub-directories
    """
    path_to_directory = path(path_to_directory)
    if not path_to_directory.isdir():
        return None
    if not _is_working_directory(path_to_directory):
        return None
    status = _get_immediately_significant_status(path_to_directory)
    if status:
        return status
    for path_to_dir in path_to_directory.dirs():
        if path_to_dir[0] == "." or path_to_dir == path_to_directory:
            continue
        status = get_significant_status(path_to_dir)
        if status:
            return status
    return None
Example #22
0
def read_environ_items():
    jab = path("~/jab").expanduser()
    items = {}
    for environ_file in jab.files("*environ*"):
        lines = [l.strip() for l in environ_file.lines()]
        lines = [l for l in lines if l and l[0] != "#"]
        lines = [l for l in lines if "export" in l and "=" in l]
        while_i_was_debugging = "\n".join([l for l in lines if l.count("=") > 1])
        lines = [l.replace("export", "") for l in lines]
        lines = [l.split("&&", 1)[-1] for l in lines]
        lines = [l.strip() for l in lines]
        lines = [l.split("=", 1) for l in lines]
        lines = [(key, value.strip('"').strip("'")) for key, value in lines]
        lines = [(key, value) for key, value in lines if "033" not in value]
        for key, value in lines:
            values = items.get(key, [])
            values.append(value)
            non_empty_values = [value for value in values if value]
            if non_empty_values:
                values = non_empty_values
            items[key] = values
    return sorted(items.items())
Example #23
0
def read_sys_dirs():
    """Read tags for each path in sys.path"""
    tags = []
    for path_to_system in sys.path:
        tags.append(read_dir(paths.path(path_to_system)))
    return tags
Example #24
0
def _get_existing_file(path_to_file):
    result = path(path_to_file)
    if result.isfile():
        return result
    raise ValueError("%s is not a file" % result)
Example #25
0
def refresh_paths():
    """Refresh the module-level paths"""
    paths[:] = []
    for p in sys.path:
        paths.append(path(p))
Example #26
0
def read_sys_dirs():
    """Read tags for each path in sys.path"""
    tags = []
    for path_to_system in sys.path:
        tags.append(read_dir_tags(paths.path(path_to_system)))
    return tags
Example #27
0
def string_to_paths(string):
    for c in ":, ;":
        if c in string:
            return strings_to_paths(string.split(c))
    return [path(string)]
Example #28
0
def strings_to_paths(strings):
    return [path(s) for s in strings]
Example #29
0
 def _paths(self):
     return [path(_) for _ in self._strings()]