Commit 9466df9d authored by Celine Noirot's avatar Celine Noirot
Browse files

add purge prototype to test web interface

parent 9b46a37c
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
from ng6.ng6workflow import DownloadWorkflow
from ng6.config_reader import NG6ConfigReader
class PurgeDemand (DownloadWorkflow):
def get_description(self):
return """This workflow allows you to purge files on the server.
Please be carefull that the provided user must have write permission on the ng6 data directory on the server."""
def define_parameters(self, function="process"):
config = NG6ConfigReader()
self.add_parameter('username', 'A valid user username on the server', type = "localuser" ,required = True)
self.add_parameter('password', 'The connection password for the username on the server', type="password", required = True)
self.add_parameter_list('demand', "The demand ids.",
required = True)
def process(self):
self.add_component('PurgeDemand', [self.username, self.password, self.demand])
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
\ No newline at end of file
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
import os
import pickle
from jflow.component import Component
def remove_files (output_list, user_script, username, password , ids):
import os
import pickle
import subprocess
from ng6.config_reader import NG6ConfigReader
from ng6.utils import Utils, SSH
from jflow.parameter import PasswordParameter
config = NG6ConfigReader()
data_folder = config.get_save_directory()
password = PasswordParameter.decrypt(password)
try:
#src_directories, dest_directories = Utils.get_directories_structure_and_content(ng6_username, data_folder, output_folder, prefixed_ids)
destinations = []
with open(user_script, "w") as us:
with open(output_list, "w") as ol :
for i, purge_id in enumerate(ids.split(",")):
ol.write("purge_id "+purge_id +"\n")
#ol.write(dest_file_path+"\n")
# execution of the script as the user
server_params = config.get_server_parameters()
s = SSH(username, password, server_params[0])
#s.cmd('bash %s'%user_script)
except Exception as e:
raise Exception('Unable to remove files : %s'%e)
class PurgeDemand (Component):
def define_parameters(self, username, password, demand_ids, data_ids = [], run_ids = [], analysis_ids = [], login = None):
self.add_parameter('username', 'Valid username on the server', required = True, default = username)
self.add_parameter('password', 'A password for the usernmae on the server', required = True, default = password, type = "password")
self.add_parameter_list('demand_ids', 'Ids of a demand from which data will be remove', default = demand_ids)
self.add_output_file( 'output_list', 'output_list', filename = "remove_list.txt")
def process(self):
userscript=self.get_temporary_file(".sh")
self.add_python_execution(remove_files, cmd_format = "{EXE} {OUT} {ARG} ",
arguments = [ self.username, self.password, ','.join(self.demand_ids)],
outputs = [self.output_list,userscript], local = True)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment