コード例 #1
0
ファイル: rsync.py プロジェクト: cjhammang/ReauthoringClone
def main():
    """
    Script to push the content of the build folder to a publishing site using
    rsync. The tool is assued to be installed in the system.

    Config variables:

    publish_src_folder: source folder to publish (Rsync notation)
    publish_dst_folder: destination folder to publish (Rsync notation)
    """

    # Check that rsync exists and can be executed
    if common.which('rsync') == None:
        print 'This script requires the application rsync to be installed and'
        print 'available in your system.'
        sys.exit(1)

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args=sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #2
0
def fetch_email(config_file, run_forever):
    """
    Start Backup Service
    """
    # Load config
    config = common.load_config_file(config_file)

    # Load logging config
    common.setup_logging_config("%s/../config/" % __abs_dirpath__)

    # Get logger
    logger = common.get_logger("app")

    logger.info("Starting mail parsing...")
    credentials_dir = os.path.join(__abs_dirpath__, '../.credentials')

    # Enhance configuration
    config['credentials_dir'] = credentials_dir

    # Instantiate services
    mail_reader = GmailReader(config=config, logger=logger)
    job_queuer = RedisJobQueuer(config=config, logger=logger)

    hackpad_processor = HackpadMailProcessor(config=config,
                                             mail_reader=mail_reader,
                                             job_queuer=job_queuer,
                                             logger=logger)

    if run_forever:
        hackpad_processor.run_forever()
    else:
        hackpad_processor.fetch_and_process_emails()
コード例 #3
0
ファイル: rsync.py プロジェクト: victerryso/flip_the_mrs
def main():
    """
    Script to push the content of the build folder to a publishing site using
    rsync. The tool is assued to be installed in the system.

    Config variables:

    publish_src_folder: source folder to publish (Rsync notation)
    publish_dst_folder: destination folder to publish (Rsync notation)
    """

    # Check that rsync exists and can be executed
    if common.which('rsync') == None:
        print 'This script requires the application rsync to be installed and'
        print 'available in your system.'
        sys.exit(1)

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #4
0
def load_config():
    global config

    defaults_present = False
    common.load_config_file(script_location + '/config/defaults.cfg', config)

    if len(config.sections()) is not 0:
        defaults_present = True

    common.load_config_file(script_location + '/config/config.cfg', config)

    if not defaults_present and len(config.sections()) is 0:
        common.console_print(
            "Both configuration files config.cfg and defaults.cfg are missing or empty! D:",
            console_prefix)
        common.console_print("We can't function like this...", console_prefix)
        shutdown()
コード例 #5
0
def load_custom_commands(reload, script_location):
    global commands, parent_location

    if parent_location is None:
        parent_location = script_location

    if reload:
        commands = defaultdict(dict)

    config = ConfigParser()
    common.load_config_file(
        parent_location + '/config/custom_discord_commands.cfg', config)

    if len(config.sections()) is 0:
        return

    sections = config.sections()

    for section in sections:
        if config.has_option(section, 'content'):
            commands[section]['content'] = config.get(section, 'content')

        commands[section]['base_command'] = None
        commands[section]['aliases'] = None
        commands[section]['description'] = None

        if config.has_option(section, 'alias_commands'):
            alternates = config.get(section, 'alias_commands').split(',')
            commands[section]['aliases'] = alternates

            for alternate in alternates:
                alternate = alternate.strip()
                commands[alternate]['base_command'] = section

        if config.has_option(section, 'description'):
            commands[section]['description'] = config.get(
                section, 'description')
コード例 #6
0
def main():
    """
    Script to change a line in a file and update its value with a new date/time
    tag. 
    """
    
    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #7
0
def main():
    """
    Script to search for a given set of expressions in files contained in a
    folder (or subfolder).
    """
    
    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #8
