FOSSology  3.2.0rc1
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  Copyright (C) 2013-2014 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
27 $PREFIX = "/usr/local/";
28 require_once("$PREFIX/share/fossology/lib/php/common.php");
29 $sysconfig = "$PREFIX/etc/fossology/";
30 
31 $AllPossibleOpts = "nrh";
32 $reference_flag = 0; // 1: include; 0: exclude
33 $nomos_flag = 0; // 1: include; 0: exclude
34 
35 /* command-line options */
36 $Options = getopt($AllPossibleOpts);
37 foreach($Options as $Option => $OptVal)
38 {
39  switch($Option)
40  {
41  case 'n': /* list license from nomos */
42  $nomos_flag = 1;
43  break;
44  case 'r': /* list license from reference */
45  $reference_flag = 1;
46  break;
47  case 'h': /* help */
48  Usage();
49  default:
50  echo "Invalid Option \"$Option\".\n";
51  Usage();
52  }
53 }
54 
56 if (0 == $reference_flag && 0 == $nomos_flag)
57 {
58  $reference_flag = 1;
59  $nomos_flag = 1;
60 }
61 
62 $PG_CONN = DBconnect($sysconfig);
63 list_license($reference_flag, $nomos_flag);
64 
65 function list_license($reference_flag, $nomos_flag)
66 {
67  global $PG_CONN;
68  $sql_statment = "SELECT rf_shortname from license_ref ";
69  if ($reference_flag && $nomos_flag) ;
70  else if ($reference_flag) $sql_statment .= " where rf_detector_type = 1";
71  else if ($nomos_flag) $sql_statment .= " where rf_detector_type = 2";
72  $sql_statment .= " order by rf_shortname";
73  $result = pg_query($PG_CONN, $sql_statment);
74  DBCheckResult($result, $sql_statment, __FILE__, __LINE__);
75  while ($row = pg_fetch_assoc($result))
76  {
77  print $row['rf_shortname']."\n";
78  }
79  pg_free_result($result);
80 }
81 
85 function Usage()
86 {
87  global $argv;
88 
89  $usage = "Usage: " . basename($argv[0]) . " [options]
90  List licenses fossology support. Options are:
91  -n licenses are just from nomos
92  -r licenses are just from reference
93  -h this help usage
94  default will list all licenses fossology support";
95  print "$usage\n";
96  exit(0);
97 }
98 ?>
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:44
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198