forked from importers/git-importer
		
	Compare commits
	
		
			24 Commits
		
	
	
		
			add_force
			...
			fix_ininti
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | aa73d97b35 | ||
|  | 574bc9aa10 | ||
|  | 0414b33206 | ||
|  | b9670821a9 | ||
|  | 073550825c | ||
|  | 5a353c98d3 | ||
|  | 1fc466d15b | ||
|  | 39fde7744a | ||
|  | f5ffc83a69 | ||
|  | d0ccf83684 | ||
|  | b0ffb01c59 | ||
|  | 28d5c6e606 | ||
|  | 1e22c2895a | ||
|  | 5da7861c2a | ||
|  | c9e07e536f | ||
|  | dc0f33354e | ||
|  | 56cbe0a125 | ||
|  | 4353f015c8 | ||
|  | 9cbe0899bc | ||
|  | 9e80a64fe0 | ||
|  | 12001b1640 | ||
|  | 3797ea178a | ||
|  | 999dcabcfa | ||
| 9962673eff | 
| @@ -1,4 +1,4 @@ | |||||||
| sudo zypper in python3-psycopg2 | sudo zypper in python3-psycopg | ||||||
| sudo su - postgres | sudo su - postgres | ||||||
| # `createdb -O <LOCAL_USER> imported_git` | # `createdb -O <LOCAL_USER> imported_git` | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										1355
									
								
								gone-packages.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1355
									
								
								gone-packages.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -14,8 +14,6 @@ def config(filename="database.ini", section="production"): | |||||||
