prepare argv[0] parsing for emulator use
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
d0abfbf01b
commit
76f3792885
1 changed files with 18 additions and 6 deletions
24
bin/cdist
24
bin/cdist
|
@ -25,6 +25,7 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
|
@ -55,12 +56,12 @@ REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer")
|
||||||
|
|
||||||
CODE_HEADER = "#!/bin/sh -e\n"
|
CODE_HEADER = "#!/bin/sh -e\n"
|
||||||
DOT_CDIST = ".cdist"
|
DOT_CDIST = ".cdist"
|
||||||
|
TYPE_PREFIX = "__"
|
||||||
VERSION = "2.0.0"
|
VERSION = "2.0.0"
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class TypeEmulator:
|
class TypeEmulator:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -612,10 +613,6 @@ def banner(args):
|
||||||
print(BANNER)
|
print(BANNER)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def install(args):
|
|
||||||
"""Install remote system"""
|
|
||||||
process = {}
|
|
||||||
|
|
||||||
def config(args):
|
def config(args):
|
||||||
"""Configure remote system"""
|
"""Configure remote system"""
|
||||||
process = {}
|
process = {}
|
||||||
|
@ -640,7 +637,16 @@ def config(args):
|
||||||
log.info("Total processing time for %s host(s): %s", len(args.host),
|
log.info("Total processing time for %s host(s): %s", len(args.host),
|
||||||
(time_end - time_start).total_seconds())
|
(time_end - time_start).total_seconds())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def install(args):
|
||||||
|
"""Install remote system"""
|
||||||
|
process = {}
|
||||||
|
|
||||||
|
def emulator():
|
||||||
|
"""Emulate type commands (i.e. __file and co)"""
|
||||||
|
process = {}
|
||||||
|
|
||||||
|
def commandline():
|
||||||
|
"""Parse command line"""
|
||||||
# Construct parser others can reuse
|
# Construct parser others can reuse
|
||||||
parser = {}
|
parser = {}
|
||||||
# Options _all_ parsers have in common
|
# Options _all_ parsers have in common
|
||||||
|
@ -702,3 +708,9 @@ if __name__ == "__main__":
|
||||||
args.func(args)
|
args.func(args)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if re.match(TYPE_PREFIX, os.path.basename(sys.argv[0])):
|
||||||
|
emulator()
|
||||||
|
else:
|
||||||
|
commandline()
|
||||||
|
|
Loading…
Reference in a new issue