0
def main():
    """
    Script to change a line in a file and update its value with a new date/time
    tag. 
    """

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args=sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #9
0
def main():
    """
    Script to .....
    """

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args=sys.argv[1:])

    # This script does not need any additional arguments
    if len(args) != 1:
        print 'WARNING: Script needs one of the following arguments:'
        print ' ', '\n  '.join(sorted(sub_functions.keys()))
        sys.exit(1)

    sub_commands[args[0]](config)
コード例 #10
0
def main():
    """
    Script to search for a given set of expressions in files contained in a
    folder (or subfolder).
    """

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args=sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #11
0
def main():
    """
    Script to .....
    """
    
    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    # This script does not need any additional arguments
    if len(args) != 1:
        print 'WARNING: Script needs one of the following arguments:'
        print ' ', '\n  '.join(sorted(sub_functions.keys()))
        sys.exit(1)

    sub_commands[args[0]](config)
コード例 #12
0
def start(config_file):
    """
    Start Backup Service
    """
    # Load config
    config = common.load_config_file(config_file)

    # Load logging config
    common.setup_logging_config("%s/../config/" % __abs_dirpath__)

    # Get logger
    logger = common.get_logger("app")

    logger.info("Starting backup service...")

    # Download daily
    azure_file_backup = AzureFileBackup(config=config, logger=logger)
    azure_file_backup.download_daily()
コード例 #13
0
ファイル: run.py プロジェクト: victerryso/flip_the_mrs
def main(command_index):
    """
    Script to bundle the execution of multiple steps corresponding with other
    scripts.

    command_index is a dictionary with names to functions to execute.
    """

    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    if args == []:
        print 'Script must have one or more of the following keys:'
        print ' ', '\n  '.join(sorted(command_index.keys()))

    # Loop over the command names given
    for name in args:
        if command_index.get(name) == None:
            print 'Command', name, 'not found. Ignoring.'
            continue

        command_index[name](config)
コード例 #14
0
def main(command_index):
    """
    Script to bundle the execution of multiple steps corresponding with other
    scripts.

    command_index is a dictionary with names to functions to execute.
    """

    (config, args) = common.load_config_file(cmd_args=sys.argv[1:])

    if args == []:
        print 'Script must have one or more of the following keys:'
        print ' ', '\n  '.join(sorted(command_index.keys()))

    # Loop over the command names given
    for name in args:
        if command_index.get(name) == None:
            print 'Command', name, 'not found. Ignoring.'
            continue

        command_index[name](config)
コード例 #15
0
def main():
    """
    Script to run linkchecker in a folder. It expects the following variables:

    linkchecker_ignore_urls
    linkchecker_src_folder
    """
    
    # Check that rsync exists and can be executed
    if common.which('linkchecker') == None:
        print 'This script requires the application linkchecker to be',
        print 'installed and available in your system.'
        sys.exit(1)

    # Load config and arguments
    (config, args) = common.load_config_file(cmd_args = sys.argv[1:])

    # This script does not need any additional arguments
    if args != []:
        print 'WARNING: Script ignoring the following arguments:'
        print ' ', '\n  '.join(args)

    do(config)
