skilleter-modules 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,221 @@
1
+ """ Default dircolors data, and the reference .dircolors file.
2
+ Generated from dircolors in GNU coreutils version 8.31 """
3
+
4
+ __all__ = ['DEFAULT_DIRCOLORS', 'DEFAULT_LS_COLORS']
5
+
6
+ # the output of `dircolors -p`
7
+ DEFAULT_DIRCOLORS = r"""
8
+ # Configuration file for dircolors, a utility to help you set the
9
+ # LS_COLORS environment variable used by GNU ls with the --color option.
10
+ # Copyright (C) 1996-2019 Free Software Foundation, Inc.
11
+ # Copying and distribution of this file, with or without modification,
12
+ # are permitted provided the copyright notice and this notice are preserved.
13
+ # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
14
+ # slackware version of dircolors) are recognized but ignored.
15
+ # Below are TERM entries, which can be a glob patterns, to match
16
+ # against the TERM environment variable to determine if it is colorizable.
17
+ TERM Eterm
18
+ TERM ansi
19
+ TERM *color*
20
+ TERM con[0-9]*x[0-9]*
21
+ TERM cons25
22
+ TERM console
23
+ TERM cygwin
24
+ TERM dtterm
25
+ TERM gnome
26
+ TERM hurd
27
+ TERM jfbterm
28
+ TERM konsole
29
+ TERM kterm
30
+ TERM linux
31
+ TERM linux-c
32
+ TERM mlterm
33
+ TERM putty
34
+ TERM rxvt*
35
+ TERM screen*
36
+ TERM st
37
+ TERM terminator
38
+ TERM tmux*
39
+ TERM vt100
40
+ TERM xterm*
41
+ # Below are the color init strings for the basic file types.
42
+ # One can use codes for 256 or more colors supported by modern terminals.
43
+ # The default color codes use the capabilities of an 8 color terminal
44
+ # with some additional attributes as per the following codes:
45
+ # Attribute codes:
46
+ # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
47
+ # Text color codes:
48
+ # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
49
+ # Background color codes:
50
+ # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
51
+ #NORMAL 00 # no color code at all
52
+ #FILE 00 # regular file: use no color at all
53
+ RESET 0 # reset to "normal" color
54
+ DIR 01;34 # directory
55
+ LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
56
+ # numerical value, the color is as for the file pointed to.)
57
+ MULTIHARDLINK 00 # regular file with more than one link
58
+ FIFO 40;33 # pipe
59
+ SOCK 01;35 # socket
60
+ DOOR 01;35 # door
61
+ BLK 40;33;01 # block device driver
62
+ CHR 40;33;01 # character device driver
63
+ ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file ...
64
+ MISSING 00 # ... and the files they point to
65
+ SETUID 37;41 # file that is setuid (u+s)
66
+ SETGID 30;43 # file that is setgid (g+s)
67
+ CAPABILITY 30;41 # file with capability
68
+ STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
69
+ OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
70
+ STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
71
+ # This is for files with execute permission:
72
+ EXEC 01;32
73
+ # List any file extensions like '.gz' or '.tar' that you would like ls
74
+ # to colorize below. Put the extension, a space, and the color init string.
75
+ # (and any comments you want to add after a '#')
76
+ # If you use DOS-style suffixes, you may want to uncomment the following:
77
+ #.cmd 01;32 # executables (bright green)
78
+ #.exe 01;32
79
+ #.com 01;32
80
+ #.btm 01;32
81
+ #.bat 01;32
82
+ # Or if you want to colorize scripts even if they do not have the
83
+ # executable bit actually set.
84
+ #.sh 01;32
85
+ #.csh 01;32
86
+ # archives or compressed (bright red)
87
+ .tar 01;31
88
+ .tgz 01;31
89
+ .arc 01;31
90
+ .arj 01;31
91
+ .taz 01;31
92
+ .lha 01;31
93
+ .lz4 01;31
94
+ .lzh 01;31
95
+ .lzma 01;31
96
+ .tlz 01;31
97
+ .txz 01;31
98
+ .tzo 01;31
99
+ .t7z 01;31
100
+ .zip 01;31
101
+ .z 01;31
102
+ .dz 01;31
103
+ .gz 01;31
104
+ .lrz 01;31
105
+ .lz 01;31
106
+ .lzo 01;31
107
+ .xz 01;31
108
+ .zst 01;31
109
+ .tzst 01;31
110
+ .bz2 01;31
111
+ .bz 01;31
112
+ .tbz 01;31
113
+ .tbz2 01;31
114
+ .tz 01;31
115
+ .deb 01;31
116
+ .rpm 01;31
117
+ .jar 01;31
118
+ .war 01;31
119
+ .ear 01;31
120
+ .sar 01;31
121
+ .rar 01;31
122
+ .alz 01;31
123
+ .ace 01;31
124
+ .zoo 01;31
125
+ .cpio 01;31
126
+ .7z 01;31
127
+ .rz 01;31
128
+ .cab 01;31
129
+ .wim 01;31
130
+ .swm 01;31
131
+ .dwm 01;31
132
+ .esd 01;31
133
+ # image formats
134
+ .jpg 01;35
135
+ .jpeg 01;35
136
+ .mjpg 01;35
137
+ .mjpeg 01;35
138
+ .gif 01;35
139
+ .bmp 01;35
140
+ .pbm 01;35
141
+ .pgm 01;35
142
+ .ppm 01;35
143
+ .tga 01;35
144
+ .xbm 01;35
145
+ .xpm 01;35
146
+ .tif 01;35
147
+ .tiff 01;35
148
+ .png 01;35
149
+ .svg 01;35
150
+ .svgz 01;35
151
+ .mng 01;35
152
+ .pcx 01;35
153
+ .mov 01;35
154
+ .mpg 01;35
155
+ .mpeg 01;35
156
+ .m2v 01;35
157
+ .mkv 01;35
158
+ .webm 01;35
159
+ .ogm 01;35
160
+ .mp4 01;35
161
+ .m4v 01;35
162
+ .mp4v 01;35
163
+ .vob 01;35
164
+ .qt 01;35
165
+ .nuv 01;35
166
+ .wmv 01;35
167
+ .asf 01;35
168
+ .rm 01;35
169
+ .rmvb 01;35
170
+ .flc 01;35
171
+ .avi 01;35
172
+ .fli 01;35
173
+ .flv 01;35
174
+ .gl 01;35
175
+ .dl 01;35
176
+ .xcf 01;35
177
+ .xwd 01;35
178
+ .yuv 01;35
179
+ .cgm 01;35
180
+ .emf 01;35
181
+ # https://wiki.xiph.org/MIME_Types_and_File_Extensions
182
+ .ogv 01;35
183
+ .ogx 01;35
184
+ # audio formats
185
+ .aac 00;36
186
+ .au 00;36
187
+ .flac 00;36
188
+ .m4a 00;36
189
+ .mid 00;36
190
+ .midi 00;36
191
+ .mka 00;36
192
+ .mp3 00;36
193
+ .mpc 00;36
194
+ .ogg 00;36
195
+ .ra 00;36
196
+ .wav 00;36
197
+ # https://wiki.xiph.org/MIME_Types_and_File_Extensions
198
+ .oga 00;36
199
+ .opus 00;36
200
+ .spx 00;36
201
+ .xspf 00;36
202
+ """
203
+
204
+ # the above converted to LS_COLORS by dircolors, but with the trailing ':' stripped
205
+ DEFAULT_LS_COLORS = r"""
206
+ rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:
207
+ mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:
208
+ *.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:
209
+ *.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:
210
+ *.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:
211
+ *.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:
212
+ *.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:
213
+ *.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:
214
+ *.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:
215
+ *.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:
216
+ *.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:
217
+ *.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:
218
+ *.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:
219
+ *.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:
220
+ *.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:
221
+ *.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36""".replace('\n', '')
@@ -0,0 +1,50 @@
1
+ # private utility functions for pydircolors
2
+ #
3
+ # Copyright 2019 Allen Wild <allenwild93@gmail.com>
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ """ private/internal utility functions for pydircolors """
7
+
8
+ import os
9
+
10
+ __all__ = ['stat_at', 'readlink_at']
11
+
12
+ def stat_at(file, cwd=None, follow_symlinks=False):
13
+ """ helper function to call os.stat on a file relative to a given directory.
14
+ cwd should be a string, and will be opened as read-only (then closed), or an integer
15
+ for an already-open directory file descriptor (which won't be closed).
16
+ os.open or os.stat may raise various errors, which are passed on. """
17
+ if isinstance(cwd, str):
18
+ dirfd = os.open(cwd, os.O_RDONLY)
19
+ need_to_close = True
20
+ elif cwd is None or isinstance(cwd, int):
21
+ dirfd = cwd
22
+ need_to_close = False
23
+ else:
24
+ raise ValueError('cwd must be str, int, or None')
25
+
26
+ try:
27
+ return os.stat(file, dir_fd=dirfd, follow_symlinks=follow_symlinks)
28
+ finally:
29
+ if need_to_close:
30
+ os.close(dirfd)
31
+
32
+ def readlink_at(file, cwd=None):
33
+ """ helper function to call os.readlink on a file relative to a given directory.
34
+ cwd should be a string, and will be opened as read-only (then closed), or an integer
35
+ for an already-open directory file descriptor (which won't be closed).
36
+ os.open or os.readlink may raise various errors, which are passed on. """
37
+ if isinstance(cwd, str):
38
+ dirfd = os.open(cwd, os.O_RDONLY)
39
+ need_to_close = True
40
+ elif cwd is None or isinstance(cwd, int):
41
+ dirfd = cwd
42
+ need_to_close = False
43
+ else:
44
+ raise ValueError('cwd must be str, int, or None')
45
+
46
+ try:
47
+ return os.readlink(file, dir_fd=dirfd)
48
+ finally:
49
+ if need_to_close:
50
+ os.close(dirfd)
@@ -0,0 +1,310 @@
1
+ # Dircolors, a Python library for colorizing and formatting filenames like GNU Coreutils'
2
+ # ls and dircolors programs.
3
+ # Requires python 3.3 or later
4
+ #
5
+ # Copyright 2019 Allen Wild <allenwild93@gmail.com>
6
+ # Modifications copyright 2020 John Skilleter <john@skilleter.org.uk>
7
+ # SPDX-License-Identifier: Apache-2.0
8
+
9
+ """ dircolors, a Python library to colorize filenames based on their type
10
+ for terminal use, like GNU ls and dircolors. """
11
+
12
+ from collections import OrderedDict
13
+ from io import StringIO, TextIOBase
14
+ import os
15
+ import stat
16
+
17
+ import dc_defaults
18
+ import dc_util
19
+
20
+ __all__ = ['Dircolors']
21
+
22
+ _CODE_MAP = OrderedDict()
23
+
24
+ def _init_code_map():
25
+ """ mapping between the key name in the .dircolors file and the two letter
26
+ code found in the LS_COLORS environment variable.
27
+ Used for parsing .dircolors files. """
28
+ # This code is wrapped in a function so we can disable pylint's whitespace check
29
+ # on a limited scope.
30
+ # pylint: disable=bad-whitespace
31
+ _CODE_MAP['RESET'] = 'rs'
32
+ _CODE_MAP['DIR'] = 'di'
33
+ _CODE_MAP['LINK'] = 'ln'
34
+ _CODE_MAP['MULTIHARDLINK'] = 'mh'
35
+ _CODE_MAP['FIFO'] = 'pi'
36
+ _CODE_MAP['SOCK'] = 'so'
37
+ _CODE_MAP['DOOR'] = 'do'
38
+ _CODE_MAP['BLK'] = 'bd'
39
+ _CODE_MAP['CHR'] = 'cd'
40
+ _CODE_MAP['ORPHAN'] = 'or'
41
+ _CODE_MAP['MISSING'] = 'mi'
42
+ _CODE_MAP['SETUID'] = 'su'
43
+ _CODE_MAP['SETGID'] = 'sg'
44
+ _CODE_MAP['CAPABILITY'] = 'ca'
45
+ _CODE_MAP['STICKY_OTHER_WRITABLE'] = 'tw'
46
+ _CODE_MAP['OTHER_WRITABLE'] = 'ow'
47
+ _CODE_MAP['STICKY'] = 'st'
48
+ _CODE_MAP['EXEC'] = 'ex'
49
+
50
+ _init_code_map()
51
+ del _init_code_map
52
+
53
+ class Dircolors:
54
+ """ Main dircolors class. Contains a database of formats corresponding to file types,
55
+ modes, and extensions. Use the format() method to check a file and color it appropriately.
56
+ """
57
+
58
+ def __init__(self, load=True):
59
+ """ Initialize a Dircolors object. If load=True (the default), then try
60
+ to load dircolors info from the LS_COLORS environment variable.
61
+ If no data is obtained from LS_COLORS, load the defaults.
62
+ If load=False, don't even load defaults. """
63
+ self._loaded = False
64
+ self._codes = OrderedDict()
65
+ self._extensions = OrderedDict()
66
+ if load:
67
+ if not self.load_from_environ():
68
+ self.load_defaults()
69
+
70
+ def __bool__(self):
71
+ """ convenience method for checking whether this Dircolors object has loaded a database.
72
+ Can be used like
73
+ d = Dircolors()
74
+ if d:
75
+ d.format(somefile)
76
+ """
77
+ return self._loaded
78
+
79
+ @property
80
+ def loaded(self):
81
+ """ return a boolean indicating whether some valid dircolors data has been loaded """
82
+ return self._loaded
83
+
84
+ def clear(self):
85
+ """ Clear the loaded data """
86
+ self._loaded = False
87
+ self._codes.clear()
88
+ self._extensions.clear()
89
+
90
+ def load_from_lscolors(self, lscolors):
91
+ """ Load the dircolors database from a string in the same format as the LS_COLORS
92
+ environment variable.
93
+ Returns True if data was successfully loaded, False otherwise (e.g. if
94
+ envvar is unset). Regardless, the current database will be cleared """
95
+ self.clear()
96
+ if not lscolors:
97
+ return False
98
+
99
+ for item in lscolors.split(':'):
100
+ try:
101
+ code, color = item.split('=', 1)
102
+ except ValueError:
103
+ continue # no key=value, just ignore
104
+ if code.startswith('*.'):
105
+ self._extensions[code[1:]] = color
106
+ else:
107
+ self._codes[code] = color
108
+
109
+ if self._codes or self._extensions:
110
+ self._loaded = True
111
+ return self._loaded
112
+
113
+ def load_from_environ(self, envvar='LS_COLORS'):
114
+ """ Load the dircolors database from an environment variable. By default,
115
+ use LS_COLORS like the GNU Coreutils `ls` program.
116
+ Returns True if data was successfully loaded, False otherwise (e.g. if
117
+ envvar is unset). Regardless, the current database will be cleared. """
118
+ return self.load_from_lscolors(os.environ.get(envvar))
119
+
120
+ def load_from_dircolors(self, database, strict=False):
121
+ """ Load the dircolors database from a GNU-compatible .dircolors file.
122
+ May raise any of the usual OSError exceptions if filename doesn't exist
123
+ or otherwise can't be read.
124
+
125
+ database can be a string representing a filename, or a file-like object
126
+ opened in text mode (i.e. a subclass of io.TextIOBase). To load from the
127
+ contents of a .dircolors file, wrap it in an io.StringIO object.
128
+
129
+ If strict is True, raise ValueError on the first unparsed line
130
+
131
+ Returns a boolean indicating whether any data was loaded.
132
+ The current database will always be cleared. """
133
+ self.clear()
134
+ if isinstance(database, str):
135
+ file = open(database, 'r')
136
+ elif isinstance(database, TextIOBase):
137
+ file = database
138
+ else:
139
+ raise ValueError('database must be str or io.TextIOBase, not %s' % type(database))
140
+
141
+ try:
142
+ for line in file:
143
+ # remove comments and skip empty lines
144
+ line = line.split('#')[0].strip()
145
+ if not line:
146
+ continue
147
+
148
+ # make sure there's two space-separated fields
149
+ split = line.split()
150
+ if len(split) != 2:
151
+ if strict:
152
+ raise ValueError('Warning: unable to parse dircolors line "%s"' % line)
153
+ continue
154
+
155
+ key, val = split
156
+ if key == 'TERM':
157
+ continue # ignore TERM directives
158
+ elif key in _CODE_MAP:
159
+ self._codes[_CODE_MAP[key]] = val
160
+ elif key.startswith('.'):
161
+ self._extensions[key] = val
162
+ elif strict:
163
+ raise ValueError('Warning: unable to parse dircolors line "%s"' % line)
164
+ # elif not strict, skip
165
+
166
+ if self._codes or self._extensions:
167
+ self._loaded = True
168
+ return self._loaded
169
+ finally:
170
+ file.close()
171
+
172
+ def load_defaults(self):
173
+ """ Load the default database. """
174
+ self.clear()
175
+ return self.load_from_dircolors(StringIO(dc_defaults.DEFAULT_DIRCOLORS), True)
176
+
177
+ def generate_lscolors(self):
178
+ """ Output the database in the format used by the LS_COLORS environment variable. """
179
+ if not self._loaded:
180
+ return ''
181
+
182
+ def gen_pairs():
183
+ for pair in self._codes.items():
184
+ yield pair
185
+ for pair in self._extensions.items():
186
+ # change .xyz to *.xyz
187
+ yield '*' + pair[0], pair[1]
188
+
189
+ return ':'.join('%s=%s' % pair for pair in gen_pairs())
190
+
191
+ def _format_code(self, text, code):
192
+ """ format text with an lscolors code. Return text unmodified if code
193
+ isn't found in the database """
194
+ val = self._codes.get(code, None)
195
+ if val:
196
+ return '\033[%sm%s\033[%sm' % (val, text, self._codes.get('rs', '0'))
197
+ return text
198
+
199
+ def _format_ext(self, text, ext):
200
+ """ Format text according to the given file extension.
201
+ ext must have a leading '.'
202
+ text need not actually end in '.ext' """
203
+ val = self._extensions.get(ext, '0')
204
+ if val:
205
+ return '\033[%sm%s\033[%sm' % (val, text, self._codes.get('rs', '0'))
206
+ return text
207
+
208
+ def format_mode(self, text, mode):
209
+ """ Format and color the given text based on the given file mode.
210
+
211
+ `mode` can be an integer, usually the st_mode field of an os.stat_result
212
+ object obtained from os.stat() or similar function. It can also be an os.stat_result
213
+ object, and the st_mode field will be extracted automatically.
214
+
215
+ If mode is zero then the formatting is performed only according to the filename.
216
+
217
+ `text` is an arbitrary string which will be colored according to the bits
218
+ set in `mode` and the colors database loaded in this Dircolors object.
219
+
220
+ If `mode` represents a symlink, it will be formatted as such with no dereferencing
221
+ (since this function doesn't know the file name) """
222
+ if not self._loaded:
223
+ return text
224
+
225
+ if isinstance(mode, int):
226
+ pass
227
+ elif isinstance(mode, os.stat_result):
228
+ mode = mode.st_mode
229
+ else:
230
+ raise ValueError('mode must be int or os.stat_result, not %s' % type(mode))
231
+
232
+ if mode:
233
+ if stat.S_ISDIR(mode):
234
+ if (mode & (stat.S_ISVTX | stat.S_IWOTH)) == (stat.S_ISVTX | stat.S_IWOTH):
235
+ # sticky and world-writable
236
+ return self._format_code(text, 'tw')
237
+ if mode & stat.S_ISVTX:
238
+ # sticky but not world-writable
239
+ return self._format_code(text, 'st')
240
+ if mode & stat.S_IWOTH:
241
+ # world-writable but not sticky
242
+ return self._format_code(text, 'ow')
243
+ # normal directory
244
+ return self._format_code(text, 'di')
245
+
246
+ # special file?
247
+ # pylint: disable=bad-whitespace
248
+ special_types = (
249
+ (stat.S_IFLNK, 'ln'), # symlink
250
+ (stat.S_IFIFO, 'pi'), # pipe (FIFO)
251
+ (stat.S_IFSOCK, 'so'), # socket
252
+ (stat.S_IFBLK, 'bd'), # block device
253
+ (stat.S_IFCHR, 'cd'), # character device
254
+ (stat.S_ISUID, 'su'), # setuid
255
+ (stat.S_ISGID, 'sg'), # setgid
256
+ )
257
+
258
+ for mask, code in special_types:
259
+ if (mode & mask) == mask:
260
+ return self._format_code(text, code)
261
+
262
+ # executable file?
263
+ if mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH):
264
+ return self._format_code(text, 'ex')
265
+
266
+ # regular file, format according to its extension
267
+ _, ext = os.path.splitext(text)
268
+ if ext:
269
+ return self._format_ext(text, ext)
270
+ return text
271
+
272
+ def format(self, file, cwd=None, follow_symlinks=False, show_target=False):
273
+ """ Format and color the file given by the name `file`.
274
+
275
+ If `cwd` is not None, it should be a string for the directory relative
276
+ to which `file` is looked up, or an integer representing a directory
277
+ descriptor (usually from `os.open()`).
278
+
279
+ If the file does not exist, it is formatted according to the filename only.
280
+
281
+ Use follow_symlinks to dereference symlinks entirely.
282
+ Use show_target=True with follow_symlinks=False to format both the link name
283
+ and its target in the format:
284
+ linkname -> target
285
+ With linkname formatted as a link color, and the link target formatted as its respective
286
+ type. If the link target is another link, it will not be recursively dereferenced. """
287
+
288
+ if not self.loaded:
289
+ return file
290
+
291
+ if os.path.exists(file):
292
+ try:
293
+ statbuf = dc_util.stat_at(file, cwd, follow_symlinks)
294
+ except OSError as e:
295
+ return '%s [Error stat-ing: %s]' % (file, e.strerror)
296
+
297
+ mode = statbuf.st_mode
298
+ if (not follow_symlinks) and show_target and stat.S_ISLNK(mode):
299
+ target_path = dc_util.readlink_at(file, cwd)
300
+ try:
301
+ dc_util.stat_at(target_path, cwd) # check for broken link
302
+ target = self.format(target_path, cwd, False, False)
303
+ except OSError:
304
+ # format as "orphan"
305
+ target = self._format_code(target_path, 'or') + ' [broken link]'
306
+ return self._format_code(file, 'ln') + ' -> ' + target
307
+ else:
308
+ mode = 0
309
+
310
+ return self.format_mode(file, mode)