<s> from __future__ import print_function <EOL> import argparse <EOL> import getpass <EOL> import re <EOL> import sys <EOL> from noipy import utils <EOL> from noipy import dnsupdater <EOL> from noipy import authinfo <EOL> from noipy import __version__ <EOL> EXECUTION_RESULT_OK = <NUM_LIT:0> <EOL> EXECUTION_RESULT_NOK = <NUM_LIT:1> <EOL> URL_RE = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' , re . IGNORECASE ) <EOL> def execute_update ( args ) : <EOL> """<STR_LIT>""" <EOL> provider_class = getattr ( dnsupdater , <EOL> dnsupdater . AVAILABLE_PLUGINS . get ( args . provider ) ) <EOL> updater_options = { } <EOL> process_message = None <EOL> auth = None <EOL> if args . store : <EOL> if provider_class . auth_type == '<STR_LIT:T>' : <EOL> user_arg = args . usertoken or utils . get_input ( <EOL> "<STR_LIT>" ) <EOL> auth = authinfo . ApiAuth ( usertoken = user_arg ) <EOL> else : <EOL> user_arg = args . usertoken or utils . get_input ( <EOL> "<STR_LIT>" ) <EOL> pass_arg = args . password or getpass . getpass ( "<STR_LIT>" ) <EOL> auth = authinfo . ApiAuth ( user_arg , pass_arg ) <EOL> authinfo . store ( auth , args . provider , args . config ) <EOL> exec_result = EXECUTION_RESULT_OK <EOL> if not args . hostname : <EOL> update_ddns = False <EOL> process_message = "<STR_LIT>" <EOL> else : <EOL> update_ddns = True <EOL> elif args . usertoken and args . hostname : <EOL> if args . password : <EOL> auth = authinfo . ApiAuth ( args . usertoken , args . password ) <EOL> elif provider_class . auth_type == '<STR_LIT:T>' : <EOL> auth = authinfo . ApiAuth ( args . usertoken ) <EOL> update_ddns = True <EOL> exec_result = EXECUTION_RESULT_OK <EOL> elif args . hostname : <EOL> if authinfo . exists ( args . provider , args . config ) : <EOL> auth = authinfo . load ( args . provider , args . config ) <EOL> update_ddns = True <EOL> exec_result = EXECUTION_RESULT_OK <EOL> else : <EOL> update_ddns = False <EOL> exec_result = EXECUTION_RESULT_NOK <EOL> process_message = "<STR_LIT>" "<STR_LIT>" % args . provider <EOL> else : <EOL> update_ddns = False <EOL> exec_result = EXECUTION_RESULT_NOK <EOL> process_message = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> if update_ddns and args . provider == '<STR_LIT>' : <EOL> if args . url : <EOL> if not URL_RE . match ( args . url ) : <EOL> process_message = "<STR_LIT>" <EOL> exec_result = EXECUTION_RESULT_NOK <EOL> update_ddns = False <EOL> else : <EOL> updater_options [ '<STR_LIT:url>' ] = args . url <EOL> else : <EOL> process_message = "<STR_LIT>" "<STR_LIT>" <EOL> exec_result = EXECUTION_RESULT_NOK <EOL> update_ddns = False <EOL> response_code = None <EOL> response_text = None <EOL> if update_ddns : <EOL> ip_address = args . ip if args . ip else utils . get_ip ( ) <EOL> if not ip_address : <EOL> process_message = "<STR_LIT>" <EOL> exec_result = EXECUTION_RESULT_NOK <EOL> elif ip_address == utils . get_dns_ip ( args . hostname ) : <EOL> process_message = "<STR_LIT>" <EOL> else : <EOL> updater = provider_class ( auth , args . hostname , updater_options ) <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( args . hostname , ip_address , args . provider ) ) <EOL> response_code , response_text = updater . update_dns ( ip_address ) <EOL> process_message = updater . status_message <EOL> proc_result = { <EOL> '<STR_LIT>' : exec_result , <EOL> '<STR_LIT>' : response_code , <EOL> '<STR_LIT>' : response_text , <EOL> '<STR_LIT>' : process_message , <EOL> } <EOL> return proc_result <EOL> def create_parser ( ) : <EOL> parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> % dnsupdater . DEFAULT_PLUGIN , <EOL> choices = dnsupdater . AVAILABLE_PLUGINS . keys ( ) , <EOL> default = dnsupdater . DEFAULT_PLUGIN ) <EOL> parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" % <EOL> authinfo . DEFAULT_CONFIG_DIR , <EOL> default = authinfo . DEFAULT_CONFIG_DIR ) <EOL> parser . add_argument ( '<STR_LIT>' , metavar = '<STR_LIT>' , nargs = '<STR_LIT:?>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return parser <EOL> def main ( ) : <EOL> print ( "<STR_LIT>" % __version__ ) <EOL> parser = create_parser ( ) <EOL> args = parser . parse_args ( ) <EOL> result = execute_update ( args ) <EOL> print ( result . get ( '<STR_LIT>' ) ) <EOL> if result . get ( '<STR_LIT>' ) != EXECUTION_RESULT_OK : <EOL> parser . format_usage ( ) <EOL> sys . exit ( result . get ( '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
