def _add_sys_info(report_obj,
                  fileName):
    """
    Add the system specific info to the report object.  Handles the  case where
    these objects are already included via ABRT, in which case the ABRT information
    will not be overwritten.
     report_obj -- The redhat_support_lib.xml.report to which binding should be added.
     fileName   -- The original file or directory supplied by the user.  This will be
                   queried to determine package information.

    Information added:
     - Kernel version
     - Package info
     - Hostname
     - OS Arch
     - OS Release
    """
    info = {'kernel': True,
            'package': True,
            'hostname': True,
            'architecture': True,
            'os_release': True}
    # Step 1: See what is already there.
    bAry = report_obj.get_binding()
    for b in bAry:
        if b.get_name() in info:
            info[b.get_name()] = False

    if info['kernel']:
        report_obj.add_binding(report.binding(name='kernel',
                                              valueOf_=platform.release()))
    if info['package']:
        report_obj.add_binding(report.binding(name='package',
                                              valueOf_=rpm_for_file(fileName)))
    if info['hostname']:
        report_obj.add_binding(report.binding(name='hostname',
                                              valueOf_=platform.node()))
    if info['architecture']:
        report_obj.add_binding(report.binding(name='architecture',
                                              valueOf_=platform.processor()))
    if info['os_release']:
        report_obj.add_binding(report.binding(name='os_release',
                                    valueOf_=str(' ').join(platform.dist())))
def _process_file(fileName,
                  report_obj,
                  tar_refs=None,
                  max_file_size=MAX_FILE_SIZE_BYTES,
                  name=None):
    """
    Process a specific fileName as either a value in xml fileName
    or entry in tar fileName
    """
    if not name:
        name = os.path.basename(fileName)
    mtype = get_file_type(fileName)
    if os.path.getsize(fileName) > max_file_size or \
       str(mtype).rfind('charset=binary') >= 0 or \
       contains_invalid_xml_chars(fileName):
        tar_refs.append(fileName)
        report_obj.add_binding(report.binding(name=name,
                                              fileName=fileName,
                                              type_=mtype,
                                              href='content/%s' % \
                                              (os.path.basename(fileName))))
    else:
        # read content from fileName and place into xml
        f = open(fileName, 'rb')
        try:
            content = f.read()
        finally:
            f.close

        # BZ967510 - handle &#.*; chars and nested CDATA sections
        if re.search('[&;<>]', content):
            content = content.replace(']]>',']]]]><![CDATA[>')
            content = u'<![CDATA[%s]]>' % (content.decode('utf-8'))
        try:
            report_obj.add_binding(report.binding(name=name,
                                                  fileName=fileName,
                                                  type_=mtype,
                                                  valueOf_=content))
        except Exception, e:
            print e
def _add_custom(report_obj,
                custom):
    '''
    Add any custom bindings to the content.xml

    report_obj -- The redhat_support_lib.xml.report to which binding should be added.
    custom     -- A dictionary of bindings.  Key will be name and value will
    binding's value.

    e.g.
    <binding name='uid'>500</binding>
    '''
    for i in custom:
        report_obj.add_binding(report.binding(name=i,
                                              valueOf_=custom[i]))