|
24 | 24 | from winpython.config import DATA_PATH |
25 | 25 | from winpython.py3compat import configparser as cp |
26 | 26 |
|
| 27 | +# from former wppm separate script launcher |
| 28 | +from argparse import ArgumentParser |
| 29 | +from winpython import py3compat |
| 30 | + |
| 31 | + |
27 | 32 | # Workaround for installing PyVISA on Windows from source: |
28 | 33 | os.environ['HOME'] = os.environ['USERPROFILE'] |
29 | 34 |
|
@@ -645,41 +650,69 @@ def install_nsis_package(self, package): |
645 | 650 | self.copy_files(package, targetdir, '$_OUTDIR', outdir) |
646 | 651 | self._print_done() |
647 | 652 |
|
648 | | - |
649 | | -if __name__ == '__main__': |
650 | | - sbdir = osp.join(osp.dirname(__file__), |
| 653 | +def main(test=False): |
| 654 | + if test: |
| 655 | + sbdir = osp.join(osp.dirname(__file__), |
651 | 656 | os.pardir, os.pardir, os.pardir, 'sandbox') |
652 | | - tmpdir = osp.join(sbdir, 'tobedeleted') |
653 | | - |
654 | | - # for fname in os.listdir(sbdir): |
655 | | - # try: |
656 | | - # ins = Installation(fname) |
657 | | - # print fname, '--->', ins.name, ins.version, ins.architecture |
658 | | - # except NotImplementedError: |
659 | | - # pass |
660 | | - |
661 | | - # fname = osp.join(tmpdir, 'scipy-0.10.1.win-amd64-py2.7.exe') |
662 | | - fname = osp.join(sbdir, 'Cython-0.16.win-amd64-py2.7.exe') |
663 | | - fname = osp.join(sbdir, 'VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe') |
664 | | - fname = osp.join(sbdir, 'scikits.timeseries-0.91.3.win32-py2.7.exe') |
665 | | - print(Package(fname)) |
666 | | - sys.exit() |
667 | | - # fname = osp.join(sbdir, 'pylzma-0.4.4dev.win-amd64-py2.7.exe') |
668 | | - # fname = osp.join(sbdir, 'cx_Freeze-4.3.win-amd64-py2.6.exe') |
669 | | - # fname = osp.join(sbdir, 'PyQtdoc-4.7.2.win-amd64.exe') |
670 | | - # fname = osp.join(sbdir, 'winpython-0.1dev.win-amd64.exe') |
671 | | - target = osp.join(sbdir, 'winpython-2.7.3.amd64', 'python-2.7.3.amd64') |
672 | | - |
673 | | - target = osp.join(utils.BASE_DIR, 'build', |
| 657 | + tmpdir = osp.join(sbdir, 'tobedeleted') |
| 658 | + |
| 659 | + # fname = osp.join(tmpdir, 'scipy-0.10.1.win-amd64-py2.7.exe') |
| 660 | + fname = osp.join(sbdir, 'VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe') |
| 661 | + print(Package(fname)) |
| 662 | + sys.exit() |
| 663 | + target = osp.join(utils.BASE_DIR, 'build', |
674 | 664 | 'winpython-2.7.3', 'python-2.7.3') |
675 | | - # fname = osp.join(utils.BASE_DIR, 'packages.src', 'docutils-0.9.1.tar.gz') |
676 | | - fname = osp.join(utils.BASE_DIR, 'packages.win32', |
677 | | - 'PyQt-Py2.7-x32-gpl-4.8.6-1.exe') |
678 | | - fname = osp.join(utils.BASE_DIR, 'packages.win32', |
679 | | - 'scikits-image-0.6.1.win32-py2.7.exe') |
680 | | - |
681 | | - dist = Distribution(target, verbose=True) |
682 | | - pack = Package(fname) |
683 | | - print(pack.description) |
684 | | - # dist.install(pack) |
685 | | - # dist.uninstall(pack) |
| 665 | + fname = osp.join(utils.BASE_DIR, 'packages.src', 'docutils-0.9.1.tar.gz') |
| 666 | + |
| 667 | + dist = Distribution(target, verbose=True) |
| 668 | + pack = Package(fname) |
| 669 | + print(pack.description) |
| 670 | + # dist.install(pack) |
| 671 | + # dist.uninstall(pack) |
| 672 | + else: |
| 673 | + |
| 674 | + parser = ArgumentParser(description="WinPython Package Manager: install, "\ |
| 675 | + "uninstall or upgrade Python packages on a Windows "\ |
| 676 | + "Python distribution like WinPython.") |
| 677 | + parser.add_argument('fname', metavar='package', |
| 678 | + type=str if py3compat.PY3 else unicode, |
| 679 | + help='path to a Python package') |
| 680 | + parser.add_argument('-t', '--target', dest='target', default=sys.prefix, |
| 681 | + help='path to target Python distribution '\ |
| 682 | + '(default: "%s")' % sys.prefix) |
| 683 | + parser.add_argument('-i', '--install', dest='install', |
| 684 | + action='store_const', const=True, default=False, |
| 685 | + help='install package (this is the default action)') |
| 686 | + parser.add_argument('-u', '--uninstall', dest='uninstall', |
| 687 | + action='store_const', const=True, default=False, |
| 688 | + help='uninstall package') |
| 689 | + args = parser.parse_args() |
| 690 | + |
| 691 | + if args.install and args.uninstall: |
| 692 | + raise RuntimeError("Incompatible arguments: --install and --uninstall") |
| 693 | + |
| 694 | + if not args.install and not args.uninstall: |
| 695 | + args.install = True |
| 696 | + |
| 697 | + if not osp.isfile(args.fname): |
| 698 | + raise IOError("File not found: %s" % args.fname) |
| 699 | + |
| 700 | + if utils.is_python_distribution(args.target): |
| 701 | + dist = Distribution(args.target) |
| 702 | + try: |
| 703 | + package = Package(args.fname) |
| 704 | + if package.is_compatible_with(dist): |
| 705 | + if args.install: |
| 706 | + dist.install(package) |
| 707 | + else: |
| 708 | + dist.uninstall(package) |
| 709 | + else: |
| 710 | + raise RuntimeError("Package is not compatible with Python "\ |
| 711 | + "%s %dbit" % (dist.version, dist.architecture)) |
| 712 | + except NotImplementedError: |
| 713 | + raise RuntimeError("Package is not (yet) supported by WPPM") |
| 714 | + else: |
| 715 | + raise WindowsError("Invalid Python distribution %s" % args.target) |
| 716 | + |
| 717 | +if __name__ == '__main__': |
| 718 | + main() |
0 commit comments