Unverified Commit 30d0e7ed authored by CHARLES's avatar CHARLES 🐧
Browse files

Removed elementtree dependency

parent 81eb96b0
......@@ -7,10 +7,10 @@
__docformat__ = 'epytext'
from elementtree import ElementTree
from xml.etree.ElementTree import ElementTree
import logging
from downloader_django.common.system.tasks import write_content_file
class XMLWriter(object):
......@@ -37,14 +37,14 @@ class XMLWriter(object):
except Exception:
#raise "Error during xml writing (file : %s)" % file
raise
def __indent(self, elem, level):
l = ["\n"]
for index in xrange(level):
for index in xrange(level):
l.append(" ")
i = ''.join(l)
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
......@@ -79,8 +79,8 @@ class XMLWriter(object):
def nodeSetText(self, node, text):
node.text = text
def nodeAddAttrib(self, node, key, value):
node.set(key, value)
......@@ -10,7 +10,7 @@ from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext as _
from elementtree.ElementTree import XML
from xml.etree.ElementTree import XML
from lxml.etree import XMLSyntaxError
from multiprocessing import Process, Queue
from downloader_django.apps.downloader_admin.util import downloaderXml, synchro, testFile
......@@ -38,14 +38,14 @@ def desactivate(request, xml_filename):
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
add_test_status(file_map)
if is_success :
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, "tabSelected":"desactivated",'event':"filemovetodesactivated","xml_file_name": xml_filename,}, context_instance=RequestContext(request))
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, "tabSelected":"desactivated",'event':"filemovetodesactivated","xml_file_name": xml_filename,}, context_instance=RequestContext(request))
else:
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, 'error':'desactivate_error' ,"xml_file_name": xml_filename,}, context_instance=RequestContext(request))
#@login_required()
def delete(request, xml_filename):
file_data = downloaderXml.get_xml_data(xml_filename)
download_id=file_data.attrib['id']
download_id=file_data.attrib['id']
is_success = False
#download_path = os.path.join(settings.WORKSPACE_DOWNLOAD, get_workspace_dir_name(download_id))
date = datetime.datetime.utcnow().strftime('%Y%m%d_%H%M%S')
......@@ -54,7 +54,7 @@ def delete(request, xml_filename):
"""
try:
if os.path.isdir(download_path) :
is_success = rename_a_file(download_path, new_path)
else :
is_success = True
......@@ -66,7 +66,7 @@ def delete(request, xml_filename):
error =""
if not is_success:
error="delete_error"
return HttpResponse(error)
return HttpResponse(error)
#@login_required()
def listdownload(request):
......@@ -88,13 +88,13 @@ def modetest(request, xml_filename):
if is_success:
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, 'tabSelected': 'test' ,'event':'filemovetotest','xml_file_name' : xml_filename}, context_instance=RequestContext(request))
else:
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, 'error':'test_error','xml_file_name' : xml_filename}, context_instance=RequestContext(request))
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, 'error':'test_error','xml_file_name' : xml_filename}, context_instance=RequestContext(request))
#@login_required()
def display_download_log(request, download_id):
#data_file = open(os.path.join(settings.LOG_PATH, LOGGER_DEFAULT_FILE_NAME + download_id + '.log'), 'r')
xml_filename = download_id + EXTENSION_ACTIVE
var = RequestContext(request, {'data_file': data_file, 'download_id':download_id, 'xml_filename':xml_filename})
var = RequestContext(request, {'data_file': data_file, 'download_id':download_id, 'xml_filename':xml_filename})
return render_to_response('adminview/viewlog.html', var)
#return HttpResponse(data_file)
......@@ -129,7 +129,7 @@ def editdownload(request, xml_filename):
try:
file_data = downloaderXml.get_xml_data(xml_filename)
return render_to_response(
'adminview/editdownload.html',
'adminview/editdownload.html',
#{ 'file_data': file_data, 'file_name': xml_filename, 'dCheck_config' : dCheck_config, 'error': "" },
{ 'file_data': file_data, 'file_name': xml_filename, 'error': "" },
context_instance=RequestContext(request)
......@@ -139,7 +139,7 @@ def editdownload(request, xml_filename):
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
add_test_status(file_map)
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id, 'error' : error, 'file_name': xml_filename,}, context_instance=RequestContext(request))
except IOError:
# File not found
raise Http404
......@@ -149,7 +149,7 @@ def new(request):
error=""
new_file =request.POST['newfile']
print "new file name : ",new_file
if not new_file:
error="file_error"
xml_file_name_disabled= new_file + EXTENSION_DISABLED
......@@ -160,12 +160,12 @@ def new(request):
if not error:
if not downloaderXml.create_download(xml_file_name_disabled):
error = "file_error"
if not error:
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
add_test_status(file_map)
xml_file_name_disabled= new_file + EXTENSION_DISABLED
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'tabSelected':'desactivated', 'map_file_id' : map_file_id, 'event' : 'filecreated','xml_file_name' : xml_file_name_disabled,}, context_instance=RequestContext(request))
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'tabSelected':'desactivated', 'map_file_id' : map_file_id, 'event' : 'filecreated','xml_file_name' : xml_file_name_disabled,}, context_instance=RequestContext(request))
else :
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
kwvars = {'file_map': file_map, 'map_file_id' : map_file_id, 'tabSelected':'add','file_error':error}
......@@ -179,39 +179,39 @@ def save(request, xml_filename):
except XMLSyntaxError, e:
error = e
return render_to_response(
'adminview/editdownload.html',
'adminview/editdownload.html',
{ 'file_data': file_data[0], 'file_name': xml_filename, 'error': error },
context_instance=RequestContext(request)
)
is_success = downloaderXml.save_download(xml_filename, xml_string)
if is_success :
return HttpResponseRedirect(reverse('dladmin:listdownload'))
else :
return render_to_response(
'adminview/editdownload.html',
'adminview/editdownload.html',
{ 'file_data': file_data[0], 'file_name': xml_filename, 'error': 'save_error' },
context_instance=RequestContext(request)
)
#@login_required()
def define_test_file(request, xml_filename, download_id):
test_file = TestFile(download_id)
def define_test_file(request, xml_filename, download_id):
test_file = TestFile(download_id)
test_file_content=test_file.get_content_test_file()
return HttpResponse(test_file_content)
#@login_required()
def save_test_file(request, xml_filename, download_id):
def save_test_file(request, xml_filename, download_id):
test_filename= request.POST['filename']
test_file = TestFile(download_id)
is_success = test_file.save_content_test_file(test_filename, xml_filename)
#file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
#add_test_status(file_map)
#synchro.add_synchro_status(file_map)
map_test_status = testFile.read_test_status(download_id)
return HttpResponse(map_test_status['State'])
#return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id,"tabSelected":"test"}, context_instance=RequestContext(request))
#return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'map_file_id' : map_file_id,"tabSelected":"test"}, context_instance=RequestContext(request))
def status_test(request, xml_filename, download_id):
map_test_status = testFile.read_test_status(download_id)
......@@ -276,19 +276,19 @@ def move_synchro_listing_to_download(request, download_id):
if not is_success:
error="error"
return HttpResponse(error)
#@login_required()
def display_synchro_listing (request, xml_filename, download_id):
listing_file = synchro.read_synchro_status(download_id)["Output"]
listing_list = tasks.read_listing_file(listing_file)
#data_file = open(listing_file, 'r')
#data_file = open(listing_file, 'r')
var = RequestContext(request, {'listing_list': listing_list, 'download_id':download_id, 'xml_filename':xml_filename})
#var = RequestContext(request, {'data_file': data_file, 'download_id':download_id, 'xml_filename':xml_filename})
return render_to_response('adminview/viewfile.html', var)
#@login_required()
def display_synchro_log (request, download_id):
#data_file = open(os.path.join(settings.LOG_PATH, LOGGER_SYNCHRO_FILE_NAME + download_id + '.log'), 'r')
#data_file = open(os.path.join(settings.LOG_PATH, LOGGER_SYNCHRO_FILE_NAME + download_id + '.log'), 'r')
log_data = tasks.read_log_file(LOGGER_SYNCHRO_FILE_NAME + download_id + '.log')
var = RequestContext(request, {'log_data': log_data})
#var = RequestContext(request, {'data_file': data_file})
......@@ -338,7 +338,7 @@ def copy_as_file(request, xml_filename, download_id):
if tasks.exists_configuration_file( dst + EXTENSION_ACTIVE) or tasks.exists_configuration_file( dst + EXTENSION_DISABLED):
error="file_exist"
try:
is_success = downloaderXml.copy_as_file(xml_filename, dst + EXTENSION_DISABLED, download_id_dest)
......@@ -346,10 +346,10 @@ def copy_as_file(request, xml_filename, download_id):
error ="file_error"
except XMLSyntaxError as e:
error = e
if not error:
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
xml_file_as_save = dst + EXTENSION_DISABLED
if not error:
file_map, map_file_id, map_file_id_test = downloaderXml.get_downloads()
xml_file_as_save = dst + EXTENSION_DISABLED
return render_to_response('adminview/activateddownload.html', { 'file_map': file_map, 'tabSelected':'desactivated', 'map_file_id' : map_file_id, 'event' : 'filecreated','xml_file_name' : xml_file_as_save,}, context_instance=RequestContext(request))
else :
......@@ -365,12 +365,12 @@ def filter_downloads(request, pattern):
scheme = 'https://'
else:
scheme = 'http://'
base_url = reverse('dladmin:listdownload')
download_link_edit = {}
for download_id, filename in downloads_id.items():
download_link_edit[download_id]=base_url + filename
download_link_edit_json=json.dumps(download_link_edit)
return HttpResponse(download_link_edit_json, mimetype='application/json')
......@@ -405,26 +405,26 @@ def help (request):
map_help["checksum"]=_('checksum.help')
map_help["compression_action"]=_('compression_action.help')
map_help["compression_type"]= _('compression_type.help')
# data_reader
map_help["data_reader"]=_('data_reader.help')
map_help["regexp_date"]=_('regexp_date.help')
map_help["date_format"]=_('date_format.help')
map_help["storage_path"]=_('storage_path.help')
# listing builder
map_help["dcheck_config_default_file_accept"]=_('dcheck_config_default_file_accept.help')
map_help["dcheck_config_ignore_directories_regexp"]=_('dcheck_config_ignore_directories_regexp.help')
map_help["dcheck_config_force_files_regexp"]=_('dcheck_config_force_files_regexp.help')
map_help["dcheck_config_smart_crawler_delta"]=_('dcheck_config_smart_crawler_delta.help')
map_help["dcheck_config_smart_crawler_directories_pattern"]=_('dcheck_config_smart_crawler_directories_pattern.help')
map_help["dcheck_config_smart_crawler_maxdate"]=_('dcheck_config_smart_crawler_maxdate.help')
map_help["dcheck_config_smart_crawler_mindate"]=_('dcheck_config_smart_crawler_mindate.help')
map_help["dcheck_config_regexp_date"]=_('dcheck_config_regexp_date.help')
map_help["dcheck_config_smart_crawler_delta"]=_('dcheck_config_smart_crawler_delta.help')
map_help["dcheck_config_smart_crawler_directories_pattern"]=_('dcheck_config_smart_crawler_directories_pattern.help')
map_help["dcheck_config_smart_crawler_maxdate"]=_('dcheck_config_smart_crawler_maxdate.help')
map_help["dcheck_config_smart_crawler_mindate"]=_('dcheck_config_smart_crawler_mindate.help')
map_help["dcheck_config_regexp_date"]=_('dcheck_config_regexp_date.help')
map_help["dcheck_config_date_format"]=_('dcheck_config_date_format.help')
map_help["dreport_config"]=_('dreport_config.help')
#misc_parameter
map_help["listing_delay"]=_('listing_delay.help')
map_help["wait_before_download_delay"]=_('wait_before_download_delay.help')
......@@ -434,14 +434,14 @@ def help (request):
map_help["loop_delay"]=_('loop_delay.help')
map_help["wait_between_downloads"]=_('wait_between_downloads.help')
map_help["check_provider_before_download"]=_('check_provider_before_download.help')
#download_policies
map_help["redownload"]=_('redownload.help')
map_help["pattern_filters_activated"]=_('pattern_filters_activated.help')
map_help["pattern_filters_default"]=_('pattern_filters_default.help')
map_help["regexp_apply"]=_('regexp_apply.help')
map_help["regexp_action"]=_('regexp_action.help')
#remote_storage
map_help["type_remote"]=_('type_remote.help')
map_help["server_remote"]=_('server_remote.help')
......@@ -450,11 +450,11 @@ def help (request):
map_help["passwd_remote"]=_('passwd_remote.help')
map_help["repos_remote"]=_('repos_remote.help')
map_help["max_activated_flow"]=_('max_activated_flow.help')
# local
map_help["type_local"]=_('type_local.help')
map_help["repos_local"]=_('repos_local.help')
#data_control
map_help["to_download_max_nbr"]=_('to_download_max_nbr.help')
map_help["ignore_before"]=_('ignore_before.help')
......@@ -462,4 +462,4 @@ def help (request):
map_help["ignore_older_than"]=_('ignore_older_than.help')
return HttpResponse(map_help)
Markdown is supported
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