Skip to content

Commit

Permalink
Introduce a U flag to collapse username to ~ #923 #915
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Mar 15, 2018
1 parent ec11785 commit 7923806
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sos/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,21 @@ def __format__(self, format_spec):
else:
return str(self).__format__(format_spec)

def collapseuser(path):
home = os.path.expanduser('~')
if path == home:
return '~'
elif path.startswith(home + os.sep):
return '~' + path[len(home):]
else:
return path

class path(type(Path())):
'''A regular target for files.
'''
CONVERTERS = {
'u': os.path.expanduser,

This comment has been minimized.

Copy link
@gaow

gaow Mar 15, 2018

Member

Do we still need a and u options, or are they just kept for backward compatibility?

'U': collapseuser,
'e': lambda x: x.replace(' ', '\\ '),
'a': lambda x: os.path.abspath(os.path.expanduser(x)),
'l': lambda x: os.path.realpath(os.path.expanduser(x)),
Expand Down

1 comment on commit 7923806

@BoPeng
Copy link
Contributor

@BoPeng BoPeng commented on 7923806 Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, u were kept for backward compatibility, a is still useful to expand relative path to absolute.

Please sign in to comment.