FOSSology  4.4.0
Open Source License Compliance by Open Source Software
list_license.php
Go to the documentation of this file.
1 #!/usr/bin/php -q
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2013-2014 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
15 $PREFIX = "/usr/local/";
16 require_once("$PREFIX/share/fossology/lib/php/common.php");
17 $sysconfig = "$PREFIX/etc/fossology/";
18 
19 $AllPossibleOpts = "nrh";
20 $reference_flag = 0; // 1: include; 0: exclude
21 $nomos_flag = 0; // 1: include; 0: exclude
22 
23 /* command-line options */
24 $Options = getopt($AllPossibleOpts);
25 foreach($Options as $Option => $OptVal)
26 {
27  switch($Option)
28  {
29  case 'n': /* list license from nomos */
30  $nomos_flag = 1;
31  break;
32  case 'r': /* list license from reference */
33  $reference_flag = 1;
34  break;
35  case 'h': /* help */
36  Usage();
37  default:
38  echo "Invalid Option \"$Option\".\n";
39  Usage();
40  }
41 }
42 
44 if (0 == $reference_flag && 0 == $nomos_flag)
45 {
46  $reference_flag = 1;
47  $nomos_flag = 1;
48 }
49 
50 $PG_CONN = DBconnect($sysconfig);
51 list_license($reference_flag, $nomos_flag);
52 
53 function list_license($reference_flag, $nomos_flag)
54 {
55  global $PG_CONN;
56  $sql_statment = "SELECT rf_shortname from license_ref ";
57  if ($reference_flag && $nomos_flag) ;
58  else if ($reference_flag) $sql_statment .= " where rf_detector_type = 1";
59  else if ($nomos_flag) $sql_statment .= " where rf_detector_type = 2";
60  $sql_statment .= " order by rf_shortname";
61  $result = pg_query($PG_CONN, $sql_statment);
62  DBCheckResult($result, $sql_statment, __FILE__, __LINE__);
63  while ($row = pg_fetch_assoc($result))
64  {
65  print $row['rf_shortname']."\n";
66  }
67  pg_free_result($result);
68 }
69 
73 function Usage()
74 {
75  global $argv;
76 
77  $usage = "Usage: " . basename($argv[0]) . " [options]
78  List licenses fossology support. Options are:
79  -n licenses are just from nomos
80  -r licenses are just from reference
81  -h this help usage
82  default will list all licenses fossology support";
83  print "$usage\n";
84  exit(0);
85 }
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
Definition: common-db.php:33
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN