Ejemplo n.º 1
0
def remove(path, force=False):
    """
    Remove a file/directory in a working-copy.
    """
    args = ['remove']
    if force:
        args += ['--force']
    args += [safe_path(path)]
    run_svn(args)
Ejemplo n.º 2
0
def update(path, non_recursive=False):
    """
    Update a path in a working-copy.
    """
    args = ['update', '--ignore-externals']
    if non_recursive:
        args += ['-N']
    args += [safe_path(path)]
    run_svn(args)
Ejemplo n.º 3
0
def update(path, non_recursive=False):
    """
    Update a path in a working-copy.
    """
    args = ['update', '--ignore-externals']
    if non_recursive:
        args += ['-N']
    args += [safe_path(path)]
    run_svn(args)
Ejemplo n.º 4
0
def remove(path, force=False):
    """
    Remove a file/directory in a working-copy.
    """
    args = ['remove']
    if force:
        args += ['--force']
    args += [safe_path(path)]
    run_svn(args)
Ejemplo n.º 5
0
def export(svn_url, rev_number, path, non_recursive=False, force=False):
    """
    Export a file from a repo to a local path.
    """
    args = ['export', '--ignore-externals', '-r', rev_number]
    if non_recursive:
        args += ['-N']
    if force:
        args += ['--force']
    args += [safe_path(svn_url, rev_number), safe_path(path)]
    run_svn(args)
Ejemplo n.º 6
0
def export(svn_url, rev_number, path, non_recursive=False, force=False):
    """
    Export a file from a repo to a local path.
    """
    args = ['export', '--ignore-externals', '-r', rev_number]
    if non_recursive:
        args += ['-N']
    if force:
        args += ['--force']
    args += [safe_path(svn_url, rev_number), safe_path(path)]
    run_svn(args)
Ejemplo n.º 7
0
def run_svn_log(svn_url_or_wc,
                rev_start,
                rev_end,
                limit,
                stop_on_copy=False,
                get_changed_paths=True,
                get_revprops=False):
    """
    Fetch up to 'limit' SVN log entries between the given revisions.
    """
    args = ['log', '--xml']
    if stop_on_copy:
        args += ['--stop-on-copy']
    if get_changed_paths:
        args += ['-v']
    if get_revprops:
        args += ['--with-all-revprops']
    args += ['-r', '%s:%s' % (rev_start, rev_end)]
    args += [
        '--limit',
        str(limit),
        safe_path(svn_url_or_wc, max(rev_start, rev_end))
    ]
    xml_string = run_svn(args)
    return _parse_svn_log_xml(xml_string)
Ejemplo n.º 8
0
def get_rev(svn_url_or_wc, rev_number):
    """
    Evaluate a given SVN revision pattern, to map it to a discrete rev #.
    """
    xml_string = run_svn(['info', '--xml', '-r', rev_number, safe_path(svn_url_or_wc, rev_number)], fail_if_stderr=True)
    info = _parse_svn_info_xml(xml_string)
    return info['revision']
Ejemplo n.º 9
0
def svn_checkout(svn_url, checkout_dir, rev_number=None):
    """
    Checkout the given URL at an optional revision number.
    """
    args = ['checkout', '-q']
    if rev_number is not None:
        args += ['-r', rev_number]
    args += [safe_path(svn_url, rev_number), checkout_dir]
    return run_svn(args)
Ejemplo n.º 10
0
def svn_checkout(svn_url, checkout_dir, rev_number=None):
    """
    Checkout the given URL at an optional revision number.
    """
    args = ['checkout', '-q']
    if rev_number is not None:
        args += ['-r', rev_number]
    args += [safe_path(svn_url, rev_number), checkout_dir]
    return run_svn(args)
Ejemplo n.º 11
0
def propget(svn_url_or_wc, prop_name, rev_number=None):
    """
    Get the value of a versioned property for the given path.
    """
    args = ['propget', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    args += [prop_name, safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args)
    return _parse_svn_propget_xml(xml_string)
Ejemplo n.º 12
0
def propget(svn_url_or_wc, prop_name, rev_number=None):
    """
    Get the value of a versioned property for the given path.
    """
    args = ['propget', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    args += [prop_name, safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args)
    return _parse_svn_propget_xml(xml_string)
Ejemplo n.º 13
0
def get_rev(svn_url_or_wc, rev_number):
    """
    Evaluate a given SVN revision pattern, to map it to a discrete rev #.
    """
    xml_string = run_svn([
        'info', '--xml', '-r', rev_number,
        safe_path(svn_url_or_wc, rev_number)
    ],
                         fail_if_stderr=True)
    info = _parse_svn_info_xml(xml_string)
    return info['revision']
Ejemplo n.º 14
0
def info(svn_url_or_wc, rev_number=None):
    """
    Get SVN information for the given URL or working copy, with an optionally
    specified revision number.
    Returns a dict as created by _parse_svn_info_xml().
    """
    args = ['info', '--xml']
    if rev_number is not None:
        args += ["-r", rev_number]
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args, fail_if_stderr=True)
    return _parse_svn_info_xml(xml_string)
Ejemplo n.º 15
0
def info(svn_url_or_wc, rev_number=None):
    """
    Get SVN information for the given URL or working copy, with an optionally
    specified revision number.
    Returns a dict as created by _parse_svn_info_xml().
    """
    args = ['info', '--xml']
    if rev_number is not None:
        args += ["-r", rev_number]
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args, fail_if_stderr=True)
    return _parse_svn_info_xml(xml_string)
