Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to grep out all pydoc in a python file

Options
  • 24-04-2020 11:03am
    #1
    Registered Users Posts: 5,576 ✭✭✭


    So i want to get everything between the initial """ and the final """ inclusive for all functions in a class

    Basically to save me needing copy and paste for the abstract classes


Comments

  • Registered Users Posts: 5,576 ✭✭✭veryangryman


    Bump

    Adding code for context :)
    @staticmethod
        def create_volume(compartment_id, display_name, size_in_gbs):
            """
            create_volume
    
            Builds a CreateVolumeDetails request object from the parameters passed in the method signature and calls
            the create_volume sdk endpoint to create a new volume in the specified compartment.
    
            :param compartment_id: ID of Tenancy or Compartment to create the new volume
            :param display_name: Name of the new volume
            :param size_in_gbs:: Value that specifies size of the volume in Gbs
    
            :return Block storage volume object if return_id param is set to false in the call to base_rest_util.create_resource
                    otherwise volume ID.
            :rtype oci.response.Response.data or String
            """
            availability_domain = ComputeRestUtils.get_first_availability_domain(compartment_id)
            log.info("Creating volume {0}")
            return base_rest_util.create_resource(
                RESOURCE_TYPE,
                BLK_STORAGE_CLIENT.create_volume,
                BlockStorageRestUtil._create_block_storage_object(
                    availability_domain, compartment_id, display_name, size_in_gbs))
    
        @staticmethod
        def create_volume_and_wait_for_state(compartment_id, display_name, size_in_gbs, state):
            """
            create_volume_and_wait_for_state
    
            Builds a CreateVolumeDetails request object from the parameters passed in the method signature and calls
            the create_volume sdk endpoint to create a new volume in the specified compartment and recursively check the
            state matches the expected state provided.
    
            :param compartment_id: ID of Tenancy or Compartment to create the new volume
            :param display_name: Name of the new volume
            :param size_in_gbs:: Value that specifies size of the volume in Gbs
            :param state: State to check for, should be one of the defined lifecycle states on the volume object
    
    
            :return Block storage volume object if return_id param is set to false in the call to base_rest_util.create_resource
                   otherwise volume ID.
            :rtype oci.response.Response.data or String
            """
    

    So we want to from a bash command like grep awk or sed) just get the method signature and pydoc outputted


  • Registered Users Posts: 508 ✭✭✭purpleisafruit


    This worked for me on OSX
    sed -n '/"""/,/"""/p' <file>.py
    


  • Registered Users Posts: 5,576 ✭✭✭veryangryman


    This worked for me on OSX
    sed -n '/"""/,/"""/p' <file>.py
    

    Loses the

    @staticmethod

    and

    def

    When i run it. I want them to be included


  • Registered Users Posts: 508 ✭✭✭purpleisafruit


    sed -n '/@/,/::rtype oci.response.Response.data or String """/p''
    
    Try that, if I'm understanding correctly.
    Not the prettiest, but works for the example given. If rtype is different then you may have to change that piece of the sed


Advertisement