<s> from . auth import basic_auth_opener <EOL> from . site import SharePointSite <EOL> class ExitCodes ( object ) : <EOL> MISSING_ACTION = <NUM_LIT:1> <EOL> NO_SUCH_ARGUMENT = <NUM_LIT:2> <EOL> NO_SUCH_LIST = <NUM_LIT:3> <EOL> MISSING_ARGUMENT = <NUM_LIT:4> <EOL> MISSING_CREDENTIALS = <NUM_LIT:5> <EOL> INVALID_CREDENTIALS = <NUM_LIT:6> <EOL> NO_SUCH_ACTION = <NUM_LIT:7> <EOL> def main ( ) : <EOL> from optparse import OptionParser , OptionGroup <EOL> import os <EOL> import sys <EOL> import warnings <EOL> from lxml import etree <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" ) <EOL> description = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> parser = OptionParser ( usage = '<STR_LIT>' , <EOL> description = '<STR_LIT>' . join ( description ) ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:username>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:password>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = True ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' ) <EOL> list_options = OptionGroup ( parser , '<STR_LIT>' ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' , action = '<STR_LIT>' ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = True , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = True , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> list_options . add_option ( '<STR_LIT>' , dest = '<STR_LIT:description>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> list_options . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT:100>' , help = '<STR_LIT>' ) <EOL> list_options . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , type = "<STR_LIT:float>" , help = '<STR_LIT>' ) <EOL> parser . add_option_group ( list_options ) <EOL> options , args = parser . parse_args ( ) <EOL> if not options . site_url : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( ExitCodes . MISSING_ARGUMENT ) <EOL> if options . credentials : <EOL> username , password = open ( os . path . expanduser ( options . credentials ) ) . read ( ) . strip ( ) . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> username , password = options . username , options . password <EOL> if not username : <EOL> username = raw_input ( "<STR_LIT>" ) <EOL> if not password : <EOL> from getpass import getpass <EOL> password = getpass ( ) <EOL> opener = basic_auth_opener ( options . site_url , username , password ) <EOL> site = SharePointSite ( options . site_url , opener , timeout = options . timeout ) <EOL> if not len ( args ) == <NUM_LIT:1> : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( ExitCodes . NO_SUCH_ACTION ) <EOL> action , xml = args [ <NUM_LIT:0> ] , None <EOL> if action == '<STR_LIT>' : <EOL> xml = site . as_xml ( include_lists = True , <EOL> list_names = options . list_names or None , <EOL> include_list_data = False , <EOL> include_field_definitions = False ) <EOL> elif action == '<STR_LIT>' : <EOL> xml = site . as_xml ( include_lists = True , <EOL> include_users = options . include_users , <EOL> list_names = options . list_names or None , <EOL> include_list_data = options . include_data , <EOL> include_field_definitions = options . include_field_definitions , <EOL> transclude_xml = options . transclude_xml ) <EOL> elif action == '<STR_LIT>' : <EOL> for list_name in options . list_names : <EOL> try : <EOL> site . lists . remove ( site . lists [ list_name ] ) <EOL> except KeyError : <EOL> sys . stderr . write ( "<STR_LIT>" . format ( list_name ) ) <EOL> sys . exit ( ExitCodes . NO_SUCH_LIST ) <EOL> if not options . list_names : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( ExitCodes . MISSING_ARGUMENT ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif action == '<STR_LIT>' : <EOL> for list_name in options . list_names : <EOL> try : <EOL> site . lists . create ( list_name , options . description , options . template ) <EOL> except KeyError : <EOL> sys . stderr . write ( "<STR_LIT>" . format ( list_name ) ) <EOL> sys . exit ( ExitCodes . NO_SUCH_LIST ) <EOL> if not options . list_names : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( ExitCodes . MISSING_ARGUMENT ) <EOL> xml = site . as_xml ( list_names = options . list_names or None , <EOL> include_field_definitions = options . include_field_definitions ) <EOL> elif action == '<STR_LIT>' : <EOL> try : <EOL> from IPython . Shell import IPShellEmbed <EOL> ipshell = IPShellEmbed ( ) <EOL> ipshell ( ) <EOL> except ImportError : <EOL> import code <EOL> import readline <EOL> readline . parse_and_bind ( "<STR_LIT>" ) <EOL> shell = code . InteractiveConsole ( { '<STR_LIT>' : site } ) <EOL> shell . interact ( ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if xml is not None : <EOL> sys . stdout . write ( etree . tostring ( xml , pretty_print = options . pretty_print ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
