# Path: src/LyxBlog/misc.py
# def pr3(input):
#     # Use sys.stdout instead of print so results can be used for automated testing
#     # For some reason a newline character is required to flush ?
#     # That's okay, because we'll use str.rstrip on the other side
#     input = str(input)  # This makes sure that anything printable can be passed through
#     sys.stdout.write(input + '\n')
#     # Each line must be flushed so it can be read by the other side.
#     sys.stdout.flush()


import os, sys, time
from src.LyxBlog.misc import pr3
# Call this file as:
# ./distribute.py <version>
# where <version> is a number like 1.49

print('''\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
About to run automated unit and interactive tests.
When you get the error screens, hit ENTER.
When asked for a password, enter "test" without the quotes.
''')
time.sleep(5)

def process_commands(command_list):
    for command in command_list:
        # Make sure each command executes properly. Otherwise, throw an exception
        a = os.system(command)
        if(a != 0):
            print('\nCommand was: ' + command)
            raise Exception('ERROR: There was a problem with one of your commands')


pre_commands = ['cd src \n python test_seed.py',  # Run unit tests and interactive on seed
    'rm -f INSTALL/lyxblogger.py ',    # Remove old version of lyxblogger
    'cd src \n ./coalesce.py seed.py > ../INSTALL/lyxblogger.py', # Construct lyxblogger.py
    'echo "Local password needed for installation of Python modules"', # Tell why password is needed
    'cd INSTALL \n sudo python setup.py install']  # Install the newly coalesced lyxblogger as a module

process_commands(pre_commands)
pr3('Unit tests passed')
filesize = os.path.getsize('INSTALL/lyxblogger.py')
assert(filesize > 15000) # As of LyXBlogger_0.33c, filesize was ~18k

# Path: src/LyxBlog/misc.py
# def pr3(input):
#     # Use sys.stdout instead of print so results can be used for automated testing
#     # For some reason a newline character is required to flush ?
#     # That's okay, because we'll use str.rstrip on the other side
#     input = str(input)  # This makes sure that anything printable can be passed through
#     sys.stdout.write(input + '\n')
#     # Each line must be flushed so it can be read by the other side.
#     sys.stdout.flush()


# Path: distribute.py
import os, sys, time
from src.LyxBlog.misc import pr3

# Call this file as:
# ./distribute.py <version>
# where <version> is a number like 1.49

print('''\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
About to run automated unit and interactive tests.
When you get the error screens, hit ENTER.
When asked for a password, enter "test" without the quotes.
''')
time.sleep(5)

def process_commands(command_list):
    for command in command_list:
        # Make sure each command executes properly. Otherwise, throw an exception
        a = os.system(command)
        if(a != 0):
            print('\nCommand was: ' + command)
            raise Exception('ERROR: There was a problem with one of your commands')


pre_commands = ['cd src \n python test_seed.py',  # Run unit tests and interactive on seed
    'rm -f INSTALL/lyxblogger.py ',    # Remove old version of lyxblogger
    'cd src \n ./coalesce.py seed.py > ../INSTALL/lyxblogger.py', # Construct lyxblogger.py
    'echo "Local password needed for installation of Python modules"', # Tell why password is needed
    'cd INSTALL \n sudo python setup.py install']  # Install the newly coalesced lyxblogger as a module

process_commands(pre_commands)
pr3('Unit tests passed')
filesize = os.path.getsize('INSTALL/lyxblogger.py')
assert(filesize > 15000) # As of LyXBlogger_0.33c, filesize was ~18k

pr3('seed.py with package coalesced into lyxblogger.py')