Ejemplo n.º 16
0
def version():
    """
    Returns the SVN client version as a tuple.

    The returned tuple only contains numbers, non-digits in version string are
    silently ignored.
    """
    global _svn_client_version
    if _svn_client_version is None:
        raw = run_svn(['--version', '-q']).strip()
        _svn_client_version = tuple(
            map(int, [x for x in raw.split('.') if x.isdigit()]))
    return _svn_client_version
Ejemplo n.º 17
0
def version():
    """
    Returns the SVN client version as a tuple.

    The returned tuple only contains numbers, non-digits in version string are
    silently ignored.
    """
    global _svn_client_version
    if _svn_client_version is None:
        raw = run_svn(['--version', '-q']).strip()
        _svn_client_version = tuple(map(int, [x for x in raw.split('.')
                                              if x.isdigit()]))
    return _svn_client_version
Ejemplo n.º 18
0
def status(svn_wc, quiet=False, non_recursive=False):
    """
    Get SVN status information about the given working copy.
    """
    # Ensure proper stripping by canonicalizing the path
    svn_wc = os.path.abspath(svn_wc)
    args = ['status', '--xml', '--ignore-externals']
    if quiet:
        args += ['-q']
    else:
        args += ['-v']
    if non_recursive:
        args += ['-N']
    xml_string = run_svn(args + [safe_path(svn_wc)])
    return _parse_svn_status_xml(xml_string, svn_wc, ignore_externals=True)
Ejemplo n.º 19
0
def propget_all(svn_url_or_wc, rev_number=None):
    """
    Get the values of all versioned properties for the given path.
    """
    l = {}
    args = ['proplist', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args)
    props = _parse_svn_proplist_xml(xml_string)
    for prop_name in props:
        d = propget(svn_url_or_wc, prop_name, rev_number)
        l[d['name']] = d['value']
    return l
Ejemplo n.º 20
0
def propget_all(svn_url_or_wc, rev_number=None):
    """
    Get the values of all versioned properties for the given path.
    """
    l = {}
    args = ['proplist', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args)
    props = _parse_svn_proplist_xml(xml_string)
    for prop_name in props:
        d = propget(svn_url_or_wc, prop_name, rev_number)
        l[d['name']] = d['value']
    return l
Ejemplo n.º 21
0
def status(svn_wc, quiet=False, non_recursive=False):
    """
    Get SVN status information about the given working copy.
    """
    # Ensure proper stripping by canonicalizing the path
    svn_wc = os.path.abspath(svn_wc)
    args = ['status', '--xml', '--ignore-externals']
    if quiet:
        args += ['-q']
    else:
        args += ['-v']
    if non_recursive:
        args += ['-N']
    xml_string = run_svn(args + [safe_path(svn_wc)])
    return _parse_svn_status_xml(xml_string, svn_wc, ignore_externals=True)
Ejemplo n.º 22
0
def run_svn_log(svn_url_or_wc, rev_start, rev_end, limit, stop_on_copy=False, get_changed_paths=True, get_revprops=False):
    """
    Fetch up to 'limit' SVN log entries between the given revisions.
    """
    args = ['log', '--xml']
    if stop_on_copy:
        args += ['--stop-on-copy']
    if get_changed_paths:
        args += ['-v']
    if get_revprops:
        args += ['--with-all-revprops']
    args += ['-r', '%s:%s' % (rev_start, rev_end)]
    args += ['--limit', str(limit), safe_path(svn_url_or_wc, max(rev_start, rev_end))]
    xml_string = run_svn(args)
    return _parse_svn_log_xml(xml_string)
Ejemplo n.º 23
0
def list(svn_url_or_wc, rev_number=None, recursive=False):
    """
    List the contents of a path as they exist in the repo.
    """
    args = ['list', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    if recursive:
        args += ['-R']
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args, no_fail=True)
    # If svn_url_or_wc is a WC path which hasn't been committed yet,
    # 'svn list' won't return a valid XML document. Gracefully short-circuit.
    if not "</lists>" in xml_string:
        return []
    return _parse_svn_list_xml(xml_string)
Ejemplo n.º 24
0
def list(svn_url_or_wc, rev_number=None, recursive=False):
    """
    List the contents of a path as they exist in the repo.
    """
    args = ['list', '--xml']
    if rev_number:
        args += ['-r', rev_number]
    if recursive:
        args += ['-R']
    args += [safe_path(svn_url_or_wc, rev_number)]
    xml_string = run_svn(args, no_fail=True)
    # If svn_url_or_wc is a WC path which hasn't been committed yet,
    # 'svn list' won't return a valid XML document. Gracefully short-circuit.
    if not "</lists>" in xml_string:
        return []
    return _parse_svn_list_xml(xml_string)