Mercurial > hg
annotate mercurial/scmposix.py @ 30283:e1f6898a80e1
color: restore _style global after debugcolor ran
Before this change, running 'debugcolor' would destroy all color style for the
rest of the process life. We now properly backup and restore the variable
content. Using a global variable is sketchy in general and could probably be
removed. However, this is a quest for another adventure.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 03 Nov 2016 14:29:19 +0100 |
parents | c90a05124fae |
children | 4b1af1c867fa |
rev | line source |
---|---|
27483
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
1 from __future__ import absolute_import |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
2 |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
3 import os |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
4 import sys |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
5 |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
6 from . import ( |
30276
c90a05124fae
py3: make scmposix.userrcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27483
diff
changeset
|
7 encoding, |
27483
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
8 osutil, |
39087ee88835
scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22583
diff
changeset
|
9 ) |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
10 |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
11 def _rcfiles(path): |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
12 rcs = [os.path.join(path, 'hgrc')] |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
13 rcdir = os.path.join(path, 'hgrc.d') |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
14 try: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
15 rcs.extend([os.path.join(rcdir, f) |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
16 for f, kind in osutil.listdir(rcdir) |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
17 if f.endswith(".rc")]) |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
18 except OSError: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
19 pass |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
20 return rcs |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
21 |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
22 def systemrcpath(): |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
23 path = [] |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
24 if sys.platform == 'plan9': |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
25 root = 'lib/mercurial' |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
26 else: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
27 root = 'etc/mercurial' |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
28 # old mod_python does not set sys.argv |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
29 if len(getattr(sys, 'argv', [])) > 0: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
30 p = os.path.dirname(os.path.dirname(sys.argv[0])) |
22583
23c995ed466b
config: don't read the same config file twice
Mads Kiilerich <madski@unity3d.com>
parents:
18690
diff
changeset
|
31 if p != '/': |
23c995ed466b
config: don't read the same config file twice
Mads Kiilerich <madski@unity3d.com>
parents:
18690
diff
changeset
|
32 path.extend(_rcfiles(os.path.join(p, root))) |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
33 path.extend(_rcfiles('/' + root)) |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
34 return path |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
35 |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
36 def userrcpath(): |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
37 if sys.platform == 'plan9': |
30276
c90a05124fae
py3: make scmposix.userrcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27483
diff
changeset
|
38 return [encoding.environ['home'] + '/lib/hgrc'] |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
39 else: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
40 return [os.path.expanduser('~/.hgrc')] |