Created
December 29, 2018 13:08
-
-
Save SirJson/f0624e1c91fbe1611d22f8efe514bf68 to your computer and use it in GitHub Desktop.
Can you guess what saeips means?
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 python3 | |
############### | |
# Todays challenge was to write code that is unreadable enough | |
# to be rejected by any sane person but still have a working version. | |
# | |
# How can we make this more dumb? | |
# ...I think in 2 hours I will already have a hard time reading this. | |
############### | |
import os | |
import sys | |
from pathlib import Path | |
from string import Template | |
from lib.sh import ln, mkdir, install, chown | |
from itertools import chain, dropwhile | |
home = sys.argv[1] | |
trgt = sys.argv[2] | |
shinc = 'activate' | |
sysout = Path(trgt, shinc) | |
usrout = Path(home, shinc) | |
tmpl = Path('./activate.in') | |
setupdir = Path(os.path.dirname(os.path.abspath(__file__))) | |
vars = {'location': trgt} | |
print(mkdir('-pv', trgt)) | |
chown('root:users',trgt) | |
comps = list(map(lambda q: q.name, filter(lambda u: u.is_dir() and 'leagcy' not in u.name and '.git' not in u.name, setupdir.iterdir()))) | |
for d in comps: | |
print('dir: ' + os.path.join(trgt,d)) | |
print(mkdir('-pv', os.path.join(trgt,d))) | |
chown('root:users',os.path.join(trgt,d)) | |
fmap = [] | |
for f in filter(lambda y: y.is_file(), chain.from_iterable(map(lambda a: a.iterdir(), map(lambda z: Path(setupdir, z),comps)))): | |
fmap.append((f, Path(trgt,*list(dropwhile(lambda x: x not in comps, f.parts))))) | |
run = map(lambda d: install('--group=users', '-v', '-C', str(d[0]), str(d[1])), fmap) | |
for r in run: | |
print(r) | |
with open(tmpl) as tpl: | |
with open(sysout, 'w') as acf: | |
acf.write(Template(tpl.read()).substitute(vars)) | |
ln('-svf' ,str(sysout), str(usrout)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment