view rhodecode/lib/vcs/utils/paths.py @ 2865:6d9b3ade3051 beta

Allowing multiple issue servers to be autolinked in the changeset view; linking is now contingent on issue_server_link, issue_pat and issue_prefix being defined; multiple servers can be used by specifying a common suffix on all the above variables, ie .. issue_server_link_1 issue_pat_1 issue_prefix_1 .. and .. issue_server_link_other issue_pat_other issue_prefix_other .. would be treated as two distinct servers, but .. issue_pat_thing .. would be ignored (since the other two requisite vars aren't present). This patch is backwards compatible with existing variables (as a suffix isn't needed).
author Zachary Auclair <zach101@gmail.com>
date Thu, 20 Sep 2012 20:30:55 -0400
parents 26fac32c215d
children
line wrap: on
line source

import os

abspath = lambda * p: os.path.abspath(os.path.join(*p))


def get_dirs_for_path(*paths):
    """
    Returns list of directories, including intermediate.
    """
    for path in paths:
        head = path
        while head:
            head, tail = os.path.split(head)
            if head:
                yield head
            else:
                # We don't need to yield empty path
                break


def get_dir_size(path):
    root_path = path
    size = 0
    for path, dirs, files in os.walk(root_path):
        for f in files:
            try:
                size += os.path.getsize(os.path.join(path, f))
            except OSError:
                pass
    return size


def get_user_home():
    """
    Returns home path of the user.
    """
    return os.getenv('HOME', os.getenv('USERPROFILE')) or ''