Пример #1
0
test_commands_3 = [
    Command('ls -l', '~listing all the files in the current directory:'),
    Command('sleep 5', visible=False),
    Command('aaaaa', '~bad input'),
    Command('ps -al', '~listing all the processes:')
]

# test to make sure jibberish command fails and continues
test_commands_4 = [
    Command('ls -l', '~listing all the files in the current directory:'),
    Command('sleep 5', visible=False),
    Command('touch dummyfile.txt', '~creating a new file'),
    Command('ls -l', '~listing all the files in the current directory:'),
    Command('sleep 5', visible=False),
    Command('jibberish', '~this should fail 4 times and continue', retries=3, critical=False),
    Command('rm dummyfile.txt', '~removing the created file'),
    Command('ls -l', '~listing all the files in the current directory:')
]

print("\n\n\nRunning Test Commands 1:")
run_commands(test_commands_1)

print("\n\n\nRunning Test Commands 2:")
run_commands(test_commands_2)

print("\n\n\nRunning Test Commands 3:")
run_commands(test_commands_3)

print("\n\n\nRunning Test Commands 4:")
run_commands(test_commands_4)
#!/usr/bin/env python3
import fiximports
from DeclarScript.DeclarScript import Command, run_commands

hello_commands = [
    Command('echo "Hello World! :)"'),
    Command('ls -l'),
    Command('sleep 2', visible=False),
    Command('ps -al'),
    Command('cool')
]

run_commands(hello_commands)
default_backup_list = [
    Command('echo "Yup, this one\'s the default backup list. try entering 2 or 3 for the return code."', 'Beginning of the default')
]

test_commands_linux = [
    Command('ls', "List files."),
    Command('sleep 1', 'Sleep for 1 second.'),
    Command('./examples/returncode.py', 'Run the program with user input.', critical=False, return_code_backup_command_lists=return_code_user_input_backups, backup_command_list=default_backup_list),
    Command('ps', "List processes.")
]

test_commands_windows = [
    Command('ls', "List files."),
    Command('sleep 1', 'Sleep for 1 second.'),
    Command('examples\\returncode.py', 'Run the program with user input.', critical=False, return_code_backup_command_lists=return_code_user_input_backups, backup_command_list=default_backup_list),
    Command('ps', "List processes.")
]

# how to differentiate between platforms

print("\n\nRunning Custom Return Codes:")
if platform == "linux" or platform == "linux2" :
    run_commands(test_commands_linux)
elif platform == "darwin" :
    run_commands(test_commands_linux)
elif platform == "win32" :
    run_commands(test_commands_windows)
else :
    run_commands(test_commands_linux)
    print("weird platform: " + str(platform))
Пример #4
0
            backup_command_list=AAA_backups,
            critical=False),
    Command('echo "Final Command!"'),
]

# Here's a visual representation for the tree of backup command lists:

# (root)
#   |____(AAA)
#          |____(BBB)
#          |      |____(CCC)
#          |      X      |____backup_list_that_critically_fails
#          |      X
#          |      XXXXX(FFF)
#          |
#          |____(EEE)
#          |
#          |____(DDD)
#                 |____backup_list_that_succeeds

# The branch traversal order:
# (root)=>(A)=>(B)=>(C)=>(B)=>(A)=>(E)=>(A)=>(D)=>(A)=>(root)
# *Note: (F) Never gets executed since it comes after (C), and (C) fails critically.

# let's run it!
run_commands(the_root_command_list)

# After Running the tutorial_3 python script:
# Take a look at the terminal output and see if you can connect the terminal
# output with the image of the tree and the branch traveral.
Пример #5
0
# windows version
the_root_command_list_windows = [
    Command('cat */returncode.py',
            'The contents of the python script we are calling.'),
    Command(
        'echo "on the (return_code) day of Christmas, my true love gave to me..."'
    ),
    Command('tutorial_resources\\returncode.py',
            return_code_backup_command_lists=return_code_12_days_backups,
            backup_command_list=default_backup_list),
    Command(
        'echo "Success is boring! Let\'s see it fail by typing something other than 0..."'
    )
]

# This is how you differentiate between operating systems:
from sys import platform

if platform == "linux" or platform == "linux2":
    run_commands(the_root_command_list_linux_osx)
elif platform == "darwin":
    run_commands(the_root_command_list_linux_osx)
elif platform == "win32":
    run_commands(the_root_command_list_windows)
else:
    run_commands(the_root_command_list_linux_osx)
    print("weird platform: " + str(platform))

# After Running the tutorial_4 python script:
# Take a look at the terminal output and see if you can follow what happened.
Пример #6
0
#!/usr/bin/env python3
import fiximports
from DeclarScript.DeclarScript import Command
from DeclarScript.DeclarScript import run_commands

# test for detection of backups
return_code_user_input_backups = [
    #(return_code, backup_command_list)
    (1, [Command('ls -l', 'Beginning backup command list if return code is 1.'), Command('sleep 2', 'End this back up list')]),
    (3, [Command('ps -a', 'Beginning backup command list if return code is 3.'), Command('sleep 2', 'End this back up list')])
]

test_commands_1 = [
    Command('ls', "List files."),
    Command('sleep 2', 'Sleep for two seconds.'),
    Command('./examples/user-input.py', 'Run the program with user input.', prompt_responses=['5', '3'], critical=False, return_code_backup_command_lists=return_code_user_input_backups),
    Command('ls', "List files."),
    Command('ps', "List processes."),
    Command('sleep 2', 'Sleep for two seconds.'),
    Command('sudo ./examples/user-input2.py', 'Run the program with user input.', prompt_responses=['4']),
    Command('sleep 2', 'Sleep for two seconds.')
]

print("\n\n\nRunning Test Commands 1:")
run_commands(test_commands_1)
Пример #7
0
    pass

# run the program normally
from DeclarScript.DeclarScript import Command, run_commands
from sys import platform

print('\n\n\n     #####     Test 1     #####')
tut_1 = [
    Command('echo "Hello World! :)"'),
    Command('ls -l'),
    Command('sleep 2'),
    Command('ps -al'),
    Command('qwertyuiop'),
]

run_commands(tut_1)

print('\n\n\n     #####     Test 2     #####')
tut_2 = [
    Command('echo "Hello World! :)"'),
    Command('ls', message='List all the files in the current directory'),
    Command('ps', 'List the current processes', critical=False),
    Command('qwertyuiop',
            'Bad command, it should fail...',
            retries=1,
            critical=False),
    Command('echo "I\'m invisible! \\(\'o\')/"', visible=False),
    # Command('sleep 5', visible=False),
    Command('asdfghjkl',
            'Bad command, again.',
            sleep_between_retries=2,
Пример #8
0
            'Bad command, again.',
            sleep_between_retries=2,
            retries=3,
            critical=True),

    # These commands won't be executed because the 'badbutwait' command was critical and failed.
    Command('wont be executed',
            'The list will terminate before this command.'),
    Command('ps', 'The list will terminate before this command.'),
    Command('sleep 9999', 'I wouldn\'t make you wait 9999 seconds. :)')
]

# There are a few more options, but they deserve their own little tutorial.
# Here's a complete list of all 8 options and their default values

# (0) command=''
# (1) message=''
# (2) critical=True
# (3) retries=0
# (4) sleep_between_retries=0
# (5) visible=True
# (6) backup_command_list=[]
# (7) return_code_backup_command_lists=[]
# (8) prompt_responses=[]

# let's run it!
run_commands(tutorial_2_commands)

# After Running the tutorial_2 python script:
# Take a look at the terminal output and see if you can follow what happened.