File: path.py

package info (click to toggle)
fs-uae-arcade 3.1.63-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 24,456 kB
  • sloc: python: 56,011; makefile: 170
file content (26 lines) | stat: -rw-r--r-- 657 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import sys


def unicode_path(path):
    if isinstance(path, str):
        return path
    return path.decode(sys.getfilesystemencoding())


def str_path(path):
    return path


def normalize_path(path):
    path = os.path.normcase(os.path.normpath(path))
    return unicode_path(path)


def is_same_file(path_a, path_b):
    """Checks whether path_a and path_b refer to the same file. It does this
    by normalizing the paths (and case if applicable) and eliminating any
    symbolic links along the way."""
    path_a = normalize_path(os.path.realpath(path_a))
    path_b = normalize_path(os.path.realpath(path_b))
    return path_a == path_b