Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- python -*-
# -*- coding: utf-8 -*-
# This file is part of Installsystems.
#
# Installsystems is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Installsystems 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Installsystems. If not, see <http://www.gnu.org/licenses/>.
'''
Repository v1
'''
from installsystems.image.package import PackageImage
from installsystems.printer import arrow, arrowlevel, warn, info
from installsystems.repository.config import RepositoryConfig
from installsystems.repository.database import Database
from installsystems.repository.repository import Repository
from os import listdir, unlink, symlink
from os.path import join, exists
from shutil import move, rmtree
from tempfile import mkdtemp
class Repository1(Repository):
def _add(self, image):
'''
Add description to db
'''
arrow("Adding metadata")
self.db.begin()
# insert image information
arrow("Image", 1)
self.db.ask("INSERT INTO image values (?,?,?,?,?,?,?)",
(image.md5,
image.name,
image.version,
image.date,
image.author,
image.description,
image.size,
))
# insert data information
arrow("Payloads", 1)
for name, obj in image.payload.items():
self.db.ask("INSERT INTO payload values (?,?,?,?,?)",
(obj.md5,
image.md5,
name,
obj.isdir,
obj.size,
))
# on commit
self.db.commit()
# update last file
self.update_last()
def images(self):
'''
Return a dict of information on images
'''
db_images = self.db.ask("SELECT md5, name, version, date, author, \
description, size \
FROM image ORDER BY name, version").fetchall()
images = []
field = ("md5", "name", "version", "date", "author", "description",
"size")
for info in db_images:
d = dict(zip(field, info))
d["repo"] = self.config.name
d["url"] = join(self.config.path, d["md5"])
d["format"] = 1
d["is_min_version"] = 9
images.append(d)
return images
@property
def uuid(self):
'''
Repository v1 doesn't support UUID
'''
return None
@property
def motd(self):
'''
Return repository message of the day.
Repository v1 don't have message of day
'''
return None
def setmotd(self, value=""):
'''
Don't set repository message of the day. Not supported by v1.
'''
# check local repository
warn(u"Repository v1 doesn't support motd. Unable to set")
@property
def version(self):
'''
Return repository version
'''
return 1
def upgrade(self):
raise NotImplementedError()
# if self.version == Database.version:
# info("Repository already up-to-date (%s)" % self.version)
# return
# else:
# arrow("Start repository upgrade")
# arrowlevel(1)
# # Create dummy repository
# tmpdir = mkdtemp()
# try:
# repoconf = RepositoryConfig("tmp_migrate_repo", path=tmpdir)
# dstrepo = Repository(repoconf)
# # Symlink content from repository into dummy repo
# for file in listdir(self.config.path):
# symlink(join(self.config.path, file),
# join(tmpdir, file))
# unlink(repoconf.dbpath)
# unlink(repoconf.lastpath)
# old_verbosity = installsystems.verbosity
# arrow("Initialize new database")
# # Disable unwanted message during upgrade
# installsystems.verbosity = 0
# dstrepo.init()
# # Restore verbosity
# installsystems.verbosity = old_verbosity
# md5s = self.db.ask("SELECT md5 FROM image").fetchall()
# # Copy images to dummy repository (fill new database)
# arrow("Fill database with images")
# arrowlevel(1)
# installsystems.verbosity = 0
# for img in [PackageImage(join(self.config.path, md5[0]),
# md5name=True) for md5 in md5s]:
# installsystems.verbosity = old_verbosity
# arrow("%s v%s" % (img.name, img.version))
# installsystems.verbosity = 0
# dstrepo.add(img)
# installsystems.verbosity = old_verbosity
# arrowlevel(-1)
# arrow("Backup old database")
# move(self.config.dbpath,
# join("%s.bak" % self.config.dbpath))
# # Replace old db with the new from dummy repository
# move(repoconf.dbpath, self.config.dbpath)
# self.update_last()
# arrowlevel(-1)
# arrow("Repository upgrade complete")
# finally:
# # Remove dummy repository
# rmtree(tmpdir)