[OPEN-ILS-DEV] OpenSRF Python name changes

Dan Scott denials at gmail.com
Mon Dec 17 13:20:42 EST 2007


Hi folks:

Over the weekend I modified much of the Python OpenSRF API to use more
pythonic naming conventions and to adhere more closely to the general
Python style guide (as indicated by pylint) in preparation for OpenSRF
1.0. Oh, and I added locale support. I also updated enough of the
Evergreen Python plug-in to make srfsh.py work as expected. Testing
and feedback on the new API is welcome; once we hit 1.0, we're going
to want this to be a stable API.

Attached is a script  that I used to perform most of the changes;
there will still be some changes you need to make by hand, and it will
probably introduce some regressions (sorry), but I thought it might be
useful for anyone who might have been building a client application on
top of the Python OpenSRF API.

-- 
Dan Scott
Laurentian University
-------------- next part --------------
import glob
import re

namesubs = {
    'checkStatus': 'check_status',
    'completeTime': 'complete_time',
    'findRequest': 'find_request',
    'findSession': 'find_session',
    'firstResponseTime': 'first_response_time',
    'getData': 'get_data',
    'getField': 'get_field',
    'setField': 'set_field',
    'getRegistry': 'get_registry',
    'importArrayData': 'import_array_data',
    'initHeaders': 'init_headers',
    'osrfAtomicRequest': 'AtomicRequest',
    'osrfClientSession': 'ClientSession',
    'osrfConfigValueNoEx': 'get_no_ex',
    'osrfConfigValue': 'get',
    'osrfConfig': 'Config',
    'osrfConfigException': 'OSRFConfigException',
    'osrfConnect': 'connect',
    'osrfDebugNetworkObject': 'debug_net_object',
    'osrfException': 'OSRFException',
    'osrfFormatJSON': 'pprint',
    'osrfGetNetworkHandle': 'get_network_handle',
    'osrfHandleMessage': 'handle_message',
    'osrfInitLog': 'initialize',
    'osrfInitSyslog': 'initialize_syslog',
    'osrfJSONNetworkEncoder': 'NetworkEncoder',
    'osrfJSONParseException': 'OSRFJSONParseException',
    'osrfJSONToObject': 'to_object',
    'osrfLoadSettings': 'load',
    'osrfLogDebug': 'log_debug',
    'osrfLogErr': 'log_error',
    'osrfLogInfo': 'log_info',
    'osrfLogInternal': 'log_internal',
    'osrfLogWarn': 'log_warn',
    '__osrfLog': '__log',
    'osrfNetworkException': 'OSRFNetworkException',
    'osrfNetworkMessage': 'Message',
    'osrfNetworkObjectException': 'OSRFNetworkObjectException',
    'osrfNetworkObject': 'NetworkObject',
    'osrfNetworkMessage': 'NetworkMessage',
    'osrfNetworkRegisterHint': 'network_register_hint',
    'osrfNetwork': 'Network',
    'osrfNewObjectFromHint': 'new_object_from_hint',
    'osrfObjectFindPath': 'find_object_path',
    'osrfObjectToJSON': 'to_json',
    'osrfObjectToXML': 'to_xml',
    'osrfParseJSONRaw': 'parse_json_raw',
    'osrfProtocolException': 'OSRFProtocolException',
    'osrfPushStack': 'push',
    'osrfRequest': 'Request',
    'osrfServerSession': 'ServerSession',
    'osrfServiceException': 'OSRFServiceException',
    'osrfSession': 'Session',
    'osrfSetNetworkHandle': 'set_network_handle',
    'osrfSettingsValue': 'get',
    'osrfToJSONRaw': 'to_json_raw',
    'osrfXMLFileToObject': 'xml_file_to_object',
    'osrfXMLStringToObject': 'xml_string_to_object',
    'osrfXMLNodeToObject': 'xml_node_to_object',
    'parseNetObject': 'parse_net_object',
    'parseRequest': 'parse_request',
    'pushResponseQueue': 'push_response_queue',
    'resetRequestTimeout': 'reset_request_timeout',
    'resetRemoteId': 'reset_remote_id',
    'resetTimeout': 'reset_timeout',
    'sendTime': 'send_time',
    'setComplete': 'set_complete',
    'setRemoteId': 'set_remote_id',
    'setRecvCallback': 'set_receive_callback',
    'recvCallback': 'receive_callback',
    'wireProtocol': 'protocol',

}

if __name__ == '__main__':
    for pyfile in glob.glob('*.py'):
        origfile = open(pyfile)
        lines = origfile.readlines()

        newlines = []
        for line in lines:
            for search, replace in namesubs.iteritems():
                sub = re.compile(search)
                line = sub.sub(replace, line)
            newlines.append(line)
        origfile.close()
            
        origfile = open(pyfile, 'w')
        for line in newlines:
            origfile.write(line)


More information about the Open-ils-dev mailing list