1 |
commit: 2cebb23f1497a1c50967e7772d4e36e7dc89b70e |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jul 30 22:21:48 2013 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jul 30 22:21:48 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=2cebb23f |
7 |
|
8 |
install.py: split out optparse compat code |
9 |
|
10 |
--- |
11 |
bin/install.py | 16 +--------------- |
12 |
pym/portage/util/_argparse.py | 19 +++++++++++++++++++ |
13 |
2 files changed, 20 insertions(+), 15 deletions(-) |
14 |
|
15 |
diff --git a/bin/install.py b/bin/install.py |
16 |
index 0bf7a1f..b194941 100755 |
17 |
--- a/bin/install.py |
18 |
+++ b/bin/install.py |
19 |
@@ -8,24 +8,10 @@ import sys |
20 |
import subprocess |
21 |
import traceback |
22 |
|
23 |
+from portage.util._argparse import ArgumentParser |
24 |
from portage.util.movefile import _copyxattr |
25 |
from portage.exception import OperationNotSupported |
26 |
|
27 |
-try: |
28 |
- from argparse import ArgumentParser |
29 |
-except ImportError: |
30 |
- # Compatibility with Python 2.6 and 3.1 |
31 |
- from optparse import OptionParser |
32 |
- |
33 |
- class ArgumentParser(object): |
34 |
- def __init__(self, **kwargs): |
35 |
- add_help = kwargs.pop("add_help", None) |
36 |
- if add_help is not None: |
37 |
- kwargs["add_help_option"] = add_help |
38 |
- parser = OptionParser(**kwargs) |
39 |
- self.add_argument = parser.add_option |
40 |
- self.parse_known_args = parser.parse_args |
41 |
- |
42 |
# Change back to original cwd _after_ all imports (bug #469338). |
43 |
os.chdir(os.environ["__PORTAGE_HELPER_CWD"]) |
44 |
|
45 |
|
46 |
diff --git a/pym/portage/util/_argparse.py b/pym/portage/util/_argparse.py |
47 |
new file mode 100644 |
48 |
index 0000000..5e6a9ba |
49 |
--- /dev/null |
50 |
+++ b/pym/portage/util/_argparse.py |
51 |
@@ -0,0 +1,19 @@ |
52 |
+# Copyright 2013 Gentoo Foundation |
53 |
+# Distributed under the terms of the GNU General Public License v2 |
54 |
+ |
55 |
+__all__ = ['ArgumentParser'] |
56 |
+ |
57 |
+try: |
58 |
+ from argparse import ArgumentParser |
59 |
+except ImportError: |
60 |
+ # Compatibility with Python 2.6 and 3.1 |
61 |
+ from optparse import OptionParser |
62 |
+ |
63 |
+ class ArgumentParser(object): |
64 |
+ def __init__(self, **kwargs): |
65 |
+ add_help = kwargs.pop("add_help", None) |
66 |
+ if add_help is not None: |
67 |
+ kwargs["add_help_option"] = add_help |
68 |
+ parser = OptionParser(**kwargs) |
69 |
+ self.add_argument = parser.add_option |
70 |
+ self.parse_known_args = parser.parse_args |