|         for param in params: |         for param in params: | ||||||
|             db[param[0]] = param[1] |             db[param[0]] = param[1] | ||||||
|     else: |     else: | ||||||
|         raise Exception( |         raise Exception(f"Section {section} not found in the {filename} file") | ||||||
|             "Section {0} not found in the {1} file".format(section, filename) |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     return db |     return db | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								lib/db.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								lib/db.py
									
									
									
									
									
								
							| @@ -1,7 +1,6 @@ | |||||||
| import logging | import logging | ||||||
|  |  | ||||||
| import psycopg2 | import psycopg | ||||||
| from psycopg2.extras import LoggingConnection |  | ||||||
|  |  | ||||||
| from lib.config import config | from lib.config import config | ||||||
|  |  | ||||||
| @@ -17,22 +16,20 @@ class DB: | |||||||
|             # read the connection parameters |             # read the connection parameters | ||||||
|             params = config(section=self.config_section) |             params = config(section=self.config_section) | ||||||
|             # connect to the PostgreSQL server |             # connect to the PostgreSQL server | ||||||
|             self.conn = psycopg2.connect(connection_factory=LoggingConnection, **params) |             self.conn = psycopg.connect(conninfo=f"dbname={params['database']}") | ||||||
|             logger = logging.getLogger(__name__) |             logging.getLogger("psycopg.pool").setLevel(logging.INFO) | ||||||
|             self.conn.initialize(logger) |  | ||||||
|  |  | ||||||
|         except (Exception, psycopg2.DatabaseError) as error: |         except (Exception, psycopg.DatabaseError) as error: | ||||||
|             print(error) |             print(error) | ||||||
|             raise error |             raise error | ||||||
|  |  | ||||||
|     def schema_version(self): |     def schema_version(self): | ||||||
|         # create a cursor |         # create a cursor | ||||||
|         with self.conn.cursor() as cur: |         with self.conn.cursor() as cur: | ||||||
|  |  | ||||||
|             # execute a statement |             # execute a statement | ||||||
|             try: |             try: | ||||||
|                 cur.execute("SELECT MAX(version) from scheme") |                 cur.execute("SELECT MAX(version) from scheme") | ||||||
|             except psycopg2.errors.UndefinedTable as error: |             except psycopg.errors.UndefinedTable: | ||||||
|                 cur.close() |                 cur.close() | ||||||
|                 self.close() |                 self.close() | ||||||
|                 self.connect() |                 self.connect() | ||||||
| @@ -273,7 +270,7 @@ class DB: | |||||||
|                         cur.execute(command) |                         cur.execute(command) | ||||||
|             # commit the changes |             # commit the changes | ||||||
|             self.conn.commit() |             self.conn.commit() | ||||||
|         except (Exception, psycopg2.DatabaseError) as error: |         except (Exception, psycopg.DatabaseError) as error: | ||||||
|             print(error) |             print(error) | ||||||
|             self.close() |             self.close() | ||||||
|             raise error |             raise error | ||||||
|   | |||||||
| @@ -2,7 +2,6 @@ from __future__ import annotations | |||||||
|  |  | ||||||
| from hashlib import md5 | from hashlib import md5 | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| from typing import Optional |  | ||||||
|  |  | ||||||
| from lib.db import DB | from lib.db import DB | ||||||
| from lib.obs_revision import OBSRevision | from lib.obs_revision import OBSRevision | ||||||
| @@ -255,7 +254,7 @@ class DBRevision: | |||||||
|         self._files.sort(key=lambda x: x["name"]) |         self._files.sort(key=lambda x: x["name"]) | ||||||
|         return self._files |         return self._files | ||||||
|  |  | ||||||
|     def calc_delta(self, current_rev: Optional[DBRevision]): |     def calc_delta(self, current_rev: DBRevision | None): | ||||||
|         """Calculate the list of files to download and to delete. |         """Calculate the list of files to download and to delete. | ||||||
|         Param current_rev is the revision that's currently checked out. |         Param current_rev is the revision that's currently checked out. | ||||||
|         If it's None, the repository is empty. |         If it's None, the repository is empty. | ||||||
|   | |||||||
							
								
								
									
										188
									
								
								lib/git.py
									
									
									
									
									
								
							
							
						
						
									
										188
									
								
								lib/git.py
									
									
									
									
									
								
							| @@ -4,7 +4,6 @@ import os | |||||||
| import pathlib | import pathlib | ||||||
| import subprocess | import subprocess | ||||||
|  |  | ||||||
| import pygit2 |  | ||||||
| import requests | import requests | ||||||
|  |  | ||||||
| from lib.binary import BINARY | from lib.binary import BINARY | ||||||
| @@ -20,11 +19,6 @@ class Git: | |||||||
|         self.committer = committer |         self.committer = committer | ||||||
|         self.committer_email = committer_email |         self.committer_email = committer_email | ||||||
|  |  | ||||||
|         self.repo = None |  | ||||||
|  |  | ||||||
|     def is_open(self): |  | ||||||
|         return self.repo is not None |  | ||||||
|  |  | ||||||
|     def exists(self): |     def exists(self): | ||||||
|         """Check if the path is a valid git repository""" |         """Check if the path is a valid git repository""" | ||||||
|         return (self.path / ".git").exists() |         return (self.path / ".git").exists() | ||||||
| @@ -34,36 +28,69 @@ class Git: | |||||||
|         self.path.mkdir(parents=True, exist_ok=True) |         self.path.mkdir(parents=True, exist_ok=True) | ||||||
|         self.open() |         self.open() | ||||||
|  |  | ||||||
|  |     def git_run(self, args, **kwargs): | ||||||
|  |         """Run a git command""" | ||||||
|  |         if "env" in kwargs: | ||||||
|  |             envs = kwargs["env"].copy() | ||||||
|  |             del kwargs["env"] | ||||||
|  |         else: | ||||||
|  |             envs = os.environ.copy() | ||||||
|  |         envs["GIT_LFS_SKIP_SMUDGE"] = "1" | ||||||
|  |         envs["GIT_CONFIG_GLOBAL"] = "/dev/null" | ||||||
|  |         return subprocess.run( | ||||||
|  |             ["git"] + args, | ||||||
|  |             cwd=self.path, | ||||||
|  |             check=True, | ||||||
|  |             env=envs, | ||||||
|  |             **kwargs, | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def open(self): |     def open(self): | ||||||
|         # Convert the path to string, to avoid some limitations in |         if not self.exists(): | ||||||
|         # older pygit2 |             self.git_run(["init", "--object-format=sha256", "-b", "factory"]) | ||||||
|         self.repo = pygit2.init_repository(str(self.path)) |  | ||||||
|  |  | ||||||
|     def is_dirty(self): |     def is_dirty(self): | ||||||
|         """Check if there is something to commit""" |         """Check if there is something to commit""" | ||||||
|         assert self.is_open() |         status_str = self.git_run( | ||||||
|  |             ["status", "--porcelain=2"], | ||||||
|         return self.repo.status() |             stdout=subprocess.PIPE, | ||||||
|  |         ).stdout.decode("utf-8") | ||||||
|  |         return len(list(filter(None, status_str.split("\n")))) > 0 | ||||||
|  |  | ||||||
|     def branches(self): |     def branches(self): | ||||||
|         return list(self.repo.branches) |         br = ( | ||||||
|  |             self.git_run( | ||||||
|  |                 ["for-each-ref", "--format=%(refname:short)", "refs/heads/"], | ||||||
|  |                 stdout=subprocess.PIPE, | ||||||
|  |             ) | ||||||
|  |             .stdout.decode("utf-8") | ||||||
|  |             .split() | ||||||
|  |         ) | ||||||
|  |         if len(br) == 0: | ||||||
|  |             br.append("factory")  # unborn branch? | ||||||
|  |         return br | ||||||
|  |  | ||||||
|     def branch(self, branch, commit=None): |     def branch(self, branch, commit="HEAD"): | ||||||
|         if not commit: |         commit = ( | ||||||
|             commit = self.repo.head |             self.git_run( | ||||||
|         else: |                 ["rev-parse", "--verify", "--end-of-options", commit + "^{commit}"], | ||||||
|             commit = self.repo.get(commit) |                 stdout=subprocess.PIPE, | ||||||
|         self.repo.branches.local.create(branch, commit) |             ) | ||||||
|  |             .stdout.decode("utf-8") | ||||||
|  |             .strip() | ||||||
|  |         ) | ||||||
|  |         return self.git_run(["branch", branch, commit]) | ||||||
|  |  | ||||||
|     def checkout(self, branch): |     def checkout(self, branch): | ||||||
|         """Checkout into the branch HEAD""" |         """Checkout into the branch HEAD""" | ||||||
|         new_branch = False |         new_branch = False | ||||||
|         ref = f"refs/heads/{branch}" |  | ||||||
|         if branch not in self.branches(): |         if branch not in self.branches(): | ||||||
|             self.repo.references["HEAD"].set_target(ref) |             self.git_run(["switch", "-q", "--orphan", branch]) | ||||||
|             new_branch = True |             new_branch = True | ||||||
|         else: |         else: | ||||||
|             self.repo.checkout(ref) |             ref = f"refs/heads/{branch}" | ||||||
|  |             if (self.path / ".git" / ref).exists(): | ||||||
|  |                 self.git_run(["switch", "--no-guess", "-q", branch]) | ||||||
|         return new_branch |         return new_branch | ||||||
|  |  | ||||||
|     def commit( |     def commit( | ||||||
| @@ -87,51 +114,73 @@ class Git: | |||||||
|             committer_time = committer_time if committer_time else user_time |             committer_time = committer_time if committer_time else user_time | ||||||
|  |  | ||||||
|         if self.is_dirty(): |         if self.is_dirty(): | ||||||
|             self.repo.index.add_all() |             self.git_run(["add", "--all", "."]) | ||||||
|  |  | ||||||
|         self.repo.index.write() |         tree_id = ( | ||||||
|         author = pygit2.Signature(user, user_email, int(user_time.timestamp())) |             self.git_run(["write-tree"], stdout=subprocess.PIPE) | ||||||
|         committer = pygit2.Signature( |             .stdout.decode("utf-8") | ||||||
|             committer, committer_email, int(committer_time.timestamp()) |             .strip() | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         tree = self.repo.index.write_tree() |         parent_array = [] | ||||||
|         return self.repo.create_commit( |         if isinstance(parents, list): | ||||||
|             "HEAD", author, committer, message, tree, parents |             for parent in filter(None, parents): | ||||||
|  |                 parent_array = parent_array + ["-p", parent] | ||||||
|  |         elif isinstance(parents, str): | ||||||
|  |             parent_array = ["-p", parents] | ||||||
|  |  | ||||||
|  |         commit_id = ( | ||||||
|  |             self.git_run( | ||||||
|  |                 ["commit-tree"] + parent_array + [tree_id], | ||||||
|  |                 env={ | ||||||
|  |                     "GIT_AUTHOR_NAME": user, | ||||||
|  |                     "GIT_AUTHOR_EMAIL": user_email, | ||||||
|  |                     "GIT_AUTHOR_DATE": f"{int(user_time.timestamp())} +0000", | ||||||
|  |                     "GIT_COMMITTER_NAME": committer, | ||||||
|  |                     "GIT_COMMITTER_EMAIL": committer_email, | ||||||
|  |                     "GIT_COMMITTER_DATE": f"{int(committer_time.timestamp())} +0000", | ||||||
|  |                 }, | ||||||
|  |                 input=message.encode("utf-8"), | ||||||
|  |                 stdout=subprocess.PIPE, | ||||||
|             ) |             ) | ||||||
|  |             .stdout.decode("utf-8") | ||||||
|  |             .rstrip() | ||||||
|  |         ) | ||||||
|  |         self.git_run(["reset", "--soft", commit_id]) | ||||||
|  |         return commit_id | ||||||
|  |  | ||||||
|     def last_commit(self): |     def branch_head(self, branch="HEAD"): | ||||||
|         try: |         return ( | ||||||
|             return self.repo.head.target |             self.git_run( | ||||||
|         except: |                 ["rev-parse", "--verify", "--end-of-options", branch], | ||||||
|             return None |                 stdout=subprocess.PIPE, | ||||||
|  |             ) | ||||||
|     def branch_head(self, branch): |             .stdout.decode("utf-8") | ||||||
|         return self.repo.references["refs/heads/" + branch].target |             .strip() | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def set_branch_head(self, branch, commit): |     def set_branch_head(self, branch, commit): | ||||||
|         self.repo.references["refs/heads/" + branch].set_target(commit) |         return self.git_run(["update-ref", f"refs/heads/{branch}", commit]) | ||||||
|  |  | ||||||
|     def gc(self): |     def gc(self): | ||||||
|         logging.debug(f"Garbage recollect and repackage {self.path}") |         logging.debug(f"Garbage recollect and repackage {self.path}") | ||||||
|         subprocess.run( |         self.git_run( | ||||||
|             ["git", "gc", "--auto"], |             ["gc", "--auto"], | ||||||
|             cwd=self.path, |  | ||||||
|             stdout=subprocess.PIPE, |             stdout=subprocess.PIPE, | ||||||
|             stderr=subprocess.STDOUT, |             stderr=subprocess.STDOUT, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|     def clean(self): |     #    def clean(self): | ||||||
|         for path, _ in self.repo.status().items(): |     #        for path, _ in self.repo.status().items(): | ||||||
|             logging.debug(f"Cleaning {path}") |     #            logging.debug(f"Cleaning {path}") | ||||||
|             try: |     #            try: | ||||||
|                 (self.path / path).unlink() |     #                (self.path / path).unlink() | ||||||
|                 self.repo.index.remove(path) |     #                self.repo.index.remove(path) | ||||||
|             except Exception as e: |     #            except Exception as e: | ||||||
|                 logging.warning(f"Error removing file {path}: {e}") |     #                logging.warning(f"Error removing file {path}: {e}") | ||||||
|  |  | ||||||
|     def add(self, filename): |     def add(self, filename): | ||||||
|         self.repo.index.add(filename) |         self.git_run(["add", filename]) | ||||||
|  |  | ||||||
|     def add_default_lfs_gitattributes(self, force=False): |     def add_default_lfs_gitattributes(self, force=False): | ||||||
|         if not (self.path / ".gitattributes").exists() or force: |         if not (self.path / ".gitattributes").exists() or force: | ||||||
| @@ -185,9 +234,9 @@ class Git: | |||||||
|             return any(fnmatch.fnmatch(filename, line) for line in patterns) |             return any(fnmatch.fnmatch(filename, line) for line in patterns) | ||||||
|  |  | ||||||
|     def remove(self, file: pathlib.Path): |     def remove(self, file: pathlib.Path): | ||||||
|         self.repo.index.remove(file.name) |         self.git_run( | ||||||
|         (self.path / file).unlink() |             ["rm", "-q", "-f", "--ignore-unmatch", file.name], | ||||||
|  |         ) | ||||||
|         patterns = self.get_specific_lfs_gitattributes() |         patterns = self.get_specific_lfs_gitattributes() | ||||||
|         if file.name in patterns: |         if file.name in patterns: | ||||||
|             patterns.remove(file.name) |             patterns.remove(file.name) | ||||||
| @@ -201,7 +250,7 @@ class Git: | |||||||
|             logging.warning("Not adding a remote due to missing $GITEA_TOKEN") |             logging.warning("Not adding a remote due to missing $GITEA_TOKEN") | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         url = f"https://gitea.opensuse.org/api/v1/org/{org_name}/repos" |         url = f"https://src.opensuse.org/api/v1/org/{org_name}/repos" | ||||||
|         response = requests.post( |         response = requests.post( | ||||||
|             url, |             url, | ||||||
|             data={"name": repo_name}, |             data={"name": repo_name}, | ||||||
| @@ -212,20 +261,23 @@ class Git: | |||||||
|         # 201 Created |         # 201 Created | ||||||
|         if response.status_code not in (201, 409): |         if response.status_code not in (201, 409): | ||||||
|             print(response.data) |             print(response.data) | ||||||
|         url = f"gitea@gitea.opensuse.org:{org_name}/{repo_name}.git" |         url = f"gitea@src.opensuse.org:{org_name}/{repo_name}.git" | ||||||
|         self.repo.remotes.create("origin", url) |         self.git_run( | ||||||
|  |             ["remote", "add", "origin", url], | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def push(self, force=False): |     def push(self, force=False): | ||||||
|         remo = self.repo.remotes["origin"] |         if "origin" not in self.git_run( | ||||||
|  |             ["remote"], | ||||||
|  |             stdout=subprocess.PIPE, | ||||||
|  |         ).stdout.decode("utf-8"): | ||||||
|  |             logger.warning("Not pushing to remote because no 'origin' configured") | ||||||
|  |             return | ||||||
|  |  | ||||||
|         keypair = pygit2.KeypairFromAgent("gitea") |         cmd = ["push"] | ||||||
|         callbacks = pygit2.RemoteCallbacks(credentials=keypair) |  | ||||||
|  |  | ||||||
|         refspecs = ["refs/heads/factory"] |  | ||||||
|         develspec = "refs/heads/devel" |  | ||||||
|         if develspec in self.repo.references: |  | ||||||
|         if force: |         if force: | ||||||
|                 refspecs.append(f"+{develspec}:{develspec}") |             cmd.append("-f") | ||||||
|             else: |         cmd.append("origin") | ||||||
|                 refspecs.append("{develspec}:{develspec}") |         cmd.append("refs/heads/factory") | ||||||
|         remo.push(refspecs, callbacks=callbacks) |         cmd.append("refs/heads/devel") | ||||||
|  |         self.git_run(cmd) | ||||||
|   | |||||||
| @@ -40,9 +40,9 @@ class GitExporter: | |||||||
|     def check_repo_state(self, flats, branch_state): |     def check_repo_state(self, flats, branch_state): | ||||||
|         state_data = dict() |         state_data = dict() | ||||||
|         if os.path.exists(self.state_file): |         if os.path.exists(self.state_file): | ||||||
|             with open(self.state_file, "r") as f: |             with open(self.state_file) as f: | ||||||
|                 state_data = yaml.safe_load(f) |                 state_data = yaml.safe_load(f) | ||||||
|                 if type(state_data) != dict: |                 if not isinstance(state_data, dict): | ||||||
|                     state_data = {} |                     state_data = {} | ||||||
|         left_to_commit = [] |         left_to_commit = [] | ||||||
|         for flat in reversed(flats): |         for flat in reversed(flats): | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import concurrent.futures |  | ||||||
| import logging | import logging | ||||||
|  | import pathlib | ||||||
| import xml.etree.ElementTree as ET | import xml.etree.ElementTree as ET | ||||||
|  |  | ||||||
| from lib.db import DB | from lib.db import DB | ||||||
| @@ -31,6 +31,7 @@ class Importer: | |||||||
|         self.obs = OBS(api_url) |         self.obs = OBS(api_url) | ||||||
|         assert project == "openSUSE:Factory" |         assert project == "openSUSE:Factory" | ||||||
|         self.refreshed_packages = set() |         self.refreshed_packages = set() | ||||||
|  |         self.gone_packages_set = None | ||||||
|  |  | ||||||
|     def import_request(self, number): |     def import_request(self, number): | ||||||
|         self.obs.request(number).import_into_db(self.db) |         self.obs.request(number).import_into_db(self.db) | ||||||
| @@ -161,10 +162,12 @@ class Importer: | |||||||
|                 (rev.dbid, linked.dbid), |                 (rev.dbid, linked.dbid), | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|     def revisions_without_files(self): |     def revisions_without_files(self, package): | ||||||
|  |         logging.debug(f"revisions_without_files({package})") | ||||||
|         with self.db.cursor() as cur: |         with self.db.cursor() as cur: | ||||||
|             cur.execute( |             cur.execute( | ||||||
|                 "SELECT * FROM revisions WHERE broken=FALSE AND expanded_srcmd5 IS NULL" |                 "SELECT * FROM revisions WHERE package=%s AND broken=FALSE AND expanded_srcmd5 IS NULL", | ||||||
|  |                 (package,), | ||||||
|             ) |             ) | ||||||
|             return [DBRevision(self.db, row) for row in cur.fetchall()] |             return [DBRevision(self.db, row) for row in cur.fetchall()] | ||||||
|  |  | ||||||
| @@ -178,11 +181,11 @@ class Importer: | |||||||
|             linked_rev = cur.fetchone() |             linked_rev = cur.fetchone() | ||||||
|         if linked_rev: |         if linked_rev: | ||||||
|             linked_rev = linked_rev[0] |             linked_rev = linked_rev[0] | ||||||
|         list = self.obs.list( |         obs_dir_list = self.obs.list( | ||||||
|             rev.project, rev.package, rev.unexpanded_srcmd5, linked_rev |             rev.project, rev.package, rev.unexpanded_srcmd5, linked_rev | ||||||
|         ) |         ) | ||||||
|         if list: |         if obs_dir_list: | ||||||
|             rev.import_dir_list(list) |             rev.import_dir_list(obs_dir_list) | ||||||
|             md5 = rev.calculate_files_hash() |             md5 = rev.calculate_files_hash() | ||||||
|             with self.db.cursor() as cur: |             with self.db.cursor() as cur: | ||||||
|                 cur.execute( |                 cur.execute( | ||||||
| @@ -196,39 +199,31 @@ class Importer: | |||||||
|         self.find_linked_revs() |         self.find_linked_revs() | ||||||
|  |  | ||||||
|         self.find_fake_revisions() |         self.find_fake_revisions() | ||||||
|         with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: |         for package in self.packages: | ||||||
|             fs = [ |             for rev in self.revisions_without_files(package): | ||||||
|                 executor.submit(import_rev, self, rev) |                 print(f"rev {rev} is without files") | ||||||
|                 for rev in self.revisions_without_files() |                 self.import_rev(rev) | ||||||
|             ] |  | ||||||
|         concurrent.futures.wait(fs) |  | ||||||
|  |  | ||||||
|     def refresh_package(self, project, package): |     def refresh_package(self, project, package): | ||||||
|         key = f"{project}/{package}" |         key = f"{project}/{package}" | ||||||
|         if key in self.refreshed_packages: |         if key in self.refreshed_packages: | ||||||
|             # refreshing once is good enough |             # refreshing once is good enough | ||||||
|             return |             return | ||||||
|  |         if self.package_gone(key): | ||||||
|  |             return | ||||||
|         logging.debug(f"Refresh {project}/{package}") |         logging.debug(f"Refresh {project}/{package}") | ||||||
|         self.refreshed_packages.add(key) |         self.refreshed_packages.add(key) | ||||||
|         self.update_db_package(project, package) |         self.update_db_package(project, package) | ||||||
|         self.fetch_all_linked_packages(project, package) |         self.fetch_all_linked_packages(project, package) | ||||||
|  |  | ||||||
|     def import_into_db(self): |     def import_into_db(self): | ||||||
|  |         for package in self.packages: | ||||||
|         with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: |             refresh_package(self, self.project, package) | ||||||
|             fs = [ |  | ||||||
|                 executor.submit(refresh_package, self, self.project, package) |  | ||||||
|                 for package in self.packages |  | ||||||
|             ] |  | ||||||
|             concurrent.futures.wait(fs) |  | ||||||
|  |  | ||||||
|         self.db.conn.commit() |         self.db.conn.commit() | ||||||
|  |  | ||||||
|             fs = [ |         for number in DBRevision.requests_to_fetch(self.db): | ||||||
|                 executor.submit(import_request, self, number) |             self.import_request(number) | ||||||
|                 for number in DBRevision.requests_to_fetch(self.db) |  | ||||||
|             ] |  | ||||||
|             concurrent.futures.wait(fs) |  | ||||||
|  |  | ||||||
|         self.db.conn.commit() |         self.db.conn.commit() | ||||||
|  |  | ||||||
| @@ -238,11 +233,9 @@ class Importer: | |||||||
|                         WHERE id IN (SELECT request_id FROM revisions WHERE project=%s and package = ANY(%s));""", |                         WHERE id IN (SELECT request_id FROM revisions WHERE project=%s and package = ANY(%s));""", | ||||||
|                 (self.project, self.packages), |                 (self.project, self.packages), | ||||||
|             ) |             ) | ||||||
|                 fs = [ |             for project, package in cur.fetchall(): | ||||||
|                     executor.submit(refresh_package, self, project, package) |                 self.refresh_package(project, package) | ||||||
|                     for project, package in cur.fetchall() |  | ||||||
|                 ] |  | ||||||
|                 concurrent.futures.wait(fs) |  | ||||||
|         self.db.conn.commit() |         self.db.conn.commit() | ||||||
|  |  | ||||||
|         missing_users = User.missing_users(self.db) |         missing_users = User.missing_users(self.db) | ||||||
| @@ -254,3 +247,11 @@ class Importer: | |||||||
|  |  | ||||||
|         self.fill_file_lists() |         self.fill_file_lists() | ||||||
|         self.db.conn.commit() |         self.db.conn.commit() | ||||||
|  |  | ||||||
|  |     def package_gone(self, key): | ||||||
|  |         if not self.gone_packages_set: | ||||||
|  |             self.gone_packages_set = set() | ||||||
|  |             with open(pathlib.Path(__file__).parent.parent / "gone-packages.txt") as f: | ||||||
|  |                 for line in f.readlines(): | ||||||
|  |                     self.gone_packages_set.add(line.strip()) | ||||||
|  |         return key in self.gone_packages_set | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ class LFSOid: | |||||||
|             self.register() |             self.register() | ||||||
|  |  | ||||||
|     def check(self): |     def check(self): | ||||||
|         url = f"http://gitea.opensuse.org:9999/check/{self.sha256}/{self.size}" |         url = f"http://localhost:9999/check/{self.sha256}/{self.size}" | ||||||
|         response = requests.get( |         response = requests.get( | ||||||
|             url, |             url, | ||||||
|             timeout=10, |             timeout=10, | ||||||
| @@ -127,12 +127,13 @@ class LFSOid: | |||||||
|             "size": self.size, |             "size": self.size, | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         url = "http://gitea.opensuse.org:9999/register" |         url = "http://localhost:9999/register" | ||||||
|         response = requests.post( |         response = requests.post( | ||||||
|             url, |             url, | ||||||
|             json=data, |             json=data, | ||||||
|             timeout=10, |             timeout=10, | ||||||
|         ) |         ) | ||||||
|  |         response.raise_for_status() | ||||||
|         logging.info(f"Register LFS returned {response.status_code}") |         logging.info(f"Register LFS returned {response.status_code}") | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -150,7 +150,7 @@ class OBS: | |||||||
|     def _download(self, project, package, name, revision): |     def _download(self, project, package, name, revision): | ||||||
|         url = osc.core.makeurl( |         url = osc.core.makeurl( | ||||||
|             self.url, |             self.url, | ||||||
|             ["source", project, package, urllib.parse.quote(name)], |             ["source", project, package, name], | ||||||
|             {"rev": revision, "expand": 1}, |             {"rev": revision, "expand": 1}, | ||||||
|         ) |         ) | ||||||
|         return osc.core.http_GET(url) |         return osc.core.http_GET(url) | ||||||
| @@ -165,7 +165,6 @@ class OBS: | |||||||
|         cachedir: str, |         cachedir: str, | ||||||
|         file_md5: str, |         file_md5: str, | ||||||
|     ) -> None: |     ) -> None: | ||||||
|  |  | ||||||
|         cached_file = self._path_from_md5(name, cachedir, file_md5) |         cached_file = self._path_from_md5(name, cachedir, file_md5) | ||||||
|         if not self.in_cache(name, cachedir, file_md5): |         if not self.in_cache(name, cachedir, file_md5): | ||||||
|             with (dirpath / name).open("wb") as f: |             with (dirpath / name).open("wb") as f: | ||||||
|   | |||||||
| @@ -7,8 +7,6 @@ except: | |||||||
|     print("Install python3-python-magic, not python3-magic") |     print("Install python3-python-magic, not python3-magic") | ||||||
|     raise |     raise | ||||||
|  |  | ||||||
| import requests |  | ||||||
|  |  | ||||||
| from lib.db import DB | from lib.db import DB | ||||||
| from lib.lfs_oid import LFSOid | from lib.lfs_oid import LFSOid | ||||||
| from lib.obs import OBS | from lib.obs import OBS | ||||||
| @@ -43,7 +41,6 @@ class ProxySHA256: | |||||||
|             } |             } | ||||||
|  |  | ||||||
|     def put(self, project, package, name, revision, file_md5, size): |     def put(self, project, package, name, revision, file_md5, size): | ||||||
|  |  | ||||||
|         if not self.mime: |         if not self.mime: | ||||||
|             self.mime = magic.Magic(mime=True) |             self.mime = magic.Magic(mime=True) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| from typing import Dict |  | ||||||
| from xmlrpc.client import Boolean | from xmlrpc.client import Boolean | ||||||
|  |  | ||||||
| from lib.db_revision import DBRevision | from lib.db_revision import DBRevision | ||||||
| @@ -114,7 +113,7 @@ class TreeBuilder: | |||||||
|                 candidates.append(node) |                 candidates.append(node) | ||||||
|             if node.merged_into: |             if node.merged_into: | ||||||
|                 # we can't have candidates that are crossing previous merges |                 # we can't have candidates that are crossing previous merges | ||||||
|                 # see https://gitea.opensuse.org/importers/git-importer/issues/14 |                 # see https://src.opensuse.org/importers/git-importer/issues/14 | ||||||
|                 candidates = [] |                 candidates = [] | ||||||
|             node = node.parent |             node = node.parent | ||||||
|         if candidates: |         if candidates: | ||||||
| @@ -138,7 +137,7 @@ class TreeBuilder: | |||||||
|                 self.requests.add(node.revision.request_id) |                 self.requests.add(node.revision.request_id) | ||||||
|  |  | ||||||
|         class FindMergeWalker(AbstractWalker): |         class FindMergeWalker(AbstractWalker): | ||||||
|             def __init__(self, builder: TreeBuilder, requests: Dict) -> None: |             def __init__(self, builder: TreeBuilder, requests: dict) -> None: | ||||||
|                 super().__init__() |                 super().__init__() | ||||||
|                 self.source_revisions = dict() |                 self.source_revisions = dict() | ||||||
|                 self.builder = builder |                 self.builder = builder | ||||||
|   | |||||||
							
								
								
									
										37
									
								
								opensuse-monitor.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										37
									
								
								opensuse-monitor.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,37 @@ | |||||||
|  | #!/usr/bin/python3 | ||||||
|  | import json | ||||||
|  | from pathlib import Path | ||||||
|  | import pika | ||||||
|  | import sys | ||||||
|  |  | ||||||
|  | MY_TASKS_DIR = Path(__file__).parent / "tasks" | ||||||
|  |  | ||||||
|  | connection = pika.BlockingConnection(pika.URLParameters("amqps://opensuse:opensuse@rabbit.opensuse.org")) | ||||||
|  | channel = connection.channel() | ||||||
|  |  | ||||||
|  | channel.exchange_declare(exchange='pubsub', exchange_type='topic', passive=True, durable=True) | ||||||
|  |  | ||||||
|  | result = channel.queue_declare("", exclusive=True) | ||||||
|  | queue_name = result.method.queue | ||||||
|  |  | ||||||
|  | channel.queue_bind(exchange='pubsub', | ||||||
|  |                    queue=queue_name,routing_key='#') | ||||||
|  |  | ||||||
|  | print(' [*] Waiting for logs. To exit press CTRL+C') | ||||||
|  |  | ||||||
|  | def callback(ch, method, properties, body): | ||||||
|  |     if method.routing_key not in ("opensuse.obs.package.commit",): | ||||||
|  |         return | ||||||
|  |     body = json.loads(body) | ||||||
|  |     if 'project' in body and 'package' in body and body['project'] == 'openSUSE:Factory': | ||||||
|  |         if '/' in body['package']: | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         (MY_TASKS_DIR / body['package']).touch() | ||||||
|  |         print(" [x] %r:%r" % (method.routing_key, body['package'])) | ||||||
|  |  | ||||||
|  | channel.basic_consume(queue_name, | ||||||
|  |                       callback, | ||||||
|  |                       auto_ack=True) | ||||||
|  |  | ||||||
|  | channel.start_consuming() | ||||||
							
								
								
									
										1
									
								
								tasks/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tasks/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | * | ||||||
		Reference in New Issue
	
	Block a user