コード例 #16
0
def load(parent_location):
    global bot_token, discord_playing, owner_ids, command_alias, discord_channels, discord_all_channels, discord_markov_channels, discord_markov_all_channels, chat_to_console, markov_learn_dm, ignore_bots, raw_to_markov, clean_output

    config = ConfigParser()
    common.load_config_file(parent_location + '/config/defaults.cfg', config)
    common.load_config_file(parent_location + '/config/config.cfg', config)

    if config.has_section('Discord'):
        command_alias = config.get('Discord',
                                   'command_alias',
                                   fallback='!derpy')
        bot_token = config.get('Discord', 'token', fallback='')
        discord_playing = config.get('Discord', 'playing', fallback='')

        for owner in config.get('Discord', 'owner_ids',
                                fallback='').split(','):
            owner_ids.append(owner.strip())

        if config.has_option('Markov', 'chat-to-console'):  # Legacy
            chat_to_console = config.getboolean('Discord',
                                                'chat-to-console',
                                                fallback=True)
        else:
            chat_to_console = config.getboolean('Discord',
                                                'chat_to_console',
                                                fallback=True)

        for channel in config.get('Discord', 'channels',
                                  fallback='').split(','):
            discord_channels.append(channel.strip())

        if config.has_option('Markov', 'markov-channels'):  # Legacy
            for channel in config.get('Discord',
                                      'markov-channels',
                                      fallback='').split(','):
                discord_markov_channels.append(channel.strip())
        else:
            for channel in config.get('Discord',
                                      'markov_channels',
                                      fallback='').split(','):
                discord_markov_channels.append(channel.strip())

        if config.has_option('Markov', 'markov_learn_pm'):  # Legacy
            markov_learn_dm = config.getboolean('Markov',
                                                'markov_learn_pm',
                                                fallback=True)
        else:
            markov_learn_dm = config.getboolean('Markov',
                                                'markov_learn_dm',
                                                fallback=True)

        discord_all_channels = config.getboolean('Discord',
                                                 'all_channels',
                                                 fallback=False)
        discord_markov_all_channels = config.getboolean('Discord',
                                                        'markov_all_channels',
                                                        fallback=False)
        #ignore_bots = config.getboolean('Discord', 'ignore_bots', fallback = True)
        raw_to_markov = config.getboolean('Discord',
                                          'raw_to_markov',
                                          fallback=False)
        clean_output = config.getboolean('Discord',
                                         'clean_output',
                                         fallback=True)
コード例 #17
0
if __name__ == '__main__':
    # Setup argument parser (we need to use Argparse for Gmail's Oauth 2.0 lib
    default_config_file = "%s/../config/config.yml" % __abs_dirpath__
    parser = argparse.ArgumentParser(parents=[tools.argparser])

    # Add our single option
    parser.add_argument('-c',
                        '--config-file',
                        help='Config file location',
                        required=False,
                        default=default_config_file)
    parser_namespace = parser.parse_args()
    arguments = vars(parser_namespace)

    # Load config
    config = common.load_config_file(arguments['config_file'])

    # Load logging config
    common.setup_logging_config("%s/../config/" % __abs_dirpath__)

    # Get logger
    logger = common.get_logger("gmail_auth")

    logger.info("Fetching Gmail Credentials...")
    credentials_dir = os.path.join(__abs_dirpath__, '../',
                                   config['credentials_dir_name'])

    # Enhance configuration
    config['credentials_dir'] = credentials_dir

    gmail_auth = GmailAuth(config=config,
コード例 #18
0
from configparser import ConfigParser
import common
import os

# config.py is just code. Don't put settings here!
# Settings should go in config.cfg

script_location = os.path.dirname(os.path.abspath(__file__))
config = ConfigParser()
common.load_config_file(script_location + '/config/defaults.cfg', config)
common.load_config_file(script_location + '/config/config.cfg', config)

if config.has_section('General'):
    dictionary_directory = config.get('General',
                                      'dictionary_directory',
                                      fallback='dictionaries')
    absolute_dictionary_directory = script_location + '/' + dictionary_directory
    main_dictionary_filename = config.get('General',
                                          'main_dictionary_file',
                                          fallback='main.txt')
    main_dictionary_file = absolute_dictionary_directory + '/' + main_dictionary_filename
    main_dictionary_format = config.get('General',
                                        'main_dictionary_format',
                                        fallback='lines')
    supplementary_text_filename = config.get('General',
                                             'supplementary_text_file',
                                             fallback='moar-lines.txt')
    supplementary_text_file = dictionary_directory + '/' + supplementary_text_filename
    state_size1 = config.getint('General', 'state_size', fallback=1)
    learn = config.getboolean('General', 'learn', fallback=True)
    save_interval = config.getint('General', 'save_interval', fallback=900)