Skip to content

Commit

Permalink
Format using parent phd repo style.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisCummins committed Mar 4, 2018
1 parent 008dbbd commit b89146b
Show file tree
Hide file tree
Showing 4 changed files with 1,877 additions and 1,874 deletions.
99 changes: 49 additions & 50 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,74 @@ from __future__ import print_function

import json
import os
import subprocess
import sys

from argparse import ArgumentParser


def to_text(val):
return "yes" if val else "no"
return "yes" if val else "no"


def json_to_stream(blob, stream):
json.dump(blob, stream, sort_keys=True, indent=4, separators=(',', ': '))
print("", file=stream)
json.dump(blob, stream, sort_keys=True, indent=4, separators=(',', ': '))
print("", file=stream)


def merge_dicts(a, b):
""" returns a copy of 'a' with values updated by 'b' """
dst = a.copy()
dst.update(b)
return dst
""" returns a copy of 'a' with values updated by 'b' """
dst = a.copy()
dst.update(b)
return dst


DEFAULTS = {
"dotfiles": os.path.dirname(os.path.realpath(__file__)),
"private": os.path.expanduser("~/Dropbox/Shared"),
"apple_id": None,
"excludes": [],
"dotfiles": os.path.dirname(os.path.realpath(__file__)),
"private": os.path.expanduser("~/Dropbox/Shared"),
"apple_id": None,
"excludes": [],
}


def main():
parser = ArgumentParser(description="Configure dotfiles install.")
parser.add_argument(
"--dotfiles", metavar="<path>", default=DEFAULTS["dotfiles"],
help="path to dotfiles directory (default: {})".format(DEFAULTS["dotfiles"]))
parser.add_argument(
"--private", metavar="<path>", default=DEFAULTS["private"],
help="path to private directory (default: {})".format(DEFAULTS["private"]))
parser.add_argument(
"--apple-id", metavar="<email>", default=DEFAULTS["apple_id"],
help="Apple ID (e.g. example@email.com)")
parser.add_argument(
"-e", "--excludes", metavar="<tasks>", default="",
help="comma separated list of tasks to ignore")
args = parser.parse_args()

if os.path.exists("config.json"):
with open("config.json") as infile:
# Merge existing values into defaults
cfg = merge_dicts(DEFAULTS, json.loads(infile.read()))
else:
cfg = DEFAULTS

cfg["dotfiles"] = args.dotfiles if args.dotfiles else cfg["dotfiles"]
cfg["private"] = args.private if args.private else cfg["private"]
cfg["apple_id"] = args.apple_id if args.apple_id else cfg["apple_id"]
cfg["excludes"] = args.excludes.split(",") if args.excludes else cfg["excludes"]

# generate JSON config file
with open(os.path.join(cfg["dotfiles"], "config.json"), "w") as outfile:
json_to_stream(cfg, outfile)

# print configuration
json_to_stream(cfg, sys.stdout)
parser = ArgumentParser(description="Configure dotfiles install.")
parser.add_argument(
"--dotfiles", metavar="<path>", default=DEFAULTS["dotfiles"],
help="path to dotfiles directory (default: {})".format(DEFAULTS["dotfiles"]))
parser.add_argument(
"--private", metavar="<path>", default=DEFAULTS["private"],
help="path to private directory (default: {})".format(DEFAULTS["private"]))
parser.add_argument(
"--apple-id", metavar="<email>", default=DEFAULTS["apple_id"],
help="Apple ID (e.g. example@email.com)")
parser.add_argument(
"-e", "--excludes", metavar="<tasks>", default="",
help="comma separated list of tasks to ignore")
args = parser.parse_args()

if os.path.exists("config.json"):
with open("config.json") as infile:
# Merge existing values into defaults
cfg = merge_dicts(DEFAULTS, json.loads(infile.read()))
else:
cfg = DEFAULTS

cfg["dotfiles"] = args.dotfiles if args.dotfiles else cfg["dotfiles"]
cfg["private"] = args.private if args.private else cfg["private"]
cfg["apple_id"] = args.apple_id if args.apple_id else cfg["apple_id"]
cfg["excludes"] = args.excludes.split(",") if args.excludes else cfg["excludes"]

# generate JSON config file
with open(os.path.join(cfg["dotfiles"], "config.json"), "w") as outfile:
json_to_stream(cfg, outfile)

# print configuration
json_to_stream(cfg, sys.stdout)


if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\naborting without writing changes", file=sys.stderr)
sys.exit(1)
try:
main()
except KeyboardInterrupt:
print("\naborting without writing changes", file=sys.stderr)
sys.exit(1)
Loading

0 comments on commit b89146b

Please sign in to comment.