Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/ra.py
Show All 23 Lines | _eol_style = { | ||||
'native': b'\n', | 'native': b'\n', | ||||
'CRLF': b'\r\n', | 'CRLF': b'\r\n', | ||||
'LF': b'\n', | 'LF': b'\n', | ||||
'CR': b'\r' | 'CR': b'\r' | ||||
} | } | ||||
def _normalize_line_endings(lines, eol_style='native'): | def _normalize_line_endings(lines, eol_style='native'): | ||||
"""Normalize line endings to unix (\n), windows (\r\n) or mac (\r). | r"""Normalize line endings to unix (\\n), windows (\\r\\n) or mac (\\r). | ||||
vlorentz: or: `r"""Normalize line endings to unix (\n), windows (\r\n) or mac (\r).` | |||||
Done Inline ActionsOh right, raw string litteral anlambert: Oh right, raw string litteral | |||||
Args: | Args: | ||||
lines (bytes): The lines to normalize | lines (bytes): The lines to normalize | ||||
line_ending (str): The line ending format as defined for | line_ending (str): The line ending format as defined for | ||||
svn:eol-style property. Acceptable values are 'native', | svn:eol-style property. Acceptable values are 'native', | ||||
'CRLF', 'LF' and 'CR' | 'CRLF', 'LF' and 'CR' | ||||
Returns | |||||
Returns: | |||||
bytes: lines with endings normalized | bytes: lines with endings normalized | ||||
""" | """ | ||||
lines = lines.replace(_eol_style['CRLF'], _eol_style['LF'])\ | lines = lines.replace(_eol_style['CRLF'], _eol_style['LF'])\ | ||||
.replace(_eol_style['CR'], _eol_style['LF']) | .replace(_eol_style['CR'], _eol_style['LF']) | ||||
if _eol_style[eol_style] != _eol_style['LF']: | if _eol_style[eol_style] != _eol_style['LF']: | ||||
lines = lines.replace(_eol_style['LF'], _eol_style[eol_style]) | lines = lines.replace(_eol_style['LF'], _eol_style[eol_style]) | ||||
return lines | return lines | ||||
Show All 40 Lines | |||||
def is_file_an_svnlink_p(fullpath): | def is_file_an_svnlink_p(fullpath): | ||||
"""Determine if a filepath is an svnlink or something else. | """Determine if a filepath is an svnlink or something else. | ||||
Args: | Args: | ||||
fullpath (str/bytes): Full path to the potential symlink to check | fullpath (str/bytes): Full path to the potential symlink to check | ||||
Return: | Returns: | ||||
boolean value to determine if it's indeed a symlink (as per | boolean value to determine if it's indeed a symlink (as per | ||||
svn) or not. | svn) or not. | ||||
""" | """ | ||||
with open(fullpath, 'rb') as f: | with open(fullpath, 'rb') as f: | ||||
filetype, src = read_svn_link(f.read()) | filetype, src = read_svn_link(f.read()) | ||||
return filetype == b'link', src | return filetype == b'link', src | ||||
▲ Show 20 Lines • Show All 402 Lines • Show Last 20 Lines |
or: r"""Normalize line endings to unix (\n), windows (\r\n) or mac (\r).