def _get_revisions_list(self, rev_file_path): if self._storage_adapter.path_exists(rev_file_path): rev_file = self._storage_adapter.read_file( rev_file_path, lock_file=rev_file_path + ".lock") rev_list = RevisionList.loads(rev_file) return rev_list else: return RevisionList()
def get_recipe_revisions(self, ref): """Returns a RevisionList""" if ref.revision: tmp = RevisionList() tmp.add_revision(ref.revision) return tmp.as_list() rev_file_path = self._recipe_revisions_file(ref) revs = self._get_revisions_list(rev_file_path).as_list() if not revs: raise RecipeNotFoundException(ref, print_rev=True) return revs
def get_package_revisions(self, pref): """Returns a RevisionList""" assert pref.ref.revision is not None, "BUG: server store needs PREV get_package_revisions" if pref.revision: tmp = RevisionList() tmp.add_revision(pref.revision) return tmp.as_list() tmp = self._package_revisions_file(pref) ret = self._get_revisions_list(tmp).as_list() if not ret: raise PackageNotFoundException(pref, print_rev=True) return ret
def test_compatibility_with_timestamps(self): the_time = float(floor(time.time())) iso = from_timestamp_to_iso8601(the_time) old_contents = '{"revisions": [{"revision": "rev1", "time": %s}, ' \ '{"revision": "rev2", "time": "%s"}]}' % (the_time, the_time) r_list = RevisionList.loads(old_contents) when = r_list.get_time("rev1") self.assertEqual(when, iso)
def _remove_revision(self, rev_file_path, revision): rev_file = self._storage_adapter.read_file(rev_file_path, lock_file=rev_file_path + ".lock") rev_list = RevisionList.loads(rev_file) rev_list.remove_revision(revision) self._storage_adapter.write_file(rev_file_path, rev_list.dumps(), lock_file=rev_file_path + ".lock")
def test_remove_non_latest(self): rev = RevisionList() rev.add_revision("rev1") rev.add_revision("rev2") dumped = rev.dumps() loaded = RevisionList.loads(dumped) loaded.remove_revision("rev1") self.assertEqual(loaded.latest_revision().revision, "rev2")
def _update_last_revision(self, rev_file_path, ref): if self._storage_adapter.path_exists(rev_file_path): rev_file = self._storage_adapter.read_file( rev_file_path, lock_file=rev_file_path + ".lock") rev_list = RevisionList.loads(rev_file) else: rev_list = RevisionList() if ref.revision is None: raise ConanException("Invalid revision for: %s" % ref.full_repr()) rev_list.add_revision(ref.revision) self._storage_adapter.write_file(rev_file_path, rev_list.dumps(), lock_file=rev_file_path + ".lock")
def test_remove_latest(self): rev = RevisionList() rev.add_revision("rev1") rev.add_revision("rev2") dumped = rev.dumps() loaded = RevisionList.loads(dumped) self.assertEquals(rev, loaded) self.assertEquals(loaded.latest_revision().revision, "rev2") loaded.remove_revision("rev2") self.assertEquals(loaded.latest_revision().revision, "rev1") self.assertIsNotNone(loaded.latest_revision().time)
def _get_latest_revision(self, rev_file_path): rev_list = self._get_revisions_list(rev_file_path) if not rev_list: # FIXING BREAK MIGRATION NOT CREATING INDEXES # BOTH FOR RREV AND PREV THE FILE SHOULD BE CREATED WITH "0" REVISION if self.path_exists( os.path.join(os.path.dirname(rev_file_path), DEFAULT_REVISION_V1)): rev_list = RevisionList() rev_list.add_revision(DEFAULT_REVISION_V1) self._storage_adapter.write_file(rev_file_path, rev_list.dumps(), lock_file=rev_file_path + ".lock") return rev_list.latest_revision() else: return None return rev_list.latest_revision()
def _load_package_revision_list(self, pref): path = self._package_revisions_file(pref) rev_file = self._storage_adapter.read_file(path, lock_file=path + ".lock") return RevisionList.loads(rev_file)
def migrate_to_revisions_layout(self): # .conan/data/lib/1.0/user/channel/export/* # .conan/data/lib/1.0/user/channel/0/export/* # .conan/data/lib/1.0/user/channel/package/* # .conan/data/lib/1.0/user/channel/0/package/* # .conan/data/lib/1.0/user/channel/package/XXX/* # .conan/data/lib/1.0/user/channel/0/package/XXX/0/* if not self.force_migrations: print("**********************************************") print("* *") print("* ERROR: STORAGE MIGRATION NEEDED! *") print("* *") print("**********************************************") msg = "A migration of your storage is needed, please backup first the storage " \ "directory and run:\n\n$ conan_server --migrate\n\n" logger.error(msg) print(msg) exit( 3 ) # Gunicorn expects error code 3 to stop retrying booting the worker print("**********************************************") print("* *") print("* MIGRATION IN PROGRESS *") print("* *") print("**********************************************") subdirs = list_folder_subdirs(basedir=self.store_path, level=4) for subdir in subdirs: base_dir = os.path.join(self.store_path, subdir) for export_or_package in os.listdir(base_dir): the_dir = os.path.join(base_dir, export_or_package) dest_dir = os.path.join(base_dir, DEFAULT_REVISION_V1) mkdir(dest_dir) print("Moving '%s': %s" % (subdir, export_or_package)) shutil.move(the_dir, dest_dir) rev_list = RevisionList() rev_list.add_revision(DEFAULT_REVISION_V1) save(os.path.join(base_dir, REVISIONS_FILE), rev_list.dumps()) packages_dir = os.path.join(self.store_path, subdir, DEFAULT_REVISION_V1, PACKAGES_FOLDER) if not os.path.exists(packages_dir): print("NO PACKAGES") continue for pid in os.listdir(packages_dir): package_dir = os.path.join(packages_dir, pid) mkdir(os.path.join(package_dir, DEFAULT_REVISION_V1)) print(" - Package '%s'" % pid) for item in os.listdir(package_dir): if item == DEFAULT_REVISION_V1: continue origin_path = os.path.join(package_dir, item) dest_path = os.path.join(package_dir, DEFAULT_REVISION_V1, item) mkdir(dest_dir) shutil.move(origin_path, dest_path) rev_list = RevisionList() rev_list.add_revision(DEFAULT_REVISION_V1) save(os.path.join(package_dir, REVISIONS_FILE), rev_list.dumps()) print("**********************************************") print("* *") print("* MIGRATION COMPLETED! *") print("* *") print("**********************************************")
def _load_revision_list(self, reference): path = self._recipe_revisions_file(reference) rev_file = self._storage_adapter.read_file(path, lock_file=path + ".lock") return RevisionList.loads(rev_file)