summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Kreuzer <andreas.kreuzer@open-infrastructure.net>2017-05-08 16:03:47 +0000
committerAndreas Kreuzer <andreas.kreuzer@open-infrastructure.net>2017-05-18 11:54:04 +0000
commit1e9797028a82e2d41d46e966a94fdd0e8f6d1c02 (patch)
tree025ff7bc9db128e7e8d622097e195d7af6b9ece5
parentAdding share/man/examples/config. (diff)
downloadpackage-tracker-1e9797028a82e2d41d46e966a94fdd0e8f6d1c02.tar.xz
package-tracker-1e9797028a82e2d41d46e966a94fdd0e8f6d1c02.zip
Adding share/doc/examples/testing.
Signed-off-by: Andreas Kreuzer <andreas.kreuzer@open-infrastructure.net>
-rwxr-xr-xshare/doc/examples/testing/package-tracker.apt99
-rwxr-xr-xshare/doc/examples/testing/package-tracker.apt_pkg150
-rwxr-xr-xshare/doc/examples/testing/regex.py25
-rwxr-xr-xshare/doc/examples/testing/template.py57
4 files changed, 331 insertions, 0 deletions
diff --git a/share/doc/examples/testing/package-tracker.apt b/share/doc/examples/testing/package-tracker.apt
new file mode 100755
index 0000000..8b12441
--- /dev/null
+++ b/share/doc/examples/testing/package-tracker.apt
@@ -0,0 +1,99 @@
+#!/usr/bin/env python3
+# package-tracker - Compare and track package versions in debian repositories
+# Copyright (C) 2017 Andreas Kreuzer <andreas.kreuzer@open-infrastructure.net>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+import os.path
+import apt
+import apt_pkg
+import re
+
+software = u"package-tracker"
+program = sys.argv[0]
+install_path = "/"
+apt_root_path = "var/lib/" + software
+config_path = "etc/" + software
+
+# --------------------------------
+# Function definitions
+#
+def relink_sources_file(filename):
+ """ Creates a symlink of the desired input file to sources.list """
+ global apt_root_path, config_path, install_path
+
+ symlink_dir = os.path.join(
+ install_path,
+ apt_root_path,
+ "etc/apt/sources.list"
+ )
+
+ if (os.path.exists(symlink_dir)):
+ os.remove(symlink_dir)
+
+ os.symlink(
+ os.path.join(install_path, filename),
+ symlink_dir
+ )
+
+# --------------------------------
+# Main: load apt cache objects
+#
+relink_sources_file("etc/package-tracker/progress-linux.list")
+
+query_cache = apt.Cache(rootdir=os.path.join(install_path, apt_root_path))
+query_cache.update(None)
+query_cache.open()
+
+relink_sources_file("etc/package-tracker/debian.list")
+
+compare_cache = apt.Cache(rootdir=os.path.join(install_path, apt_root_path))
+compare_cache.update(None)
+compare_cache.open()
+
+
+print("size of query: ", len(query_cache))
+
+data = {}
+for package in query_cache:
+ archive = package.versions[0].origins[0].archive
+ if (not archive in data):
+ data[archive] = {}
+ if (not package.versions[0].source_name in data[archive]):
+ data[archive][package.versions[0].source_name] = []
+ data[archive][package.versions[0].source_name].append(package.shortname)
+
+for archive in data:
+ print("archive: ", archive)
+ print(" number of source packages: ", len(data[archive]))
+
+print("size of query: ", len(compare_cache))
+
+data2 = {}
+for package in compare_cache:
+ archive = package.versions[0].origins[0].archive
+ if (not archive in data2):
+ data2[archive] = {}
+ if (not package.versions[0].source_name in data2[archive]):
+ data2[archive][package.versions[0].source_name] = []
+ data2[archive][package.versions[0].source_name].append(package.shortname)
+
+for archive in data2:
+ print("archive: ", archive)
+ print(" number of source packages: ", len(data2[archive]))
+
+
+sys.exit(0)
diff --git a/share/doc/examples/testing/package-tracker.apt_pkg b/share/doc/examples/testing/package-tracker.apt_pkg
new file mode 100755
index 0000000..d62dd26
--- /dev/null
+++ b/share/doc/examples/testing/package-tracker.apt_pkg
@@ -0,0 +1,150 @@
+#!/usr/bin/env python3
+# package-tracker - Compare and track package versions in debian repositories
+# Copyright (C) 2017 Andreas Kreuzer <andreas.kreuzer@open-infrastructure.net>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import apt_pkg
+import sys, os
+import os.path
+import apt
+import apt.package
+import aptsources
+import aptsources.sourceslist
+import getopt
+
+read_sources = ''
+compare_sources = ''
+software = u'package-tracker'
+program = sys.argv[0]
+
+#FIXME use argparse instead getopt
+
+def usage():
+ print( 'Usage:', program, '-r <readsources> -c <comparesources>' )
+
+try:
+ command = sys.argv[1]
+except IndexError:
+ usage()
+ sys.exit(2)
+
+def readopts(argv):
+ global read_sources, compare_sources
+ try:
+ opts, args = getopt.getopt(argv,"hr:c:",["read-sources=","compare-sources="])
+ except getopt.GetoptError:
+ usage()
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == '-h':
+ usage()
+ sys.exit(0)
+ elif opt in ("-r", "--read-sources"):
+ read_sources = arg
+ elif opt in ("-c", "--compare-sources"):
+ compare_sources = arg
+ if not os.path.isfile(os.path.join("/etc/package-tracker", read_sources)):
+ print( "File", read_sources, 'does not exist')
+ usage()
+ sys.exit(1)
+ if not os.path.isfile(os.path.join("/etc/package-tracker", compare_sources)):
+ print( "File", compare_sources, 'does not exist')
+ usage()
+ sys.exit(1)
+
+if __name__ == "__main__":
+ readopts(sys.argv[1:])
+
+# -------------------------------------------
+#
+# Function definitions
+
+def config_apt(sources_file):
+ apt_pkg.init_config()
+ apt_pkg.config.set("Dir::State", "var/lib/" + software)
+ apt_pkg.config.set("Dir::Cache", "var/cache/" + software)
+ apt_pkg.config.set("Dir::Etc", "etc/" + software)
+ apt_pkg.config.set("Dir::Etc::sourcelist", sources_file)
+ apt_pkg.config.set("Dir::Log", "var/log/" + software)
+ apt_pkg.init_system()
+
+# -------------------------------------------
+#
+# Initializing apt environment for
+# a list of packages wich will be compared
+# to a second sourcefile.
+#
+
+config_apt(read_sources)
+
+acquire = apt_pkg.Acquire()
+slist = apt_pkg.SourceList()
+
+slist.read_main_list()
+slist.get_indexes(acquire, True)
+
+print( "Repositories to search packages from:" )
+for src in slist.list:
+ print( "\turi: ", src.uri, ' dist: ', src.dist )
+print()
+
+fromcache = apt_pkg.Cache()
+print()
+print(fromcache)
+print('Size:', len(fromcache))
+
+# -------------------------------------------
+#
+# Initializing apt environment to compare
+# the prepared list of packages.
+#
+
+config_apt(compare_sources)
+
+acquire2 = apt_pkg.Acquire()
+slist2 = apt_pkg.SourceList()
+
+slist2.read_main_list()
+slist2.get_indexes(acquire2, True)
+
+print( "Repositories to compare against:")
+for src in slist2.list:
+ print( "\turi: ", src.uri, ' dist: ', src.dist )
+
+print()
+
+tocache = apt_pkg.Cache()
+print()
+print(tocache)
+print('Size:', len(tocache))
+sys.exit(0)
+
+for frompackage in fromcache.packages:
+ print( frompackage.name )
+ for version in frompackage.version_list:
+ print( ' from: ', version.ver_str )
+ for plist, _ in version.file_list:
+ print( ' Origin: ', plist.origin, ' Component: ', plist.component, ' Archive: ', plist.archive)
+
+ try:
+ topackage = tocache[frompackage.name]
+ for version in topackage.version_list:
+ print( ' to: ', version.ver_str )
+ for plist, _ in version.file_list:
+ print( ' Origin: ', plist.origin, ' Component: ', plist.component, ' Archive: ', plist.archive)
+ except KeyError:
+ continue
+
+sys.exit(0)
diff --git a/share/doc/examples/testing/regex.py b/share/doc/examples/testing/regex.py
new file mode 100755
index 0000000..b0ef438
--- /dev/null
+++ b/share/doc/examples/testing/regex.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+# package-tracker - Compare and track package versions in debian repositories
+# Copyright (C) 2017 Andreas Kreuzer <andreas.kreuzer@open-infrastructure.net>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+import re
+
+test = "foo\n#bar\n #ack"
+test = re.sub(r"^#.*?$\n?", "", test, flags=re.MULTILINE)
+
+print(test)
diff --git a/share/doc/examples/testing/template.py b/share/doc/examples/testing/template.py
new file mode 100755
index 0000000..56ab00d
--- /dev/null
+++ b/share/doc/examples/testing/template.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# package-tracker - Compare and track package versions in debian repositories
+# Copyright (C) 2017 Andreas Kreuzer <andreas.kreuzer@open-infrastructure.net>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+import os.path
+import argparse
+import apt
+import apt_pkg
+import re
+import logging
+
+software = u"package-tracker"
+program = sys.argv[0]
+install_path = "/"
+apt_root_path = "var/" + software
+config_path = "etc/" + software
+log_file = "var/log/" + software + "/" + software + ".log"
+template_path = "usr/share/" + software + "/templates"
+
+file_path = os.path.join(install_path, template_path)
+f = open(file_path + '/report.html', 'r')
+if (not f):
+ print('ERROR')
+ sys.exit(1)
+
+content = f.read()
+f.close()
+
+template_element = ''
+m = re.search(r'{%PT_CONTENT_ELEMENT%}(.+?){%/PT_CONTENT_ELEMENT%}', content, re.DOTALL)
+if (m):
+ template_element = m.group(1)
+
+else:
+ print('no match')
+
+template_element = template_element.replace('{%PT_ELEMENT/%}', 'foobar')
+
+content = re.sub(r'{%PT_CONTENT_ELEMENT%}(.+?){%/PT_CONTENT_ELEMENT%}',
+ template_element, content, flags=re.DOTALL)
+
+print(content)