Created
July 22, 2021 09:11
-
-
Save sritasngh/62875ee17cfce466ab50a13d0bddd187 to your computer and use it in GitHub Desktop.
scancode UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/***************************************************************************** | |
* SPDX-License-Identifier: GPL-2.0 | |
* SPDX-FileCopyrightText: 2021 Sarita Singh <[email protected]> | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License | |
* version 2 as published by the Free Software Foundation. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License along | |
* with this program; if not, write to the Free Software Foundation, Inc., | |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
****************************************************************************/ | |
namespace Fossology\Scancode\Ui; | |
use Symfony\Component\HttpFoundation\Request; | |
use Fossology\Lib\Plugin\AgentPlugin; | |
class ScancodesAgentPlugin extends AgentPlugin | |
{ | |
const RULES_FLAG = "-r"; | |
public function __construct() { | |
$this->Name = "agent_scancode"; | |
$this->Title = _("Scancode Toolkit"); | |
$this->AgentName = "scancode"; | |
parent::__construct(); | |
} | |
/** | |
* @brief Render HTML from template | |
* @param array $vars Variables using in template | |
* @return string HTML rendered from agent_decider.html.twig template | |
*/ | |
public function renderContent(&$vars) | |
{ | |
$renderer = $GLOBALS['container']->get('twig.environment'); | |
return $renderer->loadTemplate('scancode.html.twig')->render($vars); | |
} | |
/** | |
* @brief Render footer HTML | |
* @param array $vars Variables using in template | |
* @return string Footer HTML | |
*/ | |
public function renderFoot(&$vars) | |
{ | |
return ""; | |
} | |
// l-> license | |
// c-> copyright | |
// e-> email | |
// u-> url | |
/** | |
* @brief Schedule decider agent | |
* @param int $jobId | |
* @param int $uploadId | |
* @param string $errorMsg | |
* @param Request $request Session request | |
* @return string | |
*/ | |
public function scheduleAgent($jobId, $uploadId, &$errorMsg, $request) | |
{ | |
$flags = $request->get('scancodeFlags') ?: array(); | |
$scanMode = array(); | |
foreach ($flags as $flag) { | |
switch ($flag) { | |
case "license": | |
$scanMode[]='l'; | |
break; | |
case "copyright": | |
$scanMode[]='c'; | |
break; | |
case "email": | |
$scanMode[]='e'; | |
break; | |
case "url": | |
$scanMode[]='u'; | |
break; | |
} | |
} | |
if (empty($scanMode)) { | |
return 0; | |
} | |
return | |
} | |
function AgentHasResults($uploadId=0) | |
{ | |
return CheckARS($uploadId, $this->AgentName, "scancode agent", "scancode_ars"); | |
} | |
/** | |
* @copydoc Fossology\Lib\Plugin\AgentPlugin::AgentAdd() | |
* @see \Fossology\Lib\Plugin\AgentPlugin::AgentAdd() | |
*/ | |
public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=array(), $arguments=null) | |
{ | |
$unpackArgs = intval(@$_POST['scm']) == 1 ? '-I' : ''; | |
if ($this->AgentHasResults($uploadId) == 1) { | |
return 0; | |
} | |
$jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId); | |
if ($jobQueueId != 0) { | |
return $jobQueueId; | |
} | |
$args = $unpackArgs; | |
if (!empty($unpackArgs)) { | |
return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_mimetype"),$uploadId,$args); | |
} else { | |
return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_adj2nest"), $uploadId); | |
} | |
} | |
/** | |
* Check if agent already included in the dependency list | |
* @param mixed $dependencies Array of job dependencies | |
* @param string $agentName Name of the agent to be checked for | |
* @return boolean true if agent already in dependency list else false | |
*/ | |
protected function isAgentIncluded($dependencies, $agentName) | |
{ | |
foreach ($dependencies as $dependency) { | |
if ($dependency == $agentName) { | |
return true; | |
} | |
if (is_array($dependency) && $agentName == $dependency['name']) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* @copydoc Fossology::Lib::Plugin::AgentPlugin::preInstall() | |
* @see Fossology::Lib::Plugin::AgentPlugin::preInstall() | |
*/ | |
public function preInstall() | |
{ | |
menu_insert("ParmAgents::" . $this->Title, 0, $this->Name); | |
} | |
} | |
register_plugin(new ScancodesAgentPlugin()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# SPDX-License-Identifier: GPL-2.0 | |
# SPDX-FileCopyrightText: 2021 Sarita Singh <[email protected]> | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# version 2 as published by the Free Software Foundation. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License along | |
# with this program; if not, write to the Free Software Foundation, Inc., | |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
############################################################################## | |
TOP = ../../.. | |
VARS = $(TOP)/Makefile.conf | |
include $(VARS) | |
MOD_NAME = scancode | |
MOD_SUBDIR = ui | |
all: | |
@echo "nothing to do" | |
install: | |
mkdir -p $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR) | |
$(INSTALL_DATA) ./*.php $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR) | |
find template/ -type f -exec $(INSTALL_DATA) {} $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR)/{} \; | |
uninstall: | |
rm -rf $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR) | |
clean: | |
@echo "nothing to do" | |
.PHONY: all install uninstall clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% import "include/macros.html.twig" as macro %} | |
<li> | |
{{ 'ScanCode Toolkit'|trans }}, | |
{{ 'scan for'|trans }}<br/> | |
<input type="checkbox" name="scancodeFlags[]" value="license" /> {{ 'License'|trans }}<br /> | |
<input type="checkbox" name="scancodeFlags[]" value="copyright" /> {{ 'Copyright'|trans }}<br /> | |
<input type="checkbox" name="scancodeFlags[]" value="email" /> {{ 'Email'|trans }}<br /> | |
<input type="checkbox" name="scancodeFlags[]" value="url" /> {{ 'URL'|trans }} | |
</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* @brief Add the template path of decider twig templates | |
* to twig.loader | |
* @see Twig_Loader_Filesystem | |
*/ | |
$loader = $GLOBALS['container']->get('twig.loader'); | |
$loader->addPath(dirname(__FILE__).'/template'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment