[aur-dev] [PATCH 1/2] Store {make, check, opt}depends in the database

William Giokas 1007380 at gmail.com
Thu Apr 17 15:33:47 EDT 2014


On Thu, Apr 17, 2014 at 09:13:34PM +0200, Lukas Fleischer wrote:
> In addition to parsing and storing dependencies of packages, store
> makedepends, checkdepends and optdepends. Every dependency (of any type)
> is displayed on the package details page.

So I'm not sure how it's all set up, but if this can be pulled via the
api, then that would be amazing. Would really clean up a bunch of AUR
helpers out there. I know pywer has some terrible bash parsing to try
and get the depends and optdepends from the actual PKGBUILD file, which
is extremely unreliable.

> 
> Signed-off-by: Lukas Fleischer <archlinux at cryptocrack.de>
> ---
>  UPGRADING                | 23 +++++++++++++++++++++++
>  schema/aur-schema.sql    | 17 ++++++++++++++++-
>  schema/gendummydata.py   |  9 ++++++---
>  web/html/pkgsubmit.php   | 36 ++++++++++++++++++++++--------------
>  web/lib/pkgfuncs.inc.php | 29 +++++++++++++++++++++++------
>  5 files changed, 90 insertions(+), 24 deletions(-)
> 
> diff --git a/UPGRADING b/UPGRADING
> index a33ea63..48737f2 100644
> --- a/UPGRADING
> +++ b/UPGRADING
> @@ -142,6 +142,29 @@ CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageBaseID
>  CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PackageBaseID);
>  ----
>  
> +12. Create a new table to store package dependency types:
> +
> +----
> +CREATE TABLE DependencyTypes (
> +	ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
> +	Name VARCHAR(32) NOT NULL DEFAULT '',
> +	PRIMARY KEY (ID)
> +) ENGINE = InnoDB;
> +INSERT INTO DependencyTypes VALUES (1, 'depends');
> +INSERT INTO DependencyTypes VALUES (2, 'makedepends');
> +INSERT INTO DependencyTypes VALUES (3, 'checkdepends');
> +INSERT INTO DependencyTypes VALUES (4, 'optdepends');
> +----
> +
> +13. Add a field to store the dependency type to the PackageDepends table:
> +
> +----
> +ALTER TABLE PackageDepends ADD COLUMN DepTypeID TINYINT UNSIGNED NOT NULL;
> +UPDATE PackageDepends SET DepTypeID = 1;
> +ALTER TABLE PackageDepends
> +	ADD FOREIGN KEY (DepTypeID) REFERENCES DependencyTypes(ID) ON DELETE NO ACTION;
> +----
> +
>  From 2.2.0 to 2.3.0
>  -------------------
>  
> diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql
> index 9426a61..327a792 100644
> --- a/schema/aur-schema.sql
> +++ b/schema/aur-schema.sql
> @@ -133,15 +133,30 @@ CREATE TABLE Packages (
>  ) ENGINE = InnoDB;
>  
>  
> +-- Define the package dependency types
> +--
> +CREATE TABLE DependencyTypes (
> +	ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
> +	Name VARCHAR(32) NOT NULL DEFAULT '',
> +	PRIMARY KEY (ID)
> +) ENGINE = InnoDB;
> +INSERT INTO DependencyTypes VALUES (1, 'depends');
> +INSERT INTO DependencyTypes VALUES (2, 'makedepends');
> +INSERT INTO DependencyTypes VALUES (3, 'checkdepends');
> +INSERT INTO DependencyTypes VALUES (4, 'optdepends');
> +
> +
>  -- Track which dependencies a package has
>  --
>  CREATE TABLE PackageDepends (
>  	PackageID INTEGER UNSIGNED NOT NULL,
> +	DepTypeID TINYINT UNSIGNED NOT NULL,
>  	DepName VARCHAR(64) NOT NULL,
>  	DepCondition VARCHAR(20),
>  	INDEX (PackageID),
>  	INDEX (DepName),
> -	FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE
> +	FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE,
> +	FOREIGN KEY (DepTypeID) REFERENCES DependencyTypes(ID) ON DELETE NO ACTION
>  ) ENGINE = InnoDB;
>  
>  
> diff --git a/schema/gendummydata.py b/schema/gendummydata.py
> index bc0ede8..18852a2 100755
> --- a/schema/gendummydata.py
> +++ b/schema/gendummydata.py
> @@ -28,7 +28,7 @@ MAX_USERS = 300        # how many users to 'register'
>  MAX_DEVS  = .1         # what percentage of MAX_USERS are Developers
>  MAX_TUS   = .2         # what percentage of MAX_USERS are Trusted Users
>  MAX_PKGS  = 900       # how many packages to load
> -PKG_DEPS  = (1, 5)     # min/max depends a package has
> +PKG_DEPS  = (1, 15)    # min/max depends a package has
>  PKG_SRC   = (1, 3)     # min/max sources a package has
>  PKG_CMNTS = (1, 5)     # min/max number of comments a package has
>  CATEGORIES_COUNT = 17  # the number of categories from aur-schema
> @@ -258,8 +258,11 @@ for p in list(seen_pkgs.keys()):
>  	while i != num_deps:
>  		dep = random.choice([k for k in seen_pkgs])
>  		if dep not in this_deps:
> -			s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n"
> -			s = s % (seen_pkgs[p], dep)
> +			deptype = random.randrange(1, 5)
> +			if deptype == 4:
> +				dep += ": for " + random.choice([k for k in seen_pkgs])
> +			s = "INSERT INTO PackageDepends VALUES (%d, %d, '%s', NULL);\n"
> +			s = s % (seen_pkgs[p], deptype, dep)
>  			out.write(s)
>  			i += 1
>  
> diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php
> index 7db81a5..045b8f9 100644
> --- a/web/html/pkgsubmit.php
> +++ b/web/html/pkgsubmit.php
> @@ -150,7 +150,13 @@ if ($uid):
>  						$pkginfo[] = array_merge($pkgbase_info, $section_info);
>  					}
>  				}
> -				$section_info = array('depends' => array(), 'source' => array());
> +				$section_info = array(
> +					'depends' => array(),
> +					'makedepends' => array(),
> +					'checkdepends' => array(),
> +					'optdepends' => array(),
> +					'source' => array()
> +				);
>  				/* Fall-through case. */
>  			case 'epoch':
>  			case 'pkgdesc':
> @@ -162,6 +168,9 @@ if ($uid):
>  				break;
>  			case 'source':
>  			case 'depends':
> +			case 'makedepends':
> +			case 'checkdepends':
> +			case 'optdepends':
>  				$section_info[$key][] = $value;
>  				break;
>  			}
> @@ -181,15 +190,12 @@ if ($uid):
>  			if (!isset($pkgbase_info['pkgbase'])) {
>  				$pkgbase_info['pkgbase'] = $pkgbase_info['pkgname'];
>  			}
> -			if (empty($pkgbase_info['depends'])) {
> -				$pkgbase_info['depends'] = array();
> -			} else {
> -				$pkgbase_info['depends'] = explode(" ", $pkgbase_info['depends']);
> -			}
> -			if (empty($pkgbase_info['source'])) {
> -				$pkgbase_info['source'] = array();
> -			} else {
> -				$pkgbase_info['source'] = explode(" ", $pkgbase_info['source']);
> +			foreach (array('source', 'depends', 'makedepends', 'checkdepends', 'optdepends') as $array_opt) {
> +				if (empty($pkgbase_info[$array_opt])) {
> +					$pkgbase_info[$array_opt] = array();
> +				} else {
> +					$pkgbase_info[$array_opt] = explode(" ", $pkgbase_info[$array_opt]);
> +				}
>  			}
>  			$pkginfo[] = $pkgbase_info;
>  		}
> @@ -345,10 +351,12 @@ if ($uid):
>  			foreach ($pkginfo as $pi) {
>  				$pkgid = pkg_create($base_id, $pi['pkgname'], $pi['license'], $pi['full-version'], $pi['pkgdesc'], $pi['url']);
>  
> -				foreach ($pi['depends'] as $dep) {
> -					$deppkgname = preg_replace("/(<|=|>).*/", "", $dep);
> -					$depcondition = str_replace($deppkgname, "", $dep);
> -					pkg_add_dep($pkgid, $deppkgname, $depcondition);
> +				foreach (array('depends', 'makedepends', 'checkdepends', 'optdepends') as $deptype) {
> +					foreach ($pi[$deptype] as $dep) {
> +						$deppkgname = preg_replace("/(<|=|>).*/", "", $dep);
> +						$depcondition = str_replace($deppkgname, "", $dep);
> +						pkg_add_dep($pkgid, $deptype, $deppkgname, $depcondition);
> +					}
>  				}
>  
>  				foreach ($pi['source'] as $src) {
> diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
> index c6b4a27..153e2a8 100644
> --- a/web/lib/pkgfuncs.inc.php
> +++ b/web/lib/pkgfuncs.inc.php
> @@ -132,6 +132,21 @@ function pkg_dependencies($pkgid) {
>  }
>  
>  /**
> + * Get the ID of a dependency type given its name
> + *
> + * @param string $name The name of the dependency type
> + *
> + * @return int The ID of the dependency type
> + */
> +function pkg_dependency_type_id_from_name($name) {
> +	$dbh = DB::connect();
> +	$q = "SELECT ID FROM DependencyTypes WHERE Name = ";
> +	$q.= $dbh->quote($name);
> +	$result = $dbh->query($q);
> +	return $result->fetch(PDO::FETCH_COLUMN, 0);
> +}
> +
> +/**
>   * Determine packages that depend on a package
>   *
>   * @param string $name The package name for the dependency search
> @@ -653,18 +668,20 @@ function pkg_create($base_id, $pkgname, $license, $pkgver, $pkgdesc, $pkgurl) {
>   * Add a dependency for a specific package to the database
>   *
>   * @param int $pkgid The package ID to add the dependency for
> + * @param string $type The type of dependency to add
>   * @param string $depname The name of the dependency to add
>   * @param string $depcondition The  type of dependency for the package
>   *
>   * @return void
>   */
> -function pkg_add_dep($pkgid, $depname, $depcondition) {
> +function pkg_add_dep($pkgid, $type, $depname, $depcondition) {
>  	$dbh = DB::connect();
> -	$q = sprintf("INSERT INTO PackageDepends (PackageID, DepName, DepCondition) VALUES (%d, %s, %s)",
> -	$pkgid,
> -	$dbh->quote($depname),
> -	$dbh->quote($depcondition));
> -
> +	$q = sprintf("INSERT INTO PackageDepends (PackageID, DepTypeID, DepName, DepCondition) VALUES (%d, %d, %s, %s)",
> +		$pkgid,
> +		pkg_dependency_type_id_from_name($type),
> +		$dbh->quote($depname),
> +		$dbh->quote($depcondition)
> +	);
>  	$dbh->exec($q);
>  }
>  
> -- 
> 1.9.2
> 

-- 
William Giokas | KaiSforza | http://kaictl.net/
GnuPG Key: 0x73CD09CF
Fingerprint: F73F 50EF BBE2 9846 8306  E6B8 6902 06D8 73CD 09CF
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mailman.archlinux.org/pipermail/aur-dev/attachments/20140417/c4d1620a/attachment.asc>


More information about the aur-dev mailing list