Pymecavideo 8.0
Étude cinématique à l'aide de vidéos
version.py
1# -*- coding: utf-8 -*-
2
3"""
4 version, a module for pymecavideo:
5 a program to track moving points in a video frameset
6 This module is just an utility to manage the version number which
7 is important for releases of pymecavideo
8
9 Copyright (C) 2008-2018 Georges Khaznadar
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23"""
24
25import os.path
26import gzip
27import re
28
29
30class version:
31 def __init__(self, majeur, mineur, nuance=""):
32 self.majeur = majeur
33 self.mineur = mineur
34 self.nuance = nuance
35
36 def __lt__(self, other):
37 return (self.majeur < other.majeur) or \
38 (self.majeur == other.majeur and self.mineur < other.mineur)
39
40 def __str__(self):
41 return "%s.%s%s" % (self.majeur, self.mineur, self.nuance)
42
43 def __repr__(self):
44 return self.__str__()
45
46def str2version(chaine):
47 """
48 extrait la version d'une chaîne de caractères
49 """
50 m = re.match(r"(\d+)\.(\d+)(.*)", chaine)
51 if m:
52 return version(int(m.group(1)), int(m.group(2)), m.group(3))
53 return version(0, 0)
54
55def versionFromDebianChangelog():
56 """
57 Renvoie une version selon le contenu éventuel d'un fichier
58 /usr/share/doc/python3-mecavideo/changelog.Debian.gz
59 """
60 packageName = "python3-mecavideo"
61 changelog = os.path.join("/usr/share/doc", packageName, "changelog.Debian.gz")
62 if os.path.exists(changelog):
63 with gzip.open(changelog) as chlog:
64 firstline = chlog.readline().strip().decode("utf-8")
65 m = re.match(r"^pymecavideo \‍((.*)\‍).*$", firstline)
66 if m:
67 return str2version(m.group(1))
68 return None
69
70
71###############################################################
72# la version courante, à incrémenter lors de changements
73###############################################################
74Version = version(8, 1, '~rc3-1')
75
76###############################################################
77# incrémentation automatique pour une distribution debian
78###############################################################
79v = versionFromDebianChangelog()
80if v: Version = v
81
82if __name__ == "__main__":
83 print(Version)
def __str__(self)
Definition: version.py:40