You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
4.3 KiB
151 lines
4.3 KiB
14 years ago
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
# Copyright (C) 2011 Adam D. Barratt <adsb@debian.org>
|
||
|
|
||
|
# 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 2 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.
|
||
|
|
||
13 years ago
|
class MigrationItem(object):
|
||
13 years ago
|
_architectures = []
|
||
|
|
||
|
@classmethod
|
||
|
def set_architectures(cls, architectures = None):
|
||
|
cls._architectures = architectures or []
|
||
|
|
||
|
@classmethod
|
||
|
def get_architectures(cls):
|
||
|
return cls._architectures
|
||
|
|
||
11 years ago
|
def __init__(self, name = None, versionned = True):
|
||
14 years ago
|
self._name = None
|
||
13 years ago
|
self._uvname = None
|
||
|
self._package = None
|
||
14 years ago
|
self._version = None
|
||
|
self._architecture = None
|
||
|
self._suite = None
|
||
14 years ago
|
self._versionned = versionned
|
||
14 years ago
|
|
||
|
if name:
|
||
13 years ago
|
self.name = name
|
||
14 years ago
|
|
||
13 years ago
|
def __str__(self):
|
||
13 years ago
|
if self._versionned and self.version is not None:
|
||
13 years ago
|
return self.name
|
||
|
else:
|
||
|
return self.uvname
|
||
|
|
||
13 years ago
|
def __eq__(self, other):
|
||
|
isequal = False
|
||
|
if self.uvname == other.uvname:
|
||
|
if self.version is None or other.version is None:
|
||
|
isequal = True
|
||
|
else:
|
||
|
isequal = self.version == other.version
|
||
|
|
||
13 years ago
|
return isequal
|
||
13 years ago
|
|
||
|
def __hash__(self):
|
||
|
return hash((self.uvname, self.version))
|
||
|
|
||
10 years ago
|
def __lt__(self, other):
|
||
|
return (self.uvname, self.version) < (other.uvname, other.version)
|
||
|
|
||
13 years ago
|
@property
|
||
|
def name(self):
|
||
14 years ago
|
return self._name
|
||
|
|
||
13 years ago
|
@name.setter
|
||
|
def name(self, value):
|
||
14 years ago
|
self._version = None
|
||
|
self._name = value
|
||
|
if value.startswith('-'):
|
||
|
value = value[1:]
|
||
|
parts = value.split('/', 3)
|
||
|
package = parts[0]
|
||
|
if '_' in package:
|
||
|
self._package, self._suite = package.split('_', 2)
|
||
|
else:
|
||
|
self._package, self._suite = (package, 'unstable')
|
||
13 years ago
|
if self._versionned and len(parts) > 1:
|
||
14 years ago
|
if len(parts) == 3:
|
||
13 years ago
|
self._architecture = parts[1]
|
||
|
self._version = parts[2]
|
||
14 years ago
|
else:
|
||
|
self._architecture = 'source'
|
||
13 years ago
|
self._version = parts[1]
|
||
14 years ago
|
else:
|
||
13 years ago
|
if len(parts) >= 2:
|
||
14 years ago
|
self._architecture = parts[1]
|
||
|
else:
|
||
|
self._architecture = 'source'
|
||
14 years ago
|
|
||
13 years ago
|
if self._version in self.__class__.get_architectures():
|
||
|
(self._architecture, self._version) = \
|
||
|
(self._version, self._architecture)
|
||
|
|
||
14 years ago
|
if '_' in self._architecture:
|
||
13 years ago
|
self._architecture, self._suite = \
|
||
14 years ago
|
self._architecture.split('_', 2)
|
||
|
|
||
|
if self.is_removal:
|
||
|
self._suite = 'testing'
|
||
13 years ago
|
|
||
13 years ago
|
self._canonicalise_name()
|
||
13 years ago
|
|
||
13 years ago
|
def _canonicalise_name(self):
|
||
13 years ago
|
parts = self._name.split('/', 3)
|
||
13 years ago
|
is_removal = self.is_removal
|
||
13 years ago
|
if len(parts) == 1 or self._architecture == 'source':
|
||
|
self._uvname = self._package
|
||
|
else:
|
||
|
self._uvname = "%s/%s" % (self._package, self._architecture)
|
||
|
if self._suite not in ('testing', 'unstable'):
|
||
|
self._uvname = '%s_%s' % (self._uvname, self._suite)
|
||
13 years ago
|
if is_removal:
|
||
|
self._uvname = '-%s' % (self._uvname)
|
||
13 years ago
|
if self._versionned:
|
||
13 years ago
|
self._name = '%s/%s' % (self._uvname, self._version)
|
||
13 years ago
|
else:
|
||
13 years ago
|
self._name = self._uvname
|
||
13 years ago
|
|
||
14 years ago
|
@property
|
||
|
def is_removal(self):
|
||
|
return self._name.startswith('-')
|
||
|
|
||
|
@property
|
||
|
def architecture(self):
|
||
13 years ago
|
return self._architecture
|
||
14 years ago
|
|
||
|
@property
|
||
|
def package(self):
|
||
|
return self._package
|
||
|
|
||
13 years ago
|
@property
|
||
|
def suite(self):
|
||
14 years ago
|
return self._suite
|
||
|
|
||
13 years ago
|
@suite.setter
|
||
|
def suite(self, value):
|
||
13 years ago
|
self._suite = value
|
||
|
self._canonicalise_name()
|
||
|
|
||
14 years ago
|
@property
|
||
|
def version(self):
|
||
|
return self._version
|
||
14 years ago
|
|
||
13 years ago
|
@property
|
||
|
def uvname(self):
|
||
|
return self._uvname
|
||
|
|
||
8 years ago
|
|
||
11 years ago
|
class UnversionnedMigrationItem(MigrationItem):
|
||
10 years ago
|
def __init__(self, name=None):
|
||
10 years ago
|
super().__init__(name=name, versionned=False)
|