#!/bin/sh
sqlite3 "$REPOCOP_TEST_TMPDIR/tmp.db" <<EOSQL
attach database '$REPOCOP_TEST_DBDIR/rpm.db' as rpm;
CREATE TEMPORARY TABLE pytest (pkgid TEXT, filename TEXT);
CREATE TEMPORARY TABLE pyexample (pkgid TEXT, filename TEXT);
.mode tabs
INSERT INTO pytest SELECT pkgid, filename FROM rpm_files WHERE filemode & 61440 <> 16384 AND filename glob '*/python[0-9].[0-9]*/[Tt]est*/test_*';
DELETE FROM pytest WHERE pkgid GLOB '*-test-*' OR pkgid GLOB '*-tests-*' OR pkgid GLOB '*-devel-*' OR pkgid GLOB '*.test-*' OR pkgid GLOB '*.tests-*' OR pkgid GLOB '*-examples-*' OR pkgid GLOB '*-testing-*' OR pkgid GLOB '*-pickles-*';
DELETE FROM pytest WHERE pkgid GLOB '*.test*' OR pkgid GLOB '*.pytest*';
-- python3-module-testtools
DELETE FROM pytest WHERE pkgid GLOB '*-testtools-*';
-- python3-module-testscenarios
DELETE FROM pytest WHERE pkgid GLOB '*-testscenarios-*';
-- known pure developr's modules
DELETE FROM pytest WHERE pkgid GLOB 'python-module-PyDSTool-*' OR pkgid GLOB 'python-module-ETSDevTools-*' OR pkgid GLOB 'python-module-petsc-config-*' OR pkgid GLOB 'python-module-test*' OR pkgid GLOB 'python-module-*-autotest*';

INSERT INTO pyexample SELECT pkgid, filename FROM rpm_files WHERE filemode & 61440 <> 16384 AND filename glob '*/python[0-9].[0-9]*/example*/*';
DELETE FROM pyexample WHERE pkgid GLOB '*-examples-*' OR pkgid GLOB '*-doc-*' OR pkgid GLOB '*-docs-*' OR pkgid GLOB '*-pickles-*' OR pkgid GLOB '*-test-*' OR pkgid GLOB '*-tests-*' OR pkgid GLOB '*.tests-*' OR pkgid GLOB '*-testing-*';
DELETE FROM pyexample WHERE pkgid GLOB '*.test*' OR pkgid GLOB '*.pytest*';
-- known pure developr's modules
DELETE FROM pyexample WHERE pkgid GLOB 'python-module-PyDSTool-*' OR pkgid GLOB 'python-module-ETSDevTools-*' OR pkgid GLOB 'python-module-petsc-config-*' OR pkgid GLOB 'python-module-test*' OR pkgid GLOB 'python-module-*-autotest*';
.output $REPOCOP_TEST_TMPDIR/msg
SELECT a.pkgid, a.filename, b.sourceid, b.name FROM pytest as a LEFT JOIN rpm as b WHERE a.pkgid=b.pkgid;
.output $REPOCOP_TEST_TMPDIR/msg2
SELECT a.pkgid, a.filename, b.sourceid, b.name FROM pyexample as a LEFT JOIN rpm as b WHERE a.pkgid=b.pkgid;
EOSQL

cat > $REPOCOP_TEST_TMPDIR/repocop.awk <<'EOF'
BEGIN {FS="\t"}
// {system("repocop-test-info -k " $1 " '" $2 ": It is the file in the package whose name matches the format python modules use for test files. It may have been installed by accident. Remove it or move it to the -devel subpackage, if the test is required to build other packages. See http://www.altlinux.org/Python_Policy for details.'")}
EOF
cat $REPOCOP_TEST_TMPDIR/msg | /usr/share/repocop/pkgtests/altlinux-python-test-is-packaged/repocop-helper-altlinux-python-filelist-pattern-filter | awk -f $REPOCOP_TEST_TMPDIR/repocop.awk

cat > $REPOCOP_TEST_TMPDIR/repocop.awk <<'EOF'
BEGIN {FS="\t"}
// {system("repocop-test-experimental -k " $1 " '" $2 ": It is the file in the package whose location matches the format python modules use for examples. It may have been installed by accident. Move it to the -examples  or -doc subpackage. See http://www.altlinux.org/Python_Policy for details.'")}
EOF
cat $REPOCOP_TEST_TMPDIR/msg2 | /usr/share/repocop/pkgtests/altlinux-python-test-is-packaged/repocop-helper-altlinux-python-filelist-pattern-filter | awk -f $REPOCOP_TEST_TMPDIR/repocop.awk
rm $REPOCOP_TEST_TMPDIR/*
