add correction for platform instance which are protected by a basic http login/password.
--- a/.hgignore Tue Nov 06 13:56:54 2012 +0100
+++ b/.hgignore Tue Nov 06 14:40:44 2012 +0100
@@ -33,3 +33,6 @@
syntax: regexp
^virtualenv/sync/project-boot\.py$
relre:^.metadata
+
+syntax: regexp
+^web/\.htusers$
\ No newline at end of file
--- a/src/ldt/ldt/ldt_utils/contentindexer.py Tue Nov 06 13:56:54 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/contentindexer.py Tue Nov 06 14:40:44 2012 +0100
@@ -8,7 +8,8 @@
import logging
import lxml.etree #@UnresolvedImport
import tagging.utils
-import urllib #@UnresolvedImport
+from ldt.utils.url import request_with_auth
+from StringIO import StringIO
logger = logging.getLogger(__name__)
@@ -129,8 +130,8 @@
def index_content(self, content):
url = content.iri_url()
- filepath = urllib.urlopen(url)
- doc = lxml.etree.parse(filepath) #@UndefinedVariable
+ _, content = request_with_auth(url)
+ doc = lxml.etree.parse(StringIO(content)) #@UndefinedVariable
Segment.objects.filter(iri_id=content.iri_id).delete() #@UndefinedVariable
--- a/src/ldt/ldt/ldt_utils/fileimport.py Tue Nov 06 13:56:54 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/fileimport.py Tue Nov 06 14:40:44 2012 +0100
@@ -1,11 +1,13 @@
+from StringIO import StringIO
from copy import deepcopy #@UnresolvedImport
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from ldt.utils import zipfileext
+from ldt.utils.url import request_with_auth
from models import Content, Media
import fnmatch
-import lxml.etree
+import lxml.etree #@UnresolvedImport
import mimetypes #@UnresolvedImport
import os.path
import shutil #@UnresolvedImport
@@ -25,8 +27,8 @@
class IriInfo(object):
- def __init__(self, id, order, titledesc, basepath="", videopath=settings.STREAM_URL, decoupage_blacklist=settings.DECOUPAGE_BLACKLIST, flatten=True):
- self.id = id
+ def __init__(self, iri_id, order, titledesc, basepath="", videopath=settings.STREAM_URL, decoupage_blacklist=settings.DECOUPAGE_BLACKLIST, flatten=True):
+ self.id = iri_id
self.basepath = basepath
self.order = order
self.src = ""
@@ -48,14 +50,15 @@
def process_iri(self):
# for just import a file ldt and get the title for every media
if 'http' in self.src:
- #url = urllib.urlopen(self.src)
path = self.src
- #doc = xml.dom.minidom.parse(url)
#for import a zip, get title and copy file .iri in the media directory
else:
path = os.path.join(self.basepath, self.src)
- #doc = xml.dom.minidom.parse(path)
-
+
+ if 'http' in path:
+ _,content = request_with_auth(path)
+ path = StringIO(content)
+
doc = lxml.etree.parse(path) #@UndefinedVariable
@@ -78,9 +81,9 @@
#if node.nodeType == xml.dom.Node.ELEMENT_NODE and node.tagName == "ensemble":
if node.tag == "ensemble":
#id = node.getAttributeNS(None,u"id")
- id = node.attrib["id"]
- if id not in ensembleids:
- ensembleids.append(id)
+ ens_id = node.attrib["id"]
+ if ens_id not in ensembleids:
+ ensembleids.append(ens_id)
if self.annotations is not None:
newEnsemble = None
@@ -304,43 +307,41 @@
for i, medianode in enumerate(result):
# get iri file's id from file ldt
- #id = medianode.attributes['id'].value
- id = medianode.attrib['id']
+ iri_id = medianode.attrib['id']
if self.check_existing_media:
try:
- Content.objects.get(iri_id=id)
+ Content.objects.get(iri_id=iri_id)
do_pass = True
except ObjectDoesNotExist: #Content.DoesNotExist
do_pass = False
else:
do_pass = False
if not do_pass:
- if not (contents.has_key(id)):
+ if not (contents.has_key(iri_id)):
# Create instance iriInfo(id, order, titledesc, basepath="", videopath=settings.STREAM_URL)
if ldtpath:
- contents[id] = IriInfo(id, i, "", os.path.dirname(ldtpath), flatten=self.flatten)
+ contents[iri_id] = IriInfo(iri_id, i, "", os.path.dirname(ldtpath), flatten=self.flatten)
else:
- contents[id] = IriInfo(id, i, "", flatten=self.flatten)
+ contents[iri_id] = IriInfo(iri_id, i, "", flatten=self.flatten)
# Get iri file's url from ldt. This url can be relative path or absolute path.
- #contents[id].src = medianode.attributes['src'].value
- contents[id].src = medianode.attrib['src']
+ contents[iri_id].src = medianode.attrib['src']
if medianode.attrib['video'] != "":
- contents[id].videopath = medianode.attrib['video']
+ contents[iri_id].videopath = medianode.attrib['video']
elif self.videopath != "" or self.videopath:
- contents[id].videopath = self.videopath
+ contents[iri_id].videopath = self.videopath
else:
- contents[id].videopath = settings.STREAM_URL
+ contents[iri_id].videopath = settings.STREAM_URL
#get annotation of file ldt
result = doc.xpath("/iri/annotations/content")
for contentnode in result:
- id = contentnode.attrib['id']
- if contents.has_key(id):
+ content_id = contentnode.attrib['id']
+ if contents.has_key(content_id):
if self.author:
contentnode.set("author", unicode(self.author))
- contents[id].annotations = contentnode
+ contents[content_id].annotations = contentnode
#go throught values
for iriinfo in contents.values():
--- a/src/ldt/ldt/ldt_utils/utils.py Tue Nov 06 13:56:54 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/utils.py Tue Nov 06 14:40:44 2012 +0100
@@ -4,9 +4,9 @@
from StringIO import StringIO
import datetime
import django.core.urlresolvers
-import lxml.etree
-import urllib
+import lxml.etree #@UnresolvedImport
import uuid
+from ldt.utils.url import request_with_auth
__BOOLEAN_DICT = {
'false':False,
@@ -25,12 +25,12 @@
node_list = [element_node.text]
return reduce(lambda t, s: t + s, node_list , "")
-def boolean_convert(bool):
- if bool is None:
+def boolean_convert(bool_val):
+ if bool_val is None:
return False
- if bool is True or bool is False:
- return bool
- key = str(bool).lower()
+ if bool_val is True or bool_val is False:
+ return bool_val
+ key = str(bool_val).lower()
return __BOOLEAN_DICT.get(key, False)
def generate_uuid():
@@ -102,7 +102,8 @@
for content in contentList:
contentd = lxml.etree.SubElement(display, "content")
contentd.set(u"id", content.iri_id)
- filepath = urllib.urlopen(content.iri_url())
+ __, content = request_with_auth(content.iri_url())
+ filepath = StringIO(content)
udoc = lxml.etree.parse(filepath)
res = udoc.xpath("/iri/body/ensembles/ensemble/decoupage")
@@ -357,8 +358,8 @@
url = content.iri_url()
else:
url = content.iriurl
- file = urllib.urlopen(url)
- doc = lxml.etree.parse(file)
+ __, content = request_with_auth(url)
+ doc = lxml.etree.parse(StringIO(content))
res = doc.xpath("/iri/body/ensembles/ensemble/decoupage")
#node decoupage
@@ -441,7 +442,7 @@
new_project.save()
return new_project
-def create_empty_iri(file, content, username):
+def create_empty_iri(iri_file, content, username):
iri = lxml.etree.Element('iri')
doc = lxml.etree.ElementTree(iri)
@@ -492,7 +493,7 @@
lxml.etree.SubElement(body, 'display')
- doc.write(file, pretty_print=True)
+ doc.write(iri_file, pretty_print=True)
def update_iri(filepath, content, username):
--- a/src/ldt/ldt/settings.py Tue Nov 06 13:56:54 2012 +0100
+++ b/src/ldt/ldt/settings.py Tue Nov 06 14:40:44 2012 +0100
@@ -54,6 +54,7 @@
WEB_URL = getattr(settings, 'WEB_URL', '')
+WEB_AUTH = getattr(settings, 'WEB_AUTH', None)
BASE_URL = getattr(settings, 'BASE_URL', '')
STATIC_URL = getattr(settings, 'STATIC_URL', '')
MEDIA_URL = getattr(settings, 'MEDIA_URL', '')
@@ -71,6 +72,8 @@
LOG_LEVEL = getattr(settings, 'LOG_LEVEL', logging.INFO)
EMPTY_MEDIA_EXTERNALID = getattr(settings, 'EMPTY_MEDIA_EXTERNALID', None)
+ADMIN_MEDIA_PREFIX = getattr(settings, 'ADMIN_MEDIA_PREFIX', None)
+
TEST_WEBSERVER_ADDRPORT = getattr(settings, 'TEST_WEBSERVER_ADDRPORT', '127.0.0.1:8000')
ACCOUNT_ACTIVATION_DAYS = getattr(settings, 'ACCOUNT_ACTIVATION_DAYS', 7)
@@ -106,3 +109,4 @@
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}
+
--- a/src/ldt/ldt/utils/context_processors.py Tue Nov 06 13:56:54 2012 +0100
+++ b/src/ldt/ldt/utils/context_processors.py Tue Nov 06 14:40:44 2012 +0100
@@ -1,4 +1,4 @@
-from django.conf import settings
+from ldt import settings
import ldt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/utils/url.py Tue Nov 06 14:40:44 2012 +0100
@@ -0,0 +1,14 @@
+from ldt import settings
+import httplib2
+import re
+
+def request_with_auth(url, method='GET'):
+ h = httplib2.Http()
+ web_auth = getattr(settings, "WEB_AUTH", {})
+ for key in web_auth:
+ if re.search(key, url, re.IGNORECASE):
+ h.add_credentials(web_auth[key].get('NAME', ''), web_auth[key].get('PASSWORD', ''), web_auth[key].get('DOMAIN', ''))
+ break
+
+ return h.request(url, method)
+