Skip to content

Commit

Permalink
Run check_store_version() in obs_scm.Store and fix related code in Pr…
Browse files Browse the repository at this point in the history
…oject and Package
  • Loading branch information
dmach committed Jun 24, 2024
1 parent 3ffda9e commit 5c3cca6
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 15 deletions.
18 changes: 10 additions & 8 deletions osc/obs_scm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,16 +1573,18 @@ def init_package(apiurl: str, project, package, dir, size_limit=None, meta=False
raise oscerr.OscIOError(None, f'error: \'{dir}\' is already an initialized osc working copy')
else:
os.mkdir(os.path.join(dir, store))
store_write_project(dir, project)
store_write_string(dir, '_package', package + '\n')
Store(dir).apiurl = apiurl

s = Store(dir, check=False)
s.write_string("_osclib_version", Store.STORE_VERSION)
s.apiurl = apiurl
s.project = project
s.package = package
if meta:
store_write_string(dir, '_meta_mode', '')
s.write_string("_meta_mode", "")
if size_limit:
store_write_string(dir, '_size_limit', str(size_limit) + '\n')
s.size_limit = int(size_limit)
if scm_url:
Store(dir).scmurl = scm_url
s.scmurl = scm_url
else:
store_write_string(dir, '_files', '<directory />' + '\n')
store_write_string(dir, '_osclib_version', __store_version__ + '\n')
s.write_string("_files", "<directory />")
return Package(dir, progress_obj=progress_obj, size_limit=size_limit)
8 changes: 5 additions & 3 deletions osc/obs_scm/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,12 @@ def init_project(
else:
os.mkdir(os.path.join(dir, store))

store_write_project(dir, project)
Store(dir).apiurl = apiurl
s = Store(dir, check=False)
s.write_string("_osclib_version", Store.STORE_VERSION)
s.apiurl = apiurl
s.project = project
if scm_url:
Store(dir).scmurl = scm_url
s.scmurl = scm_url
package_tracking = None
if package_tracking:
store_write_initial_packages(dir, project, [])
Expand Down
3 changes: 3 additions & 0 deletions osc/obs_scm/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def __init__(self, path, check=True):
self.path = path
self.abspath = os.path.abspath(self.path)

if check:
check_store_version(self.abspath)

self.is_project = self.exists("_project") and not self.exists("_package")
self.is_package = self.exists("_project") and self.exists("_package")

Expand Down
1 change: 1 addition & 0 deletions tests/addfile_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/commit_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/deletefile_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/difffile_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/prdiff_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/prdiff_fixtures/some:project/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/repairwc_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/repairwc_fixtures/prj_noapiurl/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
1 change: 1 addition & 0 deletions tests/revertfile_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
6 changes: 6 additions & 0 deletions tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class TestMainCommand(OscMainCommand):
class TestPopProjectPackageFromArgs(unittest.TestCase):
def _write_store(self, project=None, package=None):
store = Store(self.tmpdir, check=False)
store.write_string("_osclib_version", Store.STORE_VERSION)
store.apiurl = "http://localhost"
if project:
store.project = project
store.is_project = True
Expand Down Expand Up @@ -408,6 +410,8 @@ def test_default_arch(self):
class TestPopProjectPackageRepositoryArchFromArgs(unittest.TestCase):
def _write_store(self, project=None, package=None):
store = Store(self.tmpdir, check=False)
store.write_string("_osclib_version", Store.STORE_VERSION)
store.apiurl = "http://localhost"
if project:
store.project = project
store.is_project = True
Expand Down Expand Up @@ -609,6 +613,8 @@ def test_working_copy_optional_arch(self):
class TestPopProjectPackageTargetProjectTargetPackageFromArgs(unittest.TestCase):
def _write_store(self, project=None, package=None):
store = Store(self.tmpdir, check=False)
store.write_string("_osclib_version", Store.STORE_VERSION)
store.apiurl = "http://localhost"
if project:
store.project = project
store.is_project = True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_init_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_meta_mode(self):
osc.core.Package.init_package('http://localhost', 'osctest', 'testpkg', pac_dir, meta=True)
storedir = os.path.join(pac_dir, osc.core.store)
self.assertFalse(os.path.exists(os.path.join(storedir, '_size_limit')))
self._check_list(os.path.join(storedir, '_meta_mode'), '')
self._check_list(os.path.join(storedir, '_meta_mode'), '\n')
self._check_list(os.path.join(storedir, '_project'), 'osctest\n')
self._check_list(os.path.join(storedir, '_package'), 'testpkg\n')
self._check_list(os.path.join(storedir, '_files'), '<directory />\n')
Expand Down
8 changes: 5 additions & 3 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class TestStore(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='osc_test')
self.store = Store(self.tmpdir, check=False)
self.store.write_string("_osclib_version", Store.STORE_VERSION)
self.store.apiurl = "http://localhost"
self.store.is_package = True
self.store.project = "project name"
self.store.package = "package name"
Expand Down Expand Up @@ -87,9 +89,9 @@ def test_contains(self):
self.assertFalse("_foo" in self.store)

def test_iter(self):
self.assertEqual(len(list(self.store)), 2)
self.assertEqual(len(list(self.store)), 4)
for fn in self.store:
self.assertIn(fn, ["_project", "_package"])
self.assertIn(fn, ["_osclib_version", "_apiurl", "_project", "_package"])

def test_apiurl(self):
self.store.apiurl = "https://example.com"
Expand Down Expand Up @@ -159,7 +161,7 @@ def test_osclib_version(self):
self.store.write_string("_osclib_version", "123")
self.fileEquals("_osclib_version", "123\n")

store2 = Store(self.tmpdir)
store2 = Store(self.tmpdir, check=False)
self.assertEqual(store2.osclib_version, "123")

def test_files(self):
Expand Down
1 change: 1 addition & 0 deletions tests/update_fixtures/osctest/.osc/_osclib_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0

0 comments on commit 5c3cca6

Please sign in to comment.