Unverified Commit 04baa5f5 authored by CHARLES's avatar CHARLES 🐧
Browse files

Some fixes / cleaning

parent cd2cf20f
from django.conf import settings
from lxml import etree, objectify
from lxml.etree import XMLSyntaxError
import errno
import time
import os
import downloader_django.common.constants
......@@ -14,7 +12,7 @@ def activate_download(filename):
name, fileExtension = os.path.splitext(filename)
filesplit = name.split(".")
if fileExtension == ".xml" and filesplit[-1] == "test":
newname = (".").join(filesplit[:-1])+fileExtension
newname = (".").join(filesplit[:-1]) + fileExtension
else:
newname = os.path.splitext(filename)[0]
......@@ -450,7 +448,7 @@ def save_data_destination(file_data, submitted_data):
if submitted_data['repos_local_tree']:
if parent_org.find("subpath") is None:
dummy = etree.SubElement(parent_org, "subpath")
parent_orgn.subpath = submitted_data['repos_local_tree']
parent_org.subpath = submitted_data['repos_local_tree']
if submitted_data['type_local']:
if parent_org.find("type") is None:
dummy = etree.SubElement(parent_org, "type")
......
from celery.exceptions import TimeoutError
from django.conf import settings
from lxml import etree, objectify
from lxml.etree import XMLSyntaxError
import os
import downloader_django.common.constants
from downloader_django.common.downloaderUtil import get_workspace_dir_name
......
......@@ -7,8 +7,7 @@
__docformat__ = 'epytext'
from xml.etree.ElementTree import ElementTree
import logging
from xml.etree import ElementTree
from downloader_django.common.system.tasks import write_content_file
......@@ -38,11 +37,11 @@ class XMLWriter(object):
raise
def __indent(self, elem, level):
l = ["\n"]
indentStr = ["\n"]
for index in range(level):
l.append(" ")
indentStr.append(" ")
i = ''.join(l)
i = ''.join(indentStr)
if len(elem):
if not elem.text or not elem.text.strip():
......@@ -50,7 +49,7 @@ class XMLWriter(object):
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
self.__indent(elem, level+1)
self.__indent(elem, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
......
......@@ -125,14 +125,11 @@ def modetest(request, xml_filename):
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}
)
return render(
request,
'adminview/viewlog.html', var)
# return HttpResponse(data_file)
'adminview/viewlog.html',
{'download_id': download_id, 'xml_filename': xml_filename}
)
def getActivatedNbFile(request):
......@@ -262,8 +259,6 @@ def save_test_file(request, xml_filename, download_id):
# synchro.add_synchro_status(file_map)
map_test_status = testFile.read_test_status(download_id)
return HttpResponse(map_test_status['State'])
# return renders
request,e('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):
......@@ -350,8 +345,6 @@ def display_synchro_log(request, download_id):
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})
# return HttpResponse(data_file)
return HttpResponse(log_data)
......@@ -430,8 +423,6 @@ def copy_as_file(request, xml_filename, download_id):
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}
# return renders
request,e('adminview/adddownload.html', kwvars, context_instance = RequestContext(request))
return render(
request,
'adminview/activateddownload.html',
......@@ -441,10 +432,7 @@ def copy_as_file(request, xml_filename, download_id):
def filter_downloads(request, pattern):
downloads_id = downloaderXml.filter_downloads(pattern)
if request.is_secure():
scheme = 'https://'
else:
scheme = 'http://'
# scheme = 'https://' if request.is_secure() else 'http://'
base_url = reverse('dladmin:listdownload')
download_link_edit = {}
......@@ -457,8 +445,8 @@ def filter_downloads(request, pattern):
def create_and_edit_download(request, download_id):
download_file_name_disabled = download_id + EXTENSION_DISABLED
download_file_name_active = download_id + EXTENSION_ACTIVE
download_file_name_test = download_id + EXTENSION_TEST
# download_file_name_active = download_id + EXTENSION_ACTIVE
# download_file_name_test = download_id + EXTENSION_TEST
# if os.path.isfile(os.path.join(settings.CONF_PATH, download_file_name_active)):
# xml_filename=download_file_name_active
......
from UserDict import DictMixin
class odict(DictMixin):
class odict:
def __init__(self):
self._keys = []
......@@ -30,7 +28,7 @@ class odict(DictMixin):
def __repr__(self):
repr = "{"
for key, value in list(self.items()):
for key, value in self:
repr += "u'" + key + "'"
repr += ": "
repr += str(value)
......@@ -38,3 +36,10 @@ class odict(DictMixin):
if repr[-1] == ",":
repr = repr[:-1] + "}"
return repr
def __len__(self):
return len(self._keys)
def __iter__(self):
for key in self._keys:
yield self._data[key]
......@@ -310,3 +310,52 @@ producing strings. This is equivalent to calling write() for each string."""
if not self.isOpen():
raise IOError("I/O operation on closed file")
return self.__fd.writelines(*args)
def link(self, linkName, symbolic=False, keepExist=False):
"""Link the L{File} to a new place
@param linkName: the link L{File} name
@type linkName: C{str}
@param symbolic: create a symbolic link instead of a hard link (default C{False})
@type symbolic: C{bool}
@param keepExist: If true, do not overwrite L{linkName} if exist (default C{False})
@type keepExist: C{bool}
@return: a L{File} instance of the link file
@rtype: L{File}
@raise OSError: if the instance of L{File} doesn't exist.
@raise IOError: if the instance of L{File} is actually open.
"""
if not self.exist():
raise OSError("File '%s' doesn't exist" % self.getName())
if self.isOpen():
raise IOError("FileSystem operation on open file")
if not keepExist and (os.path.isfile(linkName) or
os.path.islink(linkName)):
os.remove(linkName)
if symbolic:
os.symlink(self.getName(), linkName)
else:
os.link(self.getName(), linkName)
return File(linkName)
def getRealFile(self):
"""Return the file pointed self (if self.isLink() == True)
@rtype: C{File}
"""
if not self.isLink():
raise "File %s isn't a symbolic link, can't return real file" % self.getName()
return File(self.getName(real=True))
def remove(self):
"""Remove the L{File} from the disk
@raise OSError: if the instance of L{File} doesn't exist.
@raise IOError: if the instance of L{File} is actually open.
"""
if not self.exist():
raise OSError("File '%s' doesn't exist" % self.getName())
if self.isOpen():
raise IOError("FileSystem operation on open file")
os.remove(self.getName())
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