Last active
July 21, 2023 05:43
-
-
Save takada-at/9df055a0860d771320e45e504b67ae25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import pwd | |
from subprocess import Popen | |
from optparse import OptionParser | |
myenv = """alias pythonexec='time ionice -n 7 -c 2 nice -n 19 {workdir}/bin/python' | |
alias rsyncd='rsync --daemon --verbose --port=11874 --config={home}/LOCAL/takada-at/rsync.conf --no-detach' | |
""" | |
screenrc = """escape ^T^T | |
defutf8 on | |
defkanji utf-8 | |
encoding utf-8 utf-8 | |
defencoding utf8 | |
bind o focus | |
#hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %100=%-8=%c:%s" | |
hardstatus alwayslastline "[%02c] %0`%-w%{=b bw}%n %t%{-}%+w %= %?%{=b rw}%2`%{-} `" | |
logfile "$HOME/.screen/screen-%Y%m%d-%n.log" | |
# log on | |
#deflog on | |
#caption always "%{= wk} %-w%{=bu dr}%n %t%{-}%+w %= %{=b wb}%y/%m/%d(%D) %{=b wb}%c" | |
#defc1 off | |
bind j exec | uim-fep -s lastline -S | |
bind k eval 'exec cat' kill redisplay | |
""" | |
execscreen = """#!/usr/bin/env python | |
import re | |
from subprocess import Popen, PIPE | |
import os | |
import sys | |
p1 = Popen(["screen", "-ls"], stdout=PIPE) | |
p2 = Popen(["grep", "takada-at"], stdin=p1.stdout, stdout=PIPE) | |
reg = re.compile("(\d+)\.takada-at") | |
m = reg.search(p2.communicate()[0].decode("utf-8")) | |
if m: | |
pid=m.group(1) | |
cmd = "screen -rx %s" % pid | |
os.system(cmd) | |
else: | |
cmd = "screen -c ~/LOCAL/takada-at/.screenrc -S takada-at -U" | |
os.system(cmd) | |
""" | |
rsyncconf = """uid = {user} | |
gid = {user} | |
log file = {home}LOCAL/takada-at/rsync.log | |
pid file = {home}LOCAL/takada-at/rsync.pid | |
use chroot = false | |
### module option | |
[stat] | |
comment = kg_kpi rsyncd server | |
path = {workdir} | |
read only = no | |
""" | |
def generate(path): | |
user = pwd.getpwuid(os.getuid())[0] | |
homedir = os.path.expanduser('~/') | |
workdir = os.path.realpath(path) | |
mydir = os.path.join(homedir, 'LOCAL', 'takada-at') | |
print('generate %s' % os.path.join(mydir, '.screenrc')) | |
io = open(os.path.join(mydir, '.screenrc'), 'w') | |
io.write(screenrc) | |
io.close() | |
print('generate %s' % os.path.join(mydir, 'execscreen.py')) | |
io = open(os.path.join(mydir, 'execscreen.py'), 'w') | |
io.write(execscreen) | |
io.close() | |
sub = Popen(["chmod", "+x", os.path.join(mydir, 'execscreen.py')]) | |
sub.communicate() | |
print('generate %s' % os.path.join(mydir, 'rsync.conf')) | |
io = open(os.path.join(mydir, 'rsync.conf'), 'w') | |
io.write(rsyncconf.format(home=homedir, user=user, workdir=workdir)) | |
io.close() | |
sub.communicate() | |
print('generate %s' % os.path.join(mydir, 'myenv.sh')) | |
io = open(os.path.join(mydir, 'myenv.sh'), 'w') | |
io.write(myenv.format(home=homedir, user=user, workdir=workdir)) | |
io.close() | |
print(""" | |
# python setup | |
wget http://peak.telecommunity.com/dist/ez_setup.py | |
{workdir}/bin/python ez_setup.py | |
{workdir}/bin/easy_install pip | |
""".format(workdir=workdir)) | |
def main(): | |
usage = "usage: %prog [options] [WORKDIR]" | |
parser = OptionParser(usage=usage) | |
opt, args = parser.parse_args() | |
if len(args) < 1: | |
workdir = os.path.expanduser("~/statistics") | |
else: | |
workdir = args[0] | |
generate(workdir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment