Exemple #1
0
def run_cmd(args, pip=None):
    #CD = subprocess.check_output('pwd').strip().decode('utf-8')
    print(color('rb'), 'Running Command', color('gb'), args, color())
    if pip:
        subprocess.run(shplit(pip_env_run(args)))
    else:
        subprocess.run(shplit(args))
def sign_package(package, key):
    from shlex import split as shplit
    from subprocess import PIPE

    with open(package, 'r') as f:
        import subprocess
        p1 = subprocess.Popen(shplit('openssl dgst -sha1 -binary'), stdin=f, stdout=PIPE)
        p2 = subprocess.Popen(shplit('openssl dgst -dss1 -sign "{0}"'.format(key)), stdin=p1.stdout, stdout=PIPE)
        p3 = subprocess.Popen(shplit('openssl enc -base64'), stdin=p2.stdout, stdout=PIPE)

        sig = ''.join(p3.communicate()[0].splitlines())

        p1.poll(), p2.poll(), p3.poll()
        if p1.returncode or p2.returncode or p3.returncode:
            raise RuntimeError

        return sig
Exemple #3
0
def sign_delta(filename, key, delta_tool):

    from shlex import split as shplit
    from subprocess import PIPE

    with open(filename, 'r') as f:
        import subprocess
        p1 = subprocess.Popen(shplit('openssl dgst -sha1 -binary'), stdin=f, stdout=PIPE)
        p2 = subprocess.Popen(shplit('openssl dgst -dss1 -sign "{0}"'.format(key)), stdin=p1.stdout, stdout=PIPE)
        p3 = subprocess.Popen(shplit('openssl enc -base64'), stdin=p2.stdout, stdout=PIPE)

        sig = ''.join(p3.communicate()[0].splitlines())

        p1.poll(), p2.poll(), p3.poll()
        if p1.returncode or p2.returncode or p3.returncode:
            raise RuntimeError

        return sig
Exemple #4
0
def parse_conf_file(f, dirname=''):
    thematics = {}
    for line in f:
        thema, *patts = shplit(line)
        files = [
            fi for pattern in patts
            for fi in find_files(pattern, dirname, thema)
        ]
        add_files_to_thematic(thematics, thema, *files)
    return thematics
def main(out, path):
    out_db = out
    test1_cmd = "python test_pars.py {} -u -m -d {}"
    test2_cmd = "python tempo2_test.py {} -r {} -d {}"

    # directories to expect in 'path': raw, converted,
    # failure(/fake, /dspsr), success
    dir_r = os.path.join(path, "raw")
    dir_c = os.path.join(path, "converted")
    dir_fd = os.path.join(path, "failure/dspsr")
    dir_ff = os.path.join(path, "failure/fake")
    dir_s = os.path.join(path, "success")
    for d in [dir_r, dir_c, dir_fd, dir_ff, dir_s]:
        if not os.path.exists(d):
            raise (RuntimeError("Path does not exist: " + d))

        if not os.access(d, os.R_OK):
            raise (RuntimeError("Necessary directories not read-able"))

        if not os.access(d, os.W_OK):
            raise (RuntimeError("Necessary directories not write-able"))

    # list of par files from /raw/
    raw_pars = os.path.join(dir_r, "*.par")
    par_files = sorted(glob(raw_pars))

    # convert par files to appropriate form
    pass

    # test par files for dspsr compatibility
    p = sproc.Popen(shplit(test1_cmd.format(raw_pars, 'dir')),
                    stdout=sproc.PIPE,
                    stderr=sproc.PIPE)
    p.wait()
    # check errors and output?

    # generate .db file
    conv_pars = os.path.join(dir_c, "*.par")
    par_files = sorted(glob(conv_pars))
    mpd_main(par_files, out_db, append=False)

    # check if conversion to .db files succeeded
    ## TODO: need to change tempo2_test.py to use correct pars and directories
    ttest_main(pars=raw_pars, root_dir='dir', db_file=out_db)

    # make new db file from successful pars
    good_pars = os.path.join(dir_s, "*.par")
    par_files = sorted(glob(good_pars))
    mpd_main(par_files, out_db, append=False)
Exemple #6
0
    exit(-1)

# Check if invalid command
if args['command'] is not None and args['command'] not in commands:
    parser.print_help()
    if started_from_gui():
        input_color_supported(f'{Colors.ASK}Press return to exit...')
    exit()

# Get options not specified from command line from input
if args['command'] is None:
    args['command'] = ask(f'{Colors.ASK}Command to run?',
                          options=list(commands.keys()))
if not files:
    files = shplit(
        ask(f'{Colors.ASK}Files to process? (Please surround each in "quotes")'
            ))
args['threads'] = threads if (
    args['threads'] is None or args['threads'] > threads) else args['threads']

command_runner: FFMpegCommand = commands[args['command']](args['command'],
                                                          ffmpeg_exe,
                                                          options=args)
# If additional arguments needed
if command_runner.requires_additional_arguments:
    # If args not supplied, ask
    if args['arguments'] is None or (
            command_runner.additional_arguments_validator is not None
            and not command_runner.additional_arguments_validator(
                args['arguments'])):
        args['arguments'] = ask(
Exemple #7
0
     for p in procs:
         p = p.strip()
         ppid, pid, cmd = re.split("\s+", p, maxsplit=2)
         if cmd == '/usr/sbin/xrdp':
             pids.add(pid)
         if ARGS.debug:
             print(p)
     # Get pid(s)
     if ARGS.debug:
         print(pids)
 
 
 parents = set()
 # Check the process states
 for pid in pids:
     proc = check_output(shplit(proc_cmd.format(pid=pid)))
     proc = proc.strip()
     state, stat = re.split(b"\s+", proc, maxsplit=1)
     state = state.decode('utf8')
     stat = stat.decode('utf8')
     if not (ARGS.quiet or ARGS.kill):
         if "Z" in state or "Z" in stat:
             print(pid, "is a zombie!")
         else:
             print(pid, "has state", state)
 
 # Check for processes with those pids as ppids (is a parent)
 with os.popen(procs_cmd) as procs:
     for p in procs:
         p = p.strip()
         ppid, cpid, cmd = re.split("\s+", p, maxsplit=2)
Exemple #8
0
def get_args(flags):
    p = argparse.ArgumentParser()
    for c in 'nlivx':
        p.add_argument(f'-{c}', action='store_true')
    return p.parse_args(shplit(flags))
Exemple #9
0
async def on_message(message):
    global ingame
    if message.content.startswith('*ping'):
        if len(shplit(message.content)) == 1:
            await client.send_message(message.channel, com.ping())
        else:
            await client.send_message(message.channel, man['ping'])

    elif message.content.startswith('*getstats'):
        if len(shplit(message.content)) == 1:
            await client.send_message(message.channel,
                                      com.getstats(message.author.id))
        elif len(shplit(message.content)) == 2:
            if message.author.id == dmid or "Dungeon Keeper" in [
                    y.name.lower() for y in message.author.roles
            ]:
                await client.send_message(
                    message.channel, com.getstats(shplit(message.content)[1]))
            else:
                await client.send_message(message.channel, 'Access denied!')
        else:
            await client.send_message(message.channel, man['getstats'])

    elif message.content.startswith('*mkchar'):
        if len(shplit(message.content)) == 1:
            await client.send_message(message.channel,
                                      com.mkchar(message.author.id))
        else:
            await client.send_message(message.channel, man['mkchar'])

    elif message.content.startswith('*putpoint'):
        if len(shplit(message.content)) == 2:
            await client.send_message(
                message.channel,
                com.putpoint(message.author.id,
                             shplit(message.content)[1]))
        elif len(shplit(message.content)) == 3:
            await client.send_message(
                message.channel,
                com.putpoint(message.author.id,
                             shplit(message.content)[1],
                             int(shplit(message.content)[2])))
        else:
            await client.send_message(message.channel, man['putpoint'])

    elif message.content.startswith('*delchar'):
        if len(shplit(message.content)) == 1:
            await client.send_message(message.channel,
                                      com.delchar(message.author.id))
        elif len(shplit(message.content)) == 2:
            if message.author.id == dmid or "Dungeon Keeper" in [
                    y.name.lower() for y in message.author.roles
            ]:
                await client.send_message(message.channel,
                                          com.delchar(message.author.id))
            else:
                await client.send_message(message.channel, 'Access denied!')
        else:
            await client.send_message(message.channel, man['delchar'])

    elif message.content.startswith('*man'):
        if len(shplit(message.content)) == 1:
            await client.send_message(
                message.channel,
                "Commands: ```\n*{}```".format('\n*'.join(man)))
        elif len(shplit(message.content)) == 2:
            await client.send_message(message.channel,
                                      man[shplit(message.content)[1]])
        else:
            await client.send_message(message.channel, man['man'])

    elif message.content.startswith('*restart'):
        if len(shplit(message.content)) == 1:
            if message.author.id == dmid:
                with open('.doblrest', 'w') as tmp:
                    tmp.write(message.channel.id)
                os.execv(__file__, sys.argv)
            else:
                await client.send_message(message.channel, 'Access denied!')

    elif message.content.startswith('*shutdown'):
        if len(shplit(message.content)) == 1:
            if message.author.id == dmid:
                await client.send_message(message.channel, 'Shutting down...')
                raise SystemExit
            else:
                await client.send_message(message.channel, 'Access denied!')
    elif message.content.startswith('*enter'):  # +init tracker
        if message.author.id in ingame:
            await client.send_message(message.channel,
                                      'You\'re already in the Dungeon!')
        else:
            await client.send_message(
                message.channel,
                '<@{}> has entered the Dungeon of Bad Luck...'.format(
                    message.author.id))
            ingame.append(message.author.id)
            if len(ingame) == 1:
                # genNpc = 0
                curTurn = 0
                # inBattle = False
                while True:
                    if ingame[curTurn][0] != 'n':
                        actions = ['n', 'L']
                        await client.send_message(
                            message.channel,
                            ext.buildActions(ingame[curTurn], actions))
                        resp = await client.wait_for_message(
                            author=await client.get_user_info(ingame[curTurn]),
                            channel=message.channel,
                            check=lambda x: True
                            if len(x.content) == 1 else False,
                            timeout=60)
                        if resp is None:
                            await client.send_message(message.channel,
                                                      'Timeout.')
                            await client.send_message(
                                message.channel,
                                '<@{}> does nothing.'.format(ingame[curTurn]))
                            curTurn += 1
                            if curTurn >= len(ingame):
                                curTurn -= len(ingame)
                            continue
                        else:
                            turn = resp.content
                        if turn not in actions:
                            await client.send_message(message.channel,
                                                      'Invalid turn.')
                            await client.send_message(
                                message.channel,
                                '<@{}> does nothing.'.format(ingame[curTurn]))
                            curTurn += 1
                        else:
                            if turn == 'L':
                                canLeave = True
                                for i in ingame:
                                    if i != ingame[curTurn]:
                                        await client.send_message(
                                            message.channel,
                                            '<@{}>, can <@{}> leave the Dungeon? (y/n)'
                                            .format(i, ingame[curTurn]))
                                        resp1 = await client.wait_for_message(
                                            author=await
                                            client.get_user_info(i),
                                            channel=message.channel,
                                            check=lambda x: True
                                            if len(x.content) == 1 else False,
                                            timeout=60)
                                        if resp1 is None:
                                            await client.send_message(
                                                message.channel, 'Timeout.')
                                        else:
                                            if resp1.content.lower() == 'n':
                                                canLeave = False
                                                break
                                            elif resp1.content.lower() == 'y':
                                                pass
                                            else:
                                                await client.send_message(
                                                    message.channel,
                                                    'Invalid choice. (assuming Y)'
                                                )
                                if canLeave is True:
                                    await client.send_message(
                                        message.channel,
                                        '<@{}> has left the Dungeon of Bad Luck.'
                                        .format(ingame[curTurn]))
                                    ingame.pop(curTurn)
                                    if len(ingame) == 0:
                                        break
                                else:
                                    if random.randint(1, 100) <= 10:
                                        await client.send_message(
                                            message.channel,
                                            '<@{}> has left the Dungeon of Bad Luck anyway.'
                                            .format(ingame[curTurn]))
                                        ingame.pop(curTurn)
                                        if len(ingame) == 0:
                                            break
                                    else:
                                        await client.send_message(
                                            message.channel,
                                            '<@{}> tried to escape, but to no avail.'
                                            .format(ingame[curTurn]))
                                        curTurn += 1
                                        if len(ingame) == 0:
                                            break
                            else:
                                if turn == 'n':
                                    await client.send_message(
                                        message.channel,
                                        '<@{}> does nothing.'.format(
                                            ingame[curTurn]))
                                curTurn += 1
                        if curTurn >= len(ingame):
                            curTurn -= len(ingame)
Exemple #10
0
from filehandler import python_findline as pf, python_writeline as pw, htmlfind_and_replace as hr
import htmlparser as html
import djangofiles as df
from htmlparser import color

if len(sys.argv) != 3:
    print("Error : {} <ProjectName> <Html Files Folder Name>".format(
        sys.argv[0]))
    exit()

#constants
HTML_FILE_NAMES = [
    f for f in glob.glob("{}/*.html".format(os.environ['PWD'] + '/' +
                                            sys.argv[2]))
]
PROJECT_NAME = shplit(sys.argv[1])[0]
PROJECT_HOME = subprocess.check_output('pwd').strip().decode('utf-8')
SETTINGS = '{}/{}/settings.py'.format(PROJECT_HOME, PROJECT_NAME)
URLS = '{}/{}/urls.py'.format(PROJECT_HOME, PROJECT_NAME)
DJANGO_PROJECT = 'django-admin startproject {} .'.format(PROJECT_NAME)
INSTALL_DJANGO_IN_VIRENV = 'pipenv install django'
PIPENV_RUN = 'pipenv run'
APPS = []
temp_file = '{}/{}'.format(PROJECT_HOME, 'templates')
if sys.argv[1] == 'setup':
    if not os.path.exists(temp_file):
        os.mkdir(temp_file)
    for i in HTML_FILE_NAMES:
        shutil.copy(i, temp_file)
        if len(hr(i, "[Model  ")) == 0:
            print(color('rb'), "# Fill the appropriate HTML file details ",
Exemple #11
0
def run_cmd(cmd):
    from subprocess import Popen, PIPE
    from shlex import split as shplit
    process = Popen(shplit(cmd), stdout=PIPE)
    output, error = process.communicate()
    return output, error