#!/bin/bash

# 
# Usage: write_row RPM_FILE ANALYZED_FILE INDEX_FILE STANDARD_DIRS_PATTERN
# $1 - name of rpm file
# $2 - name of analyzed file
# $3 - name of output file
# $4 - standard_dirs_pattern
#
# This function analyze the file and write a row to the index file
function write_row() {

    local rpm_file python_file index_file python_module

    rpm_file=${1}
    python_file=${2}
    index_file=${3}
    standard_dirs_pattern=${4}

    # extract the name of the module
    python_module=$(echo ${python_file} | sed "s#\.\?${standard_dirs_pattern}##;s#/#.#g;s/\(\.__init__\)\?\.py$//")

    echo "${rpm_file} ${python_module}" >> ${index_file}
}

source scan_lib

# Usage
# $1 - RPMS_ROOT
# $2 - INDEX_FILE
function scan_python () {
   local rpms_root index_file

   rpms_root=${1}
   index_file=${2}

   scan ${rpms_root} ${index_file} "/usr/\(local/\)\?lib\(64\)\?/python2\.[0-9]/\(site-packages/\)\?" "*.py" 

}


mode=${0/.*scan-/}
scan_all_mode $mode
