Created
June 8, 2016 18:55
-
-
Save Terrance/703a46d498e1fe581544e1c2bea42ec7 to your computer and use it in GitHub Desktop.
A wrapper script for Cygwin's setup.exe, with argparse-based command line handling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from argparse import ArgumentParser | |
from itertools import chain | |
import os | |
import subprocess | |
try: | |
import urllib.request as urllib | |
except ImportError: | |
import urllib | |
setupExe = "/setup/setup-x86_64.exe" | |
parser = ArgumentParser(description="CLI wrapper for Cygwin setup.") | |
parser.add_argument("-d", action="store_true", help="download latest setup") | |
parser.add_argument("-l", action="store_true", help="list installed packages") | |
parser.add_argument("-v", action="store_true", help="list and verify packages") | |
parser.add_argument("-i", action="store_const", const="M", default="q", help="show UI installer") | |
parser.add_argument("-a", nargs="+", default=(), metavar="pkg", help="install a new package") | |
parser.add_argument("-x", nargs="+", default=(), metavar="pkg", help="uninstall a package") | |
parser.add_argument("-r", nargs="+", default=(), metavar="pkg", help="reinstall a package") | |
parser.add_argument("-u", action="store_const", const="g", default="", help="upgrade all packages") | |
parser.add_argument("-f", action="store_const", const="f", default="", help="force latest for all packages") | |
parser.add_argument("-o", action="store_const", const="o", default="", help="remove orphan packages") | |
args = parser.parse_args() | |
if args.d: | |
print("https://www.cygwin.com/setup-x86_64.exe -> {0}".format(setupExe)) | |
urllib.urlretrieve("https://www.cygwin.com/setup-x86_64.exe", setupExe) | |
os.chmod(setupExe, os.stat(setupExe).st_mode | 0o111) | |
if any((args.l, args.v)): | |
cmd = ("/usr/bin/cygcheck", "-c{0}".format("d" if not args.v else "")) | |
print("=> {0}".format(" ".join(cmd))) | |
subprocess.Popen(cmd).wait() | |
if any(getattr(args, i) for i in "axrufo") or args.i == "M": | |
cmd = (setupExe, "-Bn" + args.i + args.u + args.o) \ | |
+ tuple(chain.from_iterable(("-P", pkg) for pkg in args.a)) \ | |
+ tuple(chain.from_iterable(("-x", pkg) for pkg in args.x)) \ | |
+ tuple(chain.from_iterable(("-x", pkg, "-P", pkg) for pkg in args.r)) | |
print("=> {0}".format(" ".join(cmd))) | |
subprocess.Popen(cmd).wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment