Package backend :: Package satellite_tools :: Module diskImportLib
[hide private]
[frames] | no frames]

Source Code for Module backend.satellite_tools.diskImportLib

  1  # 
  2  # Common dumper stuff 
  3  # 
  4  # Copyright (c) 2008--2017 Red Hat, Inc. 
  5  # 
  6  # This software is licensed to you under the GNU General Public License, 
  7  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  8  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  9  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 10  # along with this software; if not, see 
 11  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 12  # 
 13  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 14  # granted to use or replicate Red Hat trademarks that are incorporated 
 15  # in this software or its documentation. 
 16  # 
 17  # 
 18   
 19  import os 
 20   
 21  import xmlSource 
 22  from spacewalk.common.rhnLib import hash_object_id 
 23  from spacewalk.server.importlib.backendOracle import SQLBackend 
 24  from spacewalk.server.importlib.channelImport import ChannelImport, ChannelFamilyImport 
 25  from spacewalk.server.importlib.packageImport import PackageImport, SourcePackageImport 
 26  from spacewalk.server.importlib import archImport 
 27  from spacewalk.server.importlib import productNamesImport 
 28  from spacewalk.server.importlib import orgImport 
 29   
 30   
31 -class Backend:
32 __backend = None 33
34 - def __init__(self):
35 pass
36
37 - def get_backend(self):
38 if self.__backend: 39 return self.__backend 40 41 Backend.__backend = SQLBackend() 42 return Backend.__backend
43 44 # get_backend() returns a shared instance of an Oracle backend 45 46
47 -def get_backend():
48 return Backend().get_backend()
49 50 # Functions for dumping packages 51 52
53 -def rpmsPath(obj_id, mountPoint, sources=0):
54 # returns the package path (for exporter/importer only) 55 # not to be confused with where the package lands on the satellite itself. 56 if not sources: 57 template = "%s/rpms/%s/%s.rpm" 58 else: 59 template = "%s/srpms/%s/%s.rpm" 60 return os.path.normpath(template % (mountPoint, hash_object_id(obj_id, 2), obj_id))
61 62 63 # pylint: disable=W0232
64 -class diskImportLibContainer:
65 66 """virtual class - redefines endContainerCallback""" 67 # pylint: disable=E1101,E0203,W0201 68 # this class has no __init__ for the purpose 69 # it's used in multiple inheritance mode and inherited classes should 70 # use __init__ from the other base class 71 72 importer_class = object 73
74 - def endContainerCallback(self):
75 importer = self.importer_class(self.batch, get_backend()) 76 importer.run() 77 self.batch = []
78 79
80 -class OrgContainer(xmlSource.OrgContainer):
81 importer_class = orgImport.OrgImport 82
83 - def __init__(self):
84 xmlSource.OrgContainer.__init__(self) 85 self.master_label = None 86 self.create_orgs = False
87
88 - def set_master_and_create_org_args(self, master, create_orgs):
89 self.master_label = master 90 self.create_orgs = create_orgs
91
92 - def endContainerCallback(self):
93 importer = self.importer_class(self.batch, get_backend(), 94 self.master_label, self.create_orgs) 95 importer.run() 96 self.batch = []
97 98
99 -class ProductNamesContainer(diskImportLibContainer, xmlSource.ProductNamesContainer):
100 importer_class = productNamesImport.ProductNamesImport 101
102 - def endContainerCallback(self):
103 if not self.batch: 104 return 105 diskImportLibContainer.endContainerCallback(self)
106 107
108 -class ChannelArchContainer(diskImportLibContainer, xmlSource.ChannelArchContainer):
109 importer_class = archImport.ChannelArchImport
110 111
112 -class PackageArchContainer(diskImportLibContainer, xmlSource.PackageArchContainer):
113 importer_class = archImport.PackageArchImport
114 115
116 -class ServerArchContainer(diskImportLibContainer, xmlSource.ServerArchContainer):
117 importer_class = archImport.ServerArchImport
118 119
120 -class CPUArchContainer(diskImportLibContainer, xmlSource.CPUArchContainer):
121 importer_class = archImport.CPUArchImport
122 123
124 -class ServerPackageArchCompatContainer(diskImportLibContainer, xmlSource.ServerPackageArchCompatContainer):
125 importer_class = archImport.ServerPackageArchCompatImport
126 127
128 -class ServerChannelArchCompatContainer(diskImportLibContainer, xmlSource.ServerChannelArchCompatContainer):
129 importer_class = archImport.ServerChannelArchCompatImport
130 131
132 -class ChannelPackageArchCompatContainer(diskImportLibContainer, xmlSource.ChannelPackageArchCompatContainer):
133 importer_class = archImport.ChannelPackageArchCompatImport
134 135
136 -class ServerGroupServerArchCompatContainer(diskImportLibContainer, xmlSource.ServerGroupServerArchCompatContainer):
137 importer_class = archImport.ServerGroupServerArchCompatImport
138 139
140 -class ChannelFamilyContainer(diskImportLibContainer, xmlSource.ChannelFamilyContainer):
141 importer_class = ChannelFamilyImport
142 143
144 -class ChannelContainer(diskImportLibContainer, xmlSource.ChannelContainer):
145 importer_class = ChannelImport
146 147
148 -class PackageContainer(diskImportLibContainer, xmlSource.PackageContainer):
149 importer_class = PackageImport
150 151
152 -class SourcePackageContainer(diskImportLibContainer, xmlSource.SourcePackageContainer):
153 importer_class = SourcePackageImport
154