--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,9 @@
+
+syntax: regexp
+^run$
+syntax: regexp
+^\.pydevproject$
+syntax: regexp
+^src/p4l/config\.py$
+syntax: regexp
+^\.metadata$
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.project Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>plan4learning</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.python.pydev.PyDevBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.python.pydev.pythonNature</nature>
+ </natures>
+</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/manage.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "p4l.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/admin.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,15 @@
+from p4l.models import User
+from django.contrib import admin
+from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
+from django.utils.translation import gettext_lazy as _
+from p4l.forms import UserChangeForm, UserCreationform
+
+class UserAdmin(AuthUserAdmin):
+ form = UserChangeForm
+ add_form = UserCreationform
+ fieldsets = tuple(list(AuthUserAdmin.fieldsets) + [(_('language'), {'fields':('language',)})])
+
+
+admin.site.register(User, UserAdmin)
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/config.py.tmpl Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,137 @@
+import logging
+import os
+# Django settings for p4l project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': '', # Or path to database file if using sqlite3.
+ # The following settings are not used with sqlite3:
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
+ 'PORT': '', # Set to empty string for default.
+ }
+}
+
+# Hosts/domain names that are valid for this site; required if DEBUG is False
+# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
+ALLOWED_HOSTS = []
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# In a Windows environment this must be set to your system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"
+BASE_URL = '/~ymh/p4l/'
+WEB_URL = 'http://localhost'
+BASE_STATIC_URL = WEB_URL + BASE_URL + 'static/'
+BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../../web/static/").rstrip("/")+"/"
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/var/www/example.com/media/"
+MEDIA_ROOT = BASE_STATIC_ROOT + "media/"
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://example.com/media/", "http://media.example.com/"
+MEDIA_URL = BASE_STATIC_URL + "media/"
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/var/www/example.com/static/"
+STATIC_ROOT = BASE_STATIC_ROOT + "site/"
+
+# URL prefix for static files.
+# Example: "http://example.com/static/", "http://static.example.com/"
+STATIC_URL = BASE_STATIC_URL + 'site/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'change_this_with_very_secret_key'
+
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'p4l.wsgi.application'
+
+LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../../run/log/log.txt"))
+LOG_LEVEL = logging.DEBUG
+
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
+ 'formatters' : {
+ 'simple' : {
+ 'format': "%(asctime)s - %(levelname)s : %(message)s",
+ },
+ 'semi-verbose': {
+ 'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
+ },
+ },
+ 'handlers': {
+ 'stream_to_console': {
+ 'level': LOG_LEVEL,
+ 'class': 'logging.StreamHandler'
+ },
+ 'file': {
+ 'level': LOG_LEVEL,
+ 'class': 'logging.FileHandler',
+ 'filename': LOG_FILE,
+ 'formatter': 'semi-verbose',
+ },
+ },
+ 'loggers': {
+ 'django.db.backends': {
+ 'handlers': ['file'],
+ 'level': 'DEBUG',
+ 'propagate': True,
+ },
+ 'django.request': {
+ 'handlers': ['file'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ 'p4l': {
+ 'handlers': ['file'],
+ 'level': 'DEBUG',
+ 'propagate': True,
+ },
+ 'core': {
+ 'handlers': ['file'],
+ 'level': 'DEBUG',
+ 'propagate': True,
+ },
+ 'rdflib_sqlalchemy': {
+ 'handlers': ['file'],
+ 'level': 'DEBUG',
+ 'propagate': True,
+ },
+ 'rdflib.term': {
+ 'handlers': ['file'],
+ 'level': 'DEBUG',
+ 'propagate': True,
+ },
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/forms.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+'''
+Created on Aug 4, 2013
+
+@author: ymh
+'''
+from django.conf import settings
+from django.contrib.auth import get_user_model
+from django.contrib.auth.forms import (UserChangeForm as AuthUserChangeForm,
+ UserCreationForm as AuthUserCreationForm)
+from django.core.exceptions import ValidationError
+from django.forms.fields import ChoiceField
+from django.utils.translation import ugettext as _
+
+
+User = get_user_model()
+
+class UserCreationform(AuthUserCreationForm):
+ class Meta:
+ model = User
+
+ def clean_username(self):
+ # Since User.username is unique, this check is redundant,
+ # but it sets a nicer error message than the ORM. See #13147.
+ username = self.cleaned_data["username"]
+ try:
+ User.objects.get(username=username)
+ except User.DoesNotExist:
+ return username
+ raise ValidationError(self.error_messages['duplicate_username'])
+
+
+class UserChangeForm(AuthUserChangeForm):
+ language = ChoiceField(label=_("language"), choices=[(k,_(v)) for k,v in settings.LANGUAGES], initial=settings.LANGUAGE_CODE[:2])
+ class Meta:
+ model = User
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/management/commands/import_record.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,393 @@
+# -*- coding: utf-8 -*-
+
+from p4l.utils import show_progress, get_code_from_language_uri
+from p4l.models import Record, Language
+from rdflib import Graph, Namespace, BNode, URIRef
+from rdflib.plugins.sparql import prepareQuery
+from django.core.management import BaseCommand
+from optparse import make_option
+import xml.etree.cElementTree as ET
+from django.db import reset_queries, transaction
+import traceback
+import logging
+import sys
+
+logger = logging.getLogger(__name__)
+
+
+RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+RDFS = Namespace("http://www.w3.org/2000/01/rdf-schema#")
+DCT = Namespace("http://purl.org/dc/terms/")
+IIEP = Namespace("http://www.iiep.unesco.org/plan4learning/model.owl#")
+UNESCO = Namespace("http://www.iiep.unesco.org/Ontology/")
+
+DEFAULT_LANGUAGE_URI = "http://psi.oasis-open.org/iso/639/#eng"
+
+DEFAULT_LANGUAGE_QUERY = """SELECT ( COALESCE(?lang, ?other_lang) as ?main_lang) WHERE {
+ OPTIONAL { ?s dct:language ?lang }.
+ OPTIONAL { ?s iiep:otherLanguage ?other_lang }.
+}"""
+
+
+class Command(BaseCommand):
+
+ args = "record_url ..."
+
+ help = "Import p4l record rdf format"
+
+ option_list = BaseCommand.option_list + (
+ make_option('-b', '--batch-size',
+ dest= 'batch_size',
+ type='int',
+ default= 50,
+ help= 'number of object to import in bulk operations'
+ ),
+ )
+
+ def __init__(self, *args, **kwargs):
+ super(Command, self).__init__(*args, **kwargs)
+ self.__query_cache = {}
+
+
+ def __get_sparql_query(self, query, namespaces):
+
+ return self.__query_cache[query] \
+ if query in self.__query_cache \
+ else self.__query_cache.setdefault(query, prepareQuery(query, initNs=namespaces))
+
+ def get_empty_graph(self):
+ record_graph = Graph()
+ record_graph.bind('iiep',"http://www.iiep.unesco.org/plan4learning/model.owl#")
+ record_graph.bind('dct',"http://purl.org/dc/terms/")
+ return record_graph
+
+ def extract_single_value_form_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None):
+ return next(self.extract_multiple_values_from_graph(graph, q, bindings, index, convert), None)
+
+ def extract_multiple_values_from_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None):
+
+ index_list = index
+ if isinstance(index, int):
+ index_list = range(index+1)
+
+ if hasattr(convert, '__call__'):
+ convert_dict = dict((k, convert) for k in index_list)
+ else:
+ convert_dict = convert
+
+ convert_dict = dict((k, f if hasattr(f,'__call__') else lambda v:unicode(v) if v is not None else None) for k,f in convert_dict.iteritems())
+
+ for row in graph.query(self.__get_sparql_query(q, dict(graph.namespaces())), initBindings=bindings):
+ if len(row) < len(index_list):
+ break
+ else:
+ res = dict([ (k, convert_dict.get(k, lambda v:unicode(v) if v is not None else None)(v)) for k, v in zip(index_list, row)])
+ if isinstance(index, int):
+ yield res[index]
+ else:
+ yield res
+
+
+ def convert_bool(self, val):
+ if val == True or val == False:
+ return val
+ if val is None:
+ return False
+ if isinstance(val, basestring):
+ if len(val) == 0:
+ return False
+ if val[0].lower() in ['t','y','1','o']:
+ return True
+ else:
+ return False
+ return bool(val)
+
+ def convert_lang(self, val, default_lang):
+ return unicode(val) if (val is not None and len(unicode(val))>0) else default_lang
+
+
+ def get_record_default_language(self, g, record_uri):
+ lang_uri = self.extract_single_value_form_graph(g, DEFAULT_LANGUAGE_QUERY, bindings={'s': URIRef(record_uri)})
+ if not lang_uri:
+ lang_uri = DEFAULT_LANGUAGE_URI
+ lang_code = get_code_from_language_uri(lang_uri)
+ if lang_code is None:
+ logger.warn("get_record_default_language: no code found for %s in record %s" % (lang_uri, record_uri))
+ return get_code_from_language_uri(DEFAULT_LANGUAGE_URI)
+ return lang_code
+
+
+ def add_to_related_collection(self, coll, graph, fields, q, bindings={}, convert=lambda v: unicode(v) if v is not None else None, through_fields=None):
+
+ for val in self.extract_multiple_values_from_graph(graph, q, bindings=bindings, index=fields, convert=convert):
+
+ if through_fields:
+ new_obj_val = dict([(k,v) for k,v in val.iteritems() if k not in through_fields])
+ else:
+ new_obj_val = val
+
+ if hasattr(coll, 'through'):
+ new_obj_rel, _ = coll.model.objects.get_or_create(**new_obj_val)
+ if through_fields:
+ through_vals = {coll.source_field_name: coll.instance, coll.target_field_name: new_obj_rel}
+ through_vals.update(dict([(k,v) for k,v in val.iteritems() if k in through_fields]))
+ coll.through.objects.create(**through_vals)
+ new_obj = None
+ else:
+ new_obj = new_obj_rel
+
+ else:
+ new_obj = coll.create(**new_obj_val)
+
+ if new_obj:
+ coll.add(new_obj)
+
+
+
+
+ def build_record(self, graph):
+
+ record_uri = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?s WHERE { ?s rdf:type iiep:Record .}")
+ default_language_code = self.get_record_default_language(graph, record_uri)
+
+ record = Record()
+ record.uri = record_uri
+ record.identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record.uri)})
+ record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)})
+ record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)})
+ record.isDocumentPart = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:isDocumentPart ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool)
+ record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)})
+
+ language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)})
+ if language:
+ record.language, _ = Language.objects.get_or_create(language=language)
+
+ record.save()
+
+ self.add_to_related_collection(record.otherLanguages, graph, ['language'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.subjects, graph, ['subject'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.themes, graph, ['theme'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.countries, graph, ['country'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)})
+ self.add_to_related_collection(record.projectNames, graph, ['label','acronym'], "SELECT ?l ?a WHERE { [ iiep:projectName ?bnode ]. ?bnode rdfs:label ?l. OPTIONAL { ?bnode iiep:acronym ?a } }")
+
+ self.add_to_related_collection(
+ record.periodicals,
+ graph,
+ ['label','lang'],
+ "SELECT DISTINCT ?o ( lang(?o) as ?l) WHERE { ?s iiep:periodical ?o .}",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)},
+ through_fields = ['lang']
+ )
+
+ self.add_to_related_collection(
+ record.meetings,
+ graph,
+ ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear', 'lang'],
+ "SELECT ?l ?mn ?mp ?md ?my (lang(COALESCE(?l,?nm, ?mp,?md,?my)) as ?lang) WHERE { [iiep:meeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}",
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code), 'meetingYear' : lambda y: int(y) if y is not None else None},
+ through_fields = ['lang']
+ )
+
+ self.add_to_related_collection(
+ record.series,
+ graph,
+ ['title', 'volume', 'lang'],
+ "SELECT ?t ?vol (lang(COALESCE(?t,?vol)) as ?lang) WHERE { [iiep:serie ?bnode]. OPTIONAL { ?bnode dct:title ?t }. OPTIONAL { ?bnode iiep:volume ?vol } }",
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)},
+ through_fields = ['lang']
+ )
+
+ self.add_to_related_collection(
+ record.subjectCorporateBodies,
+ graph,
+ ['label', 'acronym'],
+ "SELECT ?l ?a WHERE { [iiep:subjectCorporateBody ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:acronym ?a } }",
+ )
+
+ self.add_to_related_collection(
+ record.subjectMeetings,
+ graph,
+ ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'],
+ "SELECT ?l ?mn ?mp ?md ?my WHERE { [iiep:meeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}",
+ convert={'meetingYear' : lambda y: int(y) if y is not None else None}
+ )
+
+ self.add_to_related_collection(
+ record.corporateAuthors,
+ graph,
+ ['label', 'acronym'],
+ "SELECT ?l ?a WHERE { [iiep:corporateAuthor ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:acronym ?a } }",
+ )
+
+ self.add_to_related_collection(
+ record.issns,
+ graph,
+ ['issn', 'lang'],
+ "SELECT ?issn (lang(COALESCE(?issn)) as ?lang) WHERE { ?s iiep:issn ?issn . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.isbns,
+ graph,
+ ['isbn', 'lang'],
+ "SELECT ?isbn (lang(COALESCE(?isbn)) as ?lang) WHERE { ?s iiep:isbn ?isbn . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.documentCodes,
+ graph,
+ ['documentCode', 'lang'],
+ "SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:documentCode ?c . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.titles,
+ graph,
+ ['title', 'lang'],
+ "SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:title ?t . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.addedTitles,
+ graph,
+ ['title', 'lang'],
+ "SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:addedTitle ?t . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.titlesMainDocument,
+ graph,
+ ['title', 'lang'],
+ "SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:titleMainDocument ?t . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.imprints,
+ graph,
+ ['imprintCity', 'publisher', 'imprintDate', 'lang'],
+ "SELECT ?c ?p ?d (lang(COALESCE(?c, ?p, ?d)) as ?lang) WHERE { [ iiep:imprint ?bnode ]. OPTIONAL { ?bnode iiep:imprintCity ?c }. OPTIONAL { ?bnode dct:publisher ?p }. OPTIONAL { ?bnode iiep:imprintDate ?d }}",
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.collations,
+ graph,
+ ['collation', 'lang'],
+ "SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:collation ?c . }",
+ bindings={'s':URIRef(record.uri)},
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.volumeIssues,
+ graph,
+ ['volume', 'number', 'lang'],
+ "SELECT ?v ?n (lang(COALESCE(?v, ?n)) as ?lang) WHERE { [ iiep:volumeIssue ?bnode ]. OPTIONAL { ?bnode iiep:volume ?v }. OPTIONAL { ?bnode iiep:number ?v }}",
+ convert={'lang':lambda l: self.convert_lang(l, default_language_code)}
+ )
+
+ self.add_to_related_collection(
+ record.urls,
+ graph,
+ ['address', 'display', 'accessLevel'],
+ "SELECT ?a ?d ?al WHERE { [ iiep:url ?bnode ]. OPTIONAL { ?bnode iiep:address ?a }. OPTIONAL { ?bnode iiep:display ?d }. OPTIONAL { ?bnode iiep:accessLevel ?al }.}",
+ )
+
+ return record
+
+
+ def filter_node(self, node, graph, res_graph):
+ for p,o in graph[node]:
+ res_graph.add((node,p,o))
+ if isinstance(o, BNode):
+ self.filter_node(o, graph, res_graph)
+
+
+
+ def calculate_records_nb(self, records_url):
+ context = ET.iterparse(records_url, events=("end",))
+ i = 0
+ for _,elem in context:
+ if elem.tag == "{%s}Record" % IIEP:
+ i += 1
+ return i
+
+ def process_url(self, records_url, options):
+
+ total_records = self.calculate_records_nb(records_url)
+ writer = None
+ errors=[]
+
+ context = ET.iterparse(records_url, events=("end",))
+ i = 0
+ for event,elem in context:
+ if elem.tag == "{%s}Record" % IIEP:
+ i += 1
+ writer = show_progress(i, total_records, "Processing record nb %d " % i, 50, writer=writer)
+ try:
+ record_graph = self.get_empty_graph()
+ record_graph.parse(data=ET.tostring(elem, encoding='utf-8'), format='xml')
+ # add transaction management
+ self.build_record(record_graph)
+ except Exception as e:
+ transaction.rollback()
+ msg = "Error processing resource %d in %s : %s" % (i, records_url, repr(e))
+ logger.exception(msg)
+ errors.append((i, records_url, msg))
+ else:
+ transaction.commit()
+
+ if i%self.batch_size == 0:
+ reset_queries()
+
+ return errors
+
+
+ # def process_url(self, records_url, options):
+ # #open graph with rdflib
+ # #TODO: manage memory
+ # g = Graph()
+ # print("Loading %s" % records_url)
+ # g.parse(records_url)
+ # print("Parsing %s done" % records_url)
+ # for i,record_uri in enumerate(g[:RDF.type:IIEP.Record]):
+ # print(i, repr(record_uri))
+ # record_graph = self.get_empty_graph()
+ # self.filter_node(record_uri, g, record_graph)
+ # self.build_record(record_graph)
+ # if i > 3:
+ # break
+
+
+
+
+ def handle(self, *args, **options):
+
+ self.batch_size = options.get('batch_size', 50)
+ transaction.enter_transaction_management()
+ transaction.managed(True)
+
+ for records_url in args:
+ print("Processing %s" % records_url)
+ errors = self.process_url(records_url, options)
+ print("Processing %s Done" % records_url)
+ if errors:
+ print("%d error(s) when processing %s, check your log file." % (len(errors), records_url))
+
+ transaction.leave_transaction_management()
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/migrations/0001_initial.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,793 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Imprint'
+ db.create_table(u'p4l_imprint', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='imprints', to=orm['p4l.Record'])),
+ ('imprintCity', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=512, null=True, blank=True)),
+ ('publisher', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=512, null=True, blank=True)),
+ ('imprintDate', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=512, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['Imprint'])
+
+ # Adding model 'Serie'
+ db.create_table(u'p4l_serie', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('volume', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['Serie'])
+
+ # Adding unique constraint on 'Serie', fields ['title', 'volume']
+ db.create_unique(u'p4l_serie', ['title', 'volume'])
+
+ # Adding model 'RecordSerie'
+ db.create_table(u'p4l_recordserie', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='series+', to=orm['p4l.Record'])),
+ ('serie', self.gf('django.db.models.fields.related.ForeignKey')(related_name='records', to=orm['p4l.Serie'])),
+ ))
+ db.send_create_signal('p4l', ['RecordSerie'])
+
+ # Adding unique constraint on 'RecordSerie', fields ['record', 'serie']
+ db.create_unique(u'p4l_recordserie', ['record_id', 'serie_id'])
+
+ # Adding model 'ProjectName'
+ db.create_table(u'p4l_projectname', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('acronym', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['ProjectName'])
+
+ # Adding unique constraint on 'ProjectName', fields ['label', 'acronym']
+ db.create_unique(u'p4l_projectname', ['label', 'acronym'])
+
+ # Adding model 'CorporateAuthor'
+ db.create_table(u'p4l_corporateauthor', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('acronym', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['CorporateAuthor'])
+
+ # Adding unique constraint on 'CorporateAuthor', fields ['label', 'acronym']
+ db.create_unique(u'p4l_corporateauthor', ['label', 'acronym'])
+
+ # Adding model 'Url'
+ db.create_table(u'p4l_url', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='urls', to=orm['p4l.Record'])),
+ ('address', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('display', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('accessLevel', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=512, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['Url'])
+
+ # Adding model 'Subject'
+ db.create_table(u'p4l_subject', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('subject', self.gf('django.db.models.fields.URLField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Subject'])
+
+ # Adding model 'Theme'
+ db.create_table(u'p4l_theme', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('theme', self.gf('django.db.models.fields.URLField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Theme'])
+
+ # Adding model 'Country'
+ db.create_table(u'p4l_country', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('country', self.gf('django.db.models.fields.URLField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Country'])
+
+ # Adding model 'Isbn'
+ db.create_table(u'p4l_isbn', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='isbns', to=orm['p4l.Record'])),
+ ('isbn', self.gf('django.db.models.fields.CharField')(max_length=128)),
+ ))
+ db.send_create_signal('p4l', ['Isbn'])
+
+ # Adding model 'Issn'
+ db.create_table(u'p4l_issn', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='issns', to=orm['p4l.Record'])),
+ ('issn', self.gf('django.db.models.fields.CharField')(max_length=128)),
+ ))
+ db.send_create_signal('p4l', ['Issn'])
+
+ # Adding model 'DocumentCode'
+ db.create_table(u'p4l_documentcode', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='documentCodes', to=orm['p4l.Record'])),
+ ('documentCode', self.gf('django.db.models.fields.CharField')(max_length=128)),
+ ))
+ db.send_create_signal('p4l', ['DocumentCode'])
+
+ # Adding model 'Language'
+ db.create_table(u'p4l_language', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('language', self.gf('django.db.models.fields.URLField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Language'])
+
+ # Adding model 'Title'
+ db.create_table(u'p4l_title', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='titles', to=orm['p4l.Record'])),
+ ))
+ db.send_create_signal('p4l', ['Title'])
+
+ # Adding model 'AddedTitle'
+ db.create_table(u'p4l_addedtitle', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='addedTitles', to=orm['p4l.Record'])),
+ ))
+ db.send_create_signal('p4l', ['AddedTitle'])
+
+ # Adding model 'TitleMainDocument'
+ db.create_table(u'p4l_titlemaindocument', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='titlesMainDocument', to=orm['p4l.Record'])),
+ ))
+ db.send_create_signal('p4l', ['TitleMainDocument'])
+
+ # Adding model 'Abstract'
+ db.create_table(u'p4l_abstract', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='abstracts', to=orm['p4l.Record'])),
+ ('abstract', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['Abstract'])
+
+ # Adding model 'Collation'
+ db.create_table(u'p4l_collation', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='collations', to=orm['p4l.Record'])),
+ ('collation', self.gf('django.db.models.fields.CharField')(max_length=1024, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Collation'])
+
+ # Adding model 'VolumeIssue'
+ db.create_table(u'p4l_volumeissue', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='volumeIssues', to=orm['p4l.Record'])),
+ ('volume', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=1024, null=True, blank=True)),
+ ('number', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=1024, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['VolumeIssue'])
+
+ # Adding model 'Author'
+ db.create_table(u'p4l_author', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Author'])
+
+ # Adding model 'SubjectPerson'
+ db.create_table(u'p4l_subjectperson', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['SubjectPerson'])
+
+ # Adding model 'Periodical'
+ db.create_table(u'p4l_periodical', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(unique=True, max_length=2048, db_index=True)),
+ ))
+ db.send_create_signal('p4l', ['Periodical'])
+
+ # Adding model 'RecordPeriodical'
+ db.create_table(u'p4l_recordperiodical', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='periodicals+', to=orm['p4l.Record'])),
+ ('periodical', self.gf('django.db.models.fields.related.ForeignKey')(related_name='records', to=orm['p4l.Periodical'])),
+ ))
+ db.send_create_signal('p4l', ['RecordPeriodical'])
+
+ # Adding unique constraint on 'RecordPeriodical', fields ['record', 'periodical']
+ db.create_unique(u'p4l_recordperiodical', ['record_id', 'periodical_id'])
+
+ # Adding model 'Meeting'
+ db.create_table(u'p4l_meeting', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('meetingNumber', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingPlace', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingDate', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingYear', self.gf('django.db.models.fields.PositiveSmallIntegerField')(db_index=True, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['Meeting'])
+
+ # Adding unique constraint on 'Meeting', fields ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
+ db.create_unique(u'p4l_meeting', ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'])
+
+ # Adding model 'RecordMeeting'
+ db.create_table(u'p4l_recordmeeting', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('lang', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, null=True, blank=True)),
+ ('record', self.gf('django.db.models.fields.related.ForeignKey')(related_name='meetings+', to=orm['p4l.Record'])),
+ ('meeting', self.gf('django.db.models.fields.related.ForeignKey')(related_name='records', to=orm['p4l.Meeting'])),
+ ))
+ db.send_create_signal('p4l', ['RecordMeeting'])
+
+ # Adding unique constraint on 'RecordMeeting', fields ['record', 'meeting']
+ db.create_unique(u'p4l_recordmeeting', ['record_id', 'meeting_id'])
+
+ # Adding model 'SubjectMeeting'
+ db.create_table(u'p4l_subjectmeeting', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('meetingNumber', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingPlace', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingDate', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ('meetingYear', self.gf('django.db.models.fields.PositiveSmallIntegerField')(db_index=True, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['SubjectMeeting'])
+
+ # Adding unique constraint on 'SubjectMeeting', fields ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
+ db.create_unique(u'p4l_subjectmeeting', ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'])
+
+ # Adding model 'CorporateBody'
+ db.create_table(u'p4l_corporatebody', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('label', self.gf('django.db.models.fields.CharField')(max_length=2048, db_index=True)),
+ ('acronym', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2048, null=True, blank=True)),
+ ))
+ db.send_create_signal('p4l', ['CorporateBody'])
+
+ # Adding unique constraint on 'CorporateBody', fields ['label', 'acronym']
+ db.create_unique(u'p4l_corporatebody', ['label', 'acronym'])
+
+ # Adding model 'Record'
+ db.create_table(u'p4l_record', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('uri', self.gf('django.db.models.fields.URLField')(unique=True, max_length=2048, db_index=True)),
+ ('identifier', self.gf('django.db.models.fields.CharField')(unique=True, max_length=128, db_index=True)),
+ ('notes', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
+ ('language', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['p4l.Language'], null=True, blank=True)),
+ ('editionStatement', self.gf('django.db.models.fields.CharField')(max_length=1024, null=True, blank=True)),
+ ('recordType', self.gf('django.db.models.fields.URLField')(max_length=2048)),
+ ('isDocumentPart', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ))
+ db.send_create_signal('p4l', ['Record'])
+
+ # Adding M2M table for field subjects on 'Record'
+ db.create_table(u'p4l_record_subjects', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('subject', models.ForeignKey(orm['p4l.subject'], null=False))
+ ))
+ db.create_unique(u'p4l_record_subjects', ['record_id', 'subject_id'])
+
+ # Adding M2M table for field themes on 'Record'
+ db.create_table(u'p4l_record_themes', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('theme', models.ForeignKey(orm['p4l.theme'], null=False))
+ ))
+ db.create_unique(u'p4l_record_themes', ['record_id', 'theme_id'])
+
+ # Adding M2M table for field countries on 'Record'
+ db.create_table(u'p4l_record_countries', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('country', models.ForeignKey(orm['p4l.country'], null=False))
+ ))
+ db.create_unique(u'p4l_record_countries', ['record_id', 'country_id'])
+
+ # Adding M2M table for field otherLanguages on 'Record'
+ db.create_table(u'p4l_record_otherLanguages', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('language', models.ForeignKey(orm['p4l.language'], null=False))
+ ))
+ db.create_unique(u'p4l_record_otherLanguages', ['record_id', 'language_id'])
+
+ # Adding M2M table for field projectNames on 'Record'
+ db.create_table(u'p4l_record_projectNames', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('projectname', models.ForeignKey(orm['p4l.projectname'], null=False))
+ ))
+ db.create_unique(u'p4l_record_projectNames', ['record_id', 'projectname_id'])
+
+ # Adding M2M table for field authors on 'Record'
+ db.create_table(u'p4l_record_authors', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('author', models.ForeignKey(orm['p4l.author'], null=False))
+ ))
+ db.create_unique(u'p4l_record_authors', ['record_id', 'author_id'])
+
+ # Adding M2M table for field subjectPersons on 'Record'
+ db.create_table(u'p4l_record_subjectPersons', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('subjectperson', models.ForeignKey(orm['p4l.subjectperson'], null=False))
+ ))
+ db.create_unique(u'p4l_record_subjectPersons', ['record_id', 'subjectperson_id'])
+
+ # Adding M2M table for field subjectCorporateBodies on 'Record'
+ db.create_table(u'p4l_record_subjectCorporateBodies', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('corporatebody', models.ForeignKey(orm['p4l.corporatebody'], null=False))
+ ))
+ db.create_unique(u'p4l_record_subjectCorporateBodies', ['record_id', 'corporatebody_id'])
+
+ # Adding M2M table for field subjectMeetings on 'Record'
+ db.create_table(u'p4l_record_subjectMeetings', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('subjectmeeting', models.ForeignKey(orm['p4l.subjectmeeting'], null=False))
+ ))
+ db.create_unique(u'p4l_record_subjectMeetings', ['record_id', 'subjectmeeting_id'])
+
+ # Adding M2M table for field corporateAuthors on 'Record'
+ db.create_table(u'p4l_record_corporateAuthors', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('record', models.ForeignKey(orm['p4l.record'], null=False)),
+ ('corporateauthor', models.ForeignKey(orm['p4l.corporateauthor'], null=False))
+ ))
+ db.create_unique(u'p4l_record_corporateAuthors', ['record_id', 'corporateauthor_id'])
+
+ # Adding model 'User'
+ db.create_table(u'p4l_user', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('password', self.gf('django.db.models.fields.CharField')(max_length=128)),
+ ('last_login', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
+ ('is_superuser', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('username', self.gf('django.db.models.fields.CharField')(unique=True, max_length=30)),
+ ('first_name', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)),
+ ('last_name', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)),
+ ('email', self.gf('django.db.models.fields.EmailField')(max_length=75, blank=True)),
+ ('is_staff', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('is_active', self.gf('django.db.models.fields.BooleanField')(default=True)),
+ ('date_joined', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
+ ('language', self.gf('django.db.models.fields.CharField')(default='en', max_length=2)),
+ ))
+ db.send_create_signal('p4l', ['User'])
+
+ # Adding M2M table for field groups on 'User'
+ db.create_table(u'p4l_user_groups', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('user', models.ForeignKey(orm['p4l.user'], null=False)),
+ ('group', models.ForeignKey(orm[u'auth.group'], null=False))
+ ))
+ db.create_unique(u'p4l_user_groups', ['user_id', 'group_id'])
+
+ # Adding M2M table for field user_permissions on 'User'
+ db.create_table(u'p4l_user_user_permissions', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('user', models.ForeignKey(orm['p4l.user'], null=False)),
+ ('permission', models.ForeignKey(orm[u'auth.permission'], null=False))
+ ))
+ db.create_unique(u'p4l_user_user_permissions', ['user_id', 'permission_id'])
+
+
+ def backwards(self, orm):
+ # Removing unique constraint on 'CorporateBody', fields ['label', 'acronym']
+ db.delete_unique(u'p4l_corporatebody', ['label', 'acronym'])
+
+ # Removing unique constraint on 'SubjectMeeting', fields ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
+ db.delete_unique(u'p4l_subjectmeeting', ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'])
+
+ # Removing unique constraint on 'RecordMeeting', fields ['record', 'meeting']
+ db.delete_unique(u'p4l_recordmeeting', ['record_id', 'meeting_id'])
+
+ # Removing unique constraint on 'Meeting', fields ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
+ db.delete_unique(u'p4l_meeting', ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'])
+
+ # Removing unique constraint on 'RecordPeriodical', fields ['record', 'periodical']
+ db.delete_unique(u'p4l_recordperiodical', ['record_id', 'periodical_id'])
+
+ # Removing unique constraint on 'CorporateAuthor', fields ['label', 'acronym']
+ db.delete_unique(u'p4l_corporateauthor', ['label', 'acronym'])
+
+ # Removing unique constraint on 'ProjectName', fields ['label', 'acronym']
+ db.delete_unique(u'p4l_projectname', ['label', 'acronym'])
+
+ # Removing unique constraint on 'RecordSerie', fields ['record', 'serie']
+ db.delete_unique(u'p4l_recordserie', ['record_id', 'serie_id'])
+
+ # Removing unique constraint on 'Serie', fields ['title', 'volume']
+ db.delete_unique(u'p4l_serie', ['title', 'volume'])
+
+ # Deleting model 'Imprint'
+ db.delete_table(u'p4l_imprint')
+
+ # Deleting model 'Serie'
+ db.delete_table(u'p4l_serie')
+
+ # Deleting model 'RecordSerie'
+ db.delete_table(u'p4l_recordserie')
+
+ # Deleting model 'ProjectName'
+ db.delete_table(u'p4l_projectname')
+
+ # Deleting model 'CorporateAuthor'
+ db.delete_table(u'p4l_corporateauthor')
+
+ # Deleting model 'Url'
+ db.delete_table(u'p4l_url')
+
+ # Deleting model 'Subject'
+ db.delete_table(u'p4l_subject')
+
+ # Deleting model 'Theme'
+ db.delete_table(u'p4l_theme')
+
+ # Deleting model 'Country'
+ db.delete_table(u'p4l_country')
+
+ # Deleting model 'Isbn'
+ db.delete_table(u'p4l_isbn')
+
+ # Deleting model 'Issn'
+ db.delete_table(u'p4l_issn')
+
+ # Deleting model 'DocumentCode'
+ db.delete_table(u'p4l_documentcode')
+
+ # Deleting model 'Language'
+ db.delete_table(u'p4l_language')
+
+ # Deleting model 'Title'
+ db.delete_table(u'p4l_title')
+
+ # Deleting model 'AddedTitle'
+ db.delete_table(u'p4l_addedtitle')
+
+ # Deleting model 'TitleMainDocument'
+ db.delete_table(u'p4l_titlemaindocument')
+
+ # Deleting model 'Abstract'
+ db.delete_table(u'p4l_abstract')
+
+ # Deleting model 'Collation'
+ db.delete_table(u'p4l_collation')
+
+ # Deleting model 'VolumeIssue'
+ db.delete_table(u'p4l_volumeissue')
+
+ # Deleting model 'Author'
+ db.delete_table(u'p4l_author')
+
+ # Deleting model 'SubjectPerson'
+ db.delete_table(u'p4l_subjectperson')
+
+ # Deleting model 'Periodical'
+ db.delete_table(u'p4l_periodical')
+
+ # Deleting model 'RecordPeriodical'
+ db.delete_table(u'p4l_recordperiodical')
+
+ # Deleting model 'Meeting'
+ db.delete_table(u'p4l_meeting')
+
+ # Deleting model 'RecordMeeting'
+ db.delete_table(u'p4l_recordmeeting')
+
+ # Deleting model 'SubjectMeeting'
+ db.delete_table(u'p4l_subjectmeeting')
+
+ # Deleting model 'CorporateBody'
+ db.delete_table(u'p4l_corporatebody')
+
+ # Deleting model 'Record'
+ db.delete_table(u'p4l_record')
+
+ # Removing M2M table for field subjects on 'Record'
+ db.delete_table('p4l_record_subjects')
+
+ # Removing M2M table for field themes on 'Record'
+ db.delete_table('p4l_record_themes')
+
+ # Removing M2M table for field countries on 'Record'
+ db.delete_table('p4l_record_countries')
+
+ # Removing M2M table for field otherLanguages on 'Record'
+ db.delete_table('p4l_record_otherLanguages')
+
+ # Removing M2M table for field projectNames on 'Record'
+ db.delete_table('p4l_record_projectNames')
+
+ # Removing M2M table for field authors on 'Record'
+ db.delete_table('p4l_record_authors')
+
+ # Removing M2M table for field subjectPersons on 'Record'
+ db.delete_table('p4l_record_subjectPersons')
+
+ # Removing M2M table for field subjectCorporateBodies on 'Record'
+ db.delete_table('p4l_record_subjectCorporateBodies')
+
+ # Removing M2M table for field subjectMeetings on 'Record'
+ db.delete_table('p4l_record_subjectMeetings')
+
+ # Removing M2M table for field corporateAuthors on 'Record'
+ db.delete_table('p4l_record_corporateAuthors')
+
+ # Deleting model 'User'
+ db.delete_table(u'p4l_user')
+
+ # Removing M2M table for field groups on 'User'
+ db.delete_table('p4l_user_groups')
+
+ # Removing M2M table for field user_permissions on 'User'
+ db.delete_table('p4l_user_user_permissions')
+
+
+ models = {
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'p4l.abstract': {
+ 'Meta': {'object_name': 'Abstract'},
+ 'abstract': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'abstracts'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.addedtitle': {
+ 'Meta': {'object_name': 'AddedTitle'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'addedTitles'", 'to': "orm['p4l.Record']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.author': {
+ 'Meta': {'object_name': 'Author'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.collation': {
+ 'Meta': {'object_name': 'Collation'},
+ 'collation': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'db_index': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'collations'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.corporateauthor': {
+ 'Meta': {'unique_together': "(['label', 'acronym'],)", 'object_name': 'CorporateAuthor'},
+ 'acronym': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.corporatebody': {
+ 'Meta': {'unique_together': "(['label', 'acronym'],)", 'object_name': 'CorporateBody'},
+ 'acronym': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.country': {
+ 'Meta': {'object_name': 'Country'},
+ 'country': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'p4l.documentcode': {
+ 'Meta': {'object_name': 'DocumentCode'},
+ 'documentCode': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documentCodes'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.imprint': {
+ 'Meta': {'object_name': 'Imprint'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imprintCity': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '512', 'null': 'True', 'blank': 'True'}),
+ 'imprintDate': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '512', 'null': 'True', 'blank': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'publisher': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '512', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'imprints'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.isbn': {
+ 'Meta': {'object_name': 'Isbn'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'isbn': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'isbns'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.issn': {
+ 'Meta': {'object_name': 'Issn'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'issn': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'issns'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.language': {
+ 'Meta': {'object_name': 'Language'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.meeting': {
+ 'Meta': {'unique_together': "(['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'],)", 'object_name': 'Meeting'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'}),
+ 'meetingDate': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingNumber': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingPlace': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingYear': ('django.db.models.fields.PositiveSmallIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+ },
+ 'p4l.periodical': {
+ 'Meta': {'object_name': 'Periodical'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.projectname': {
+ 'Meta': {'unique_together': "(['label', 'acronym'],)", 'object_name': 'ProjectName'},
+ 'acronym': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.record': {
+ 'Meta': {'object_name': 'Record'},
+ 'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Author']", 'symmetrical': 'False'}),
+ 'corporateAuthors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.CorporateAuthor']", 'symmetrical': 'False'}),
+ 'countries': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Country']", 'symmetrical': 'False'}),
+ 'editionStatement': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identifier': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'db_index': 'True'}),
+ 'isDocumentPart': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['p4l.Language']", 'null': 'True', 'blank': 'True'}),
+ 'meetings': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Meeting']", 'through': "orm['p4l.RecordMeeting']", 'symmetrical': 'False'}),
+ 'notes': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'otherLanguages': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'otherLanguage_record'", 'symmetrical': 'False', 'to': "orm['p4l.Language']"}),
+ 'periodicals': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Periodical']", 'through': "orm['p4l.RecordPeriodical']", 'symmetrical': 'False'}),
+ 'projectNames': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.ProjectName']", 'symmetrical': 'False'}),
+ 'recordType': ('django.db.models.fields.URLField', [], {'max_length': '2048'}),
+ 'series': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Serie']", 'through': "orm['p4l.RecordSerie']", 'symmetrical': 'False'}),
+ 'subjectCorporateBodies': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.CorporateBody']", 'symmetrical': 'False'}),
+ 'subjectMeetings': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.SubjectMeeting']", 'symmetrical': 'False'}),
+ 'subjectPersons': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.SubjectPerson']", 'symmetrical': 'False'}),
+ 'subjects': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Subject']", 'symmetrical': 'False'}),
+ 'themes': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['p4l.Theme']", 'symmetrical': 'False'}),
+ 'uri': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.recordmeeting': {
+ 'Meta': {'unique_together': "(['record', 'meeting'],)", 'object_name': 'RecordMeeting'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'meeting': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'records'", 'to': "orm['p4l.Meeting']"}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'meetings+'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.recordperiodical': {
+ 'Meta': {'unique_together': "(['record', 'periodical'],)", 'object_name': 'RecordPeriodical'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'periodical': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'records'", 'to': "orm['p4l.Periodical']"}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'periodicals+'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.recordserie': {
+ 'Meta': {'unique_together': "(['record', 'serie'],)", 'object_name': 'RecordSerie'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'series+'", 'to': "orm['p4l.Record']"}),
+ 'serie': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'records'", 'to': "orm['p4l.Serie']"})
+ },
+ 'p4l.serie': {
+ 'Meta': {'unique_together': "(['title', 'volume'],)", 'object_name': 'Serie'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'}),
+ 'volume': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'})
+ },
+ 'p4l.subject': {
+ 'Meta': {'object_name': 'Subject'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'subject': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.subjectmeeting': {
+ 'Meta': {'unique_together': "(['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'],)", 'object_name': 'SubjectMeeting'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'}),
+ 'meetingDate': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingNumber': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingPlace': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ 'meetingYear': ('django.db.models.fields.PositiveSmallIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+ },
+ 'p4l.subjectperson': {
+ 'Meta': {'object_name': 'SubjectPerson'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.theme': {
+ 'Meta': {'object_name': 'Theme'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'theme': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.title': {
+ 'Meta': {'object_name': 'Title'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'titles'", 'to': "orm['p4l.Record']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.titlemaindocument': {
+ 'Meta': {'object_name': 'TitleMainDocument'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'titlesMainDocument'", 'to': "orm['p4l.Record']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'})
+ },
+ 'p4l.url': {
+ 'Meta': {'object_name': 'Url'},
+ 'accessLevel': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '512', 'null': 'True', 'blank': 'True'}),
+ 'address': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'db_index': 'True'}),
+ 'display': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2048', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'urls'", 'to': "orm['p4l.Record']"})
+ },
+ 'p4l.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'language': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'p4l.volumeissue': {
+ 'Meta': {'object_name': 'VolumeIssue'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+ 'number': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+ 'record': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'volumeIssues'", 'to': "orm['p4l.Record']"}),
+ 'volume': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1024', 'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['p4l']
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/models/__init__.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,13 @@
+
+__all__ = ['Imprint', 'Serie', 'ProjectName', 'CorporateAuthor', 'Url',
+ 'Subject', 'Theme', 'Country', 'Isbn','Issn', 'DocumentCode',
+ 'Language', 'Title', 'AddedTitle', 'TitleMainDocument', 'Abstract'
+ 'Collation', 'VolumeIssue', 'Author', 'SubjectPerson', 'Periodical',
+ 'Meeting', 'SubjectMeeting', 'CorporateBody', 'Record', 'User']
+
+from p4l.models.data import (Imprint, Serie, ProjectName, CorporateAuthor, Url,
+ Subject, Theme, Country, Isbn, Issn, DocumentCode, Language, Title,
+ AddedTitle, TitleMainDocument, Abstract, Collation, VolumeIssue, Author,
+ SubjectPerson, Periodical, Meeting, SubjectMeeting, CorporateBody, Record)
+
+from p4l.models.user import User
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/models/common.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,11 @@
+from django.db import models
+
+class P4lModel(models.Model):
+ class Meta:
+ app_label = 'p4l'
+ abstract= True
+
+class P4lModelLang(P4lModel):
+ lang = models.CharField(max_length=15, blank=True, null=True, db_index=True) #@xml:lang
+ class Meta(P4lModel.Meta):
+ abstract= True
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/models/data.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,237 @@
+# -*- coding: utf-8 -*-
+
+from django.db import models
+from p4l.models.common import P4lModel, P4lModelLang
+
+
+class Imprint(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="imprints")
+ imprintCity = models.CharField(max_length=512, blank=True, null=True, db_index=True)
+ publisher = models.CharField(max_length=512, blank=True, null=True, db_index=True)
+ imprintDate = models.CharField(max_length=512, blank=True, null=True, db_index=True)
+
+
+class Serie(P4lModel):
+ title = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
+ volume = models.CharField(max_length=2048, blank=True, null=True, db_index=True)
+ class Meta(P4lModel.Meta):
+ unique_together = ['title', 'volume']
+
+class RecordSerie(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="series+")
+ serie = models.ForeignKey('p4l.Serie', related_name="records")
+ class Meta(P4lModelLang.Meta):
+ unique_together = ['record','serie']
+
+
+
+class ProjectName(P4lModel):
+ label = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
+ acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
+ class Meta(P4lModel.Meta):
+ unique_together = ['label', 'acronym']
+
+
+class CorporateAuthor(P4lModel):
+ label = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
+ acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
+ class Meta(P4lModel.Meta):
+ unique_together = ['label', 'acronym']
+
+
+class Url(P4lModel):
+ record = models.ForeignKey('p4l.Record', related_name="urls")
+ address = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #iiep:address
+ display = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:display
+ accessLevel = models.CharField(max_length=512, blank=True, null=True, db_index=True) #iiep:accessLevel
+
+
+class Subject(P4lModel):
+ subject = models.URLField(max_length=2048, unique=True, db_index=True)
+
+class Theme(P4lModel):
+ theme = models.URLField(max_length=2048, unique=True, db_index=True)
+
+
+class Country(P4lModel):
+ country = models.URLField(max_length=2048, unique=True, db_index=True)
+
+
+class Isbn(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="isbns")
+ isbn = models.CharField(max_length=128) #iiep:isbn
+
+
+class Issn(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="issns")
+ issn = models.CharField(max_length=128) #iiep:issn
+
+class DocumentCode(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="documentCodes")
+ documentCode = models.CharField(max_length=128) #iiep:issn
+
+class Language(P4lModel):
+ language = models.URLField(max_length=2048, unique=True, db_index=True)
+
+
+
+class BaseTitle(P4lModelLang):
+ title = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
+ class Meta(P4lModelLang.Meta):
+ abstract = True
+
+class Title(BaseTitle):
+ record = models.ForeignKey('p4l.Record', related_name="titles")
+
+class AddedTitle(BaseTitle):
+ record = models.ForeignKey('p4l.Record', related_name="addedTitles")
+
+class TitleMainDocument(BaseTitle):
+ record = models.ForeignKey('p4l.Record', related_name="titlesMainDocument")
+
+
+class Abstract(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="abstracts")
+ abstract = models.TextField(blank=True, null=True)
+
+
+class Collation(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="collations")
+ collation = models.CharField(max_length=1024, blank=False, null=False, db_index=True)
+
+
+class VolumeIssue(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="volumeIssues")
+ volume = models.CharField(max_length=1024, blank=True, null=True, db_index=True) #iiep:volume
+ number = models.CharField(max_length=1024, blank=True, null=True, db_index=True) #iiep:number
+
+
+class P4lPerson(P4lModel):
+ name = models.CharField(max_length=2048, blank=False, null=False, db_index=True, unique=True)
+ class Meta(P4lModel.Meta):
+ abstract = True
+
+
+class Author(P4lPerson):
+ pass
+
+class SubjectPerson(P4lPerson):
+ pass
+
+
+class Periodical(P4lModel):
+ label = models.CharField(max_length=2048, blank=False, null=False, db_index=True, unique=True) #iiep:periodical
+
+class RecordPeriodical(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="periodicals+")
+ periodical = models.ForeignKey('p4l.Periodical', related_name="records")
+ class Meta(P4lModelLang.Meta):
+ unique_together = ['record','periodical']
+
+
+class BaseMeeting(P4lModel):
+ label = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #rdfs:label
+ meetingNumber = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingNumber
+ meetingPlace = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingPlace
+ meetingDate = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingDate
+ meetingYear = models.PositiveSmallIntegerField(blank=True, null=True, db_index=True) #iiep:meetingYear
+ class Meta(P4lModel.Meta):
+ abstract = True
+ unique_together = ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
+
+
+class Meeting(BaseMeeting):
+ pass
+
+class RecordMeeting(P4lModelLang):
+ record = models.ForeignKey('p4l.Record', related_name="meetings+")
+ meeting = models.ForeignKey('p4l.Meeting', related_name="records")
+ class Meta(P4lModelLang.Meta):
+ unique_together = ['record','meeting']
+
+
+class SubjectMeeting(BaseMeeting):
+ pass
+
+
+class CorporateBody(P4lModel):
+ label = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #rdfs:label
+ acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
+ class Meta(P4lModel.Meta):
+ unique_together = ['label','acronym']
+
+class Record(P4lModel):
+ uri = models.URLField(max_length=2048, unique=True, db_index=True) #subject
+ subjects = models.ManyToManyField('p4l.Subject') #dct:subject
+ themes = models.ManyToManyField('p4l.Theme') #iiep:theme
+ countries = models.ManyToManyField('p4l.Country') #iiep:country
+ identifier = models.CharField(max_length=128, unique=True, db_index=True) #dct:identifier
+ notes = models.TextField(blank=True, null=True) #iiep:notes
+ #issns foreign key from Isbn #iiep:issn
+ #isbns foreign key from Isbn #iiep:isbn
+ #documentCodes foreign key from Isbn #iiep:documentCode
+ language = models.ForeignKey('p4l.Language', blank=True, null=True) #dct:language
+ otherLanguages = models.ManyToManyField('p4l.Language', related_name='otherLanguage_record') #iiep:otherLanguage
+ #titles foreign Key from Title #dct:title
+ #addedTitles foreign Key from AddedTitle #iiep:addedTitle
+ #titlesMainDocument foreign Key from TitleMainDocument #iiep:titleMainDocument
+ editionStatement = models.CharField(max_length=1024, blank=True, null=True) #iiep:editionStatement
+ #imprints foreign Key from Imprint #iiep:imprint
+ #collations = foreign Key from Collation #iiep:collation
+ #volumeIssues = foreign Key from VolumeIssue #iiep:volumeIssue
+ projectNames = models.ManyToManyField('p4l.ProjectName') #iiep:projectName
+ periodicals = models.ManyToManyField('p4l.Periodical', through='p4l.RecordPeriodical') #iiep:periodical
+ meetings = models.ManyToManyField('p4l.Meeting', through='p4l.RecordMeeting') #iiep:meeting
+ series = models.ManyToManyField('p4l.Serie', through='p4l.RecordSerie') #iiep:serie
+ authors = models.ManyToManyField('p4l.Author') #iiep:author
+ subjectPersons = models.ManyToManyField('p4l.SubjectPerson') #iiep:subjectPerson
+ subjectCorporateBodies = models.ManyToManyField('p4l.CorporateBody') #iiep:subjectCorporateBody
+ subjectMeetings = models.ManyToManyField('p4l.SubjectMeeting') #iiep:subjectMeeting
+ corporateAuthors = models.ManyToManyField('p4l.CorporateAuthor') #iiep:corporateAuthor
+ #urls foreign Key from Url #iiep:url
+ recordType = models.URLField(max_length=2048) #dct:type
+ isDocumentPart = models.BooleanField() #iiep:isDocumentPart
+
+ def __unicode__(self):
+ return "Record id %s { identifier: %s, uri: %s, editionStatement: %s, recordType: %s, isDocumentPart: %s, notes: %s, language : %s}" \
+ % (
+ self.id,
+ self.identifier,
+ self.uri,
+ self.editionStatement,
+ self.recordType,
+ self.isDocumentPart,
+ self.notes[:100] if self.notes else None,
+ self.language.id if self.language else None
+ )
+
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}issn', 3)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}documentCode', 3)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}country', 44)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}imprint', 5)
+#('{http://purl.org/dc/terms/}title', 4)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}isDocumentPart', 1)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}notes', 1)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}isbn', 8)
+#('{http://purl.org/dc/terms/}identifier', 1)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}meeting', 4)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}projectName', 10)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}addedTitle', 18)
+#('{http://purl.org/dc/terms/}subject', 29)
+#('{http://purl.org/dc/terms/}language', 1)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}serie', 4)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}volumeIssue', 3)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}url', 20)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}titleMainDocument', 3)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}otherLanguage', 13)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}periodical', 3)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}editionStatement', 1)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}collation', 4)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectMeeting', 6)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}corporateAuthor', 7)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}author', 26)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectPerson', 2)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectCorporateBody', 8)
+#('{http://www.iiep.unesco.org/plan4learning/model.owl#}theme', 6)
+#('{http://purl.org/dc/terms/}abstract', 3)
+#('{http://purl.org/dc/terms/}type', 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/models/user.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+'''
+Created on Aug 04, 2013
+
+@author: ymh
+'''
+from django.conf import settings
+from django.contrib.auth.models import AbstractUser
+from django.db import models
+from p4l.models.common import P4lModel
+
+class User(AbstractUser):
+ language = models.CharField(max_length=2, default=settings.LANGUAGE_CODE[:2])
+
+ class Meta:
+ app_label = 'p4l'
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/settings.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,169 @@
+# Django settings for p4l project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': '', # Or path to database file if using sqlite3.
+ # The following settings are not used with sqlite3:
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
+ 'PORT': '', # Set to empty string for default.
+ }
+}
+
+# Hosts/domain names that are valid for this site; required if DEBUG is False
+# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
+ALLOWED_HOSTS = []
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# In a Windows environment this must be set to your system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+ugettext = lambda s: s
+
+LANGUAGES = (
+ ('fr', ugettext('French')),
+ ('en', ugettext('English')),
+)
+
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale.
+USE_L10N = True
+
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/var/www/example.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://example.com/media/", "http://media.example.com/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/var/www/example.com/static/"
+STATIC_ROOT = ''
+
+# URL prefix for static files.
+# Example: "http://example.com/static/", "http://static.example.com/"
+STATIC_URL = '/static/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ # Uncomment the next line for simple clickjacking protection:
+ # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+)
+
+ROOT_URLCONF = 'p4l.urls'
+
+AUTH_USER_MODEL = 'p4l.User'
+INITIAL_CUSTOM_USER_MIGRATION = "0001_initial"
+
+
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'p4l.wsgi.application'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'django.contrib.admin',
+ 'south',
+ 'p4l'
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error when DEBUG=False.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'filters': ['require_debug_false'],
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
+
+from config import * # @UnusedWildImport
+
+if not "SRC_BASE_URL" in locals():
+ SRC_BASE_URL = BASE_URL + __name__.split('.')[0] + '/'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/urls.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,15 @@
+from django.conf.urls import patterns, include, url
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Examples:
+ # url(r'^$', 'p4l.views.home', name='home'),
+ # url(r'^p4l/', include('p4l.foo.urls')),
+
+ # Uncomment the admin/doc line below to enable admin documentation:
+ # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ url(r'^admin/', include(admin.site.urls)),
+)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/utils.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+import sys
+import codecs #@UnresolvedImport
+import math
+
+def show_progress(current_line, total_line, label, width, writer=None):
+
+ if writer is None:
+ writer = sys.stdout
+ if sys.stdout.encoding is not None:
+ writer = codecs.getwriter(sys.stdout.encoding)(sys.stdout)
+
+ percent = (float(current_line) / float(total_line)) * 100.0
+
+ marks = math.floor(width * (percent / 100.0)) #@UndefinedVariable
+ spaces = math.floor(width - marks) #@UndefinedVariable
+
+ loader = u'[' + (u'=' * int(marks)) + (u' ' * int(spaces)) + u']'
+
+ s = u"%s %3d%% %*d/%d - %*s\r" % (loader, percent, len(str(total_line)), current_line, total_line, width, label[:width])
+
+ writer.write(s) #takes the header into account
+ if percent >= 100:
+ writer.write("\n")
+ writer.flush()
+
+ return writer
+
+LANGUAGE_NS = u"http://psi.oasis-open.org/iso/639/#"
+LANGUAGE_URI_MAP = {u'roh': u'rm', u'sco': u'sco', u'scn': u'scn', u'rom': u'rom', u'ron': u'ro', u'oss': u'os', u'ale': u'ale', u'mni': u'mni', u'nwc': u'nwc', u'osa': u'osa', u'mnc': u'mnc', u'mwr': u'mwr', u'ven': u'ven', u'uga': u'uga', u'mwl': u'mwl', u'fas': u'fa', u'fat': u'fat', u'fan': u'fan', u'fao': u'fo', u'din': u'din', u'hye': u'hy', u'dsb': u'dsb', u'srd': u'sc', u'iba': u'iba', u'div': u'div', u'tel': u'te', u'tem': u'tem', u'nbl': u'nr', u'ter': u'ter', u'tet': u'tet', u'sun': u'su', u'kut': u'kut', u'suk': u'suk', u'kur': u'ku', u'kum': u'kum', u'sus': u'sus', u'new': u'new', u'nep': u'ne', u'sux': u'sux', u'men': u'men', u'lez': u'lez', u'gla': u'gd', u'bos': u'bs', u'gle': u'ga', u'eka': u'eka', u'glg': u'gl', u'akk': u'akk', u'aka': u'aka', u'bod': u'bo', u'glv': u'gv', u'jrb': u'jrb', u'vie': u'vi', u'ipk': u'ik', u'uzb': u'uz', u'sga': u'sga', u'bre': u'br', u'bra': u'bra', u'aym': u'ay', u'cha': u'ch', u'chb': u'chb', u'che': u'ce', u'chg': u'chg', u'chk': u'chk', u'chm': u'chm', u'chn': u'chn', u'cho': u'cho', u'chp': u'chp', u'chr': u'chr', u'chu': u'cu', u'chv': u'cv', u'chy': u'chy', u'msa': u'ms', u'iii': u'ii', u'ndo': u'ng', u'ibo': u'ibo', u'car': u'car', u'xho': u'xh', u'deu': u'de', u'cat': u'ca', u'del': u'del', u'den': u'den', u'cad': u'cad', u'tat': u'tt', u'srn': u'srn', u'raj': u'raj', u'spa': u'es', u'tam': u'ta', u'tah': u'ty', u'afh': u'afh', u'eng': u'en', u'enm': u'enm', u'csb': u'csb', u'nyn': u'nyn', u'nyo': u'nyo', u'sid': u'sid', u'nya': u'ny', u'sin': u'si', u'afr': u'af', u'lam': u'lam', u'snd': u'sd', u'mar': u'mr', u'lah': u'lah', u'sna': u'sn', u'lad': u'lad', u'snk': u'snk', u'mad': u'mad', u'mag': u'mag', u'lat': u'la', u'mah': u'mh', u'mak': u'mak', u'mal': u'ml', u'man': u'man', u'egy': u'egy', u'znd': u'znd', u'zen': u'zen', u'kbd': u'kbd', u'ita': u'it', u'tsn': u'tn', u'tso': u'ts', u'tsi': u'tsi', u'byn': u'byn', u'fij': u'fj', u'fin': u'fi', u'eus': u'eu', u'non': u'non', u'ceb': u'ceb', u'dan': u'da', u'nym': u'nym', u'nob': u'nb', u'dak': u'dak', u'ces': u'cs', u'dar': u'dar', u'day': u'day', u'nor': u'no', u'kpe': u'kpe', u'guj': u'gu', u'mdf': u'mdf', u'mas': u'mas', u'lao': u'lo', u'mdr': u'mdr', u'gon': u'gon', u'goh': u'goh', u'sms': u'sms', u'smo': u'sm', u'smn': u'smn', u'smj': u'smj', u'got': u'got', u'sme': u'se', u'bla': u'bla', u'sma': u'sma', u'gor': u'gor', u'ast': u'ast', u'orm': u'om', u'que': u'qu', u'ori': u'or', u'bal': u'bal', u'asm': u'as', u'pus': u'ps', u'kik': u'ki', u'ltz': u'lb', u'wln': u'wa', u'isl': u'is', u'mai': u'mai', u'lav': u'lv', u'zap': u'zap', u'yid': u'yi', u'kok': u'kok', u'kom': u'kv', u'kon': u'kon', u'ukr': u'uk', u'ton': u'to', u'kos': u'kos', u'kor': u'ko', u'tog': u'tog', u'hun': u'hu', u'hup': u'hup', u'cym': u'cy', u'udm': u'udm', u'bej': u'bej', u'ben': u'bn', u'bel': u'be', u'bem': u'bem', u'aar': u'aa', u'nzi': u'nzi', u'sah': u'sah', u'san': u'sa', u'sam': u'sam', u'pro': u'pro', u'sag': u'sg', u'sad': u'sad', u'rar': u'rar', u'rap': u'rap', u'sas': u'sas', u'sat': u'sat', u'min': u'min', u'lim': u'li', u'lin': u'ln', u'lit': u'lt', u'efi': u'efi', u'btk': u'btk', u'kac': u'kac', u'kab': u'kab', u'kaa': u'kaa', u'kan': u'kn', u'kam': u'kam', u'kal': u'kl', u'kas': u'ks', u'kar': u'kar', u'kaw': u'kaw', u'kau': u'kau', u'kat': u'ka', u'kaz': u'kk', u'tyv': u'tyv', u'awa': u'awa', u'urd': u'ur', u'doi': u'doi', u'tpi': u'tpi', u'mri': u'mi', u'abk': u'ab', u'tkl': u'tkl', u'nld': u'nl', u'oji': u'oji', u'oci': u'oc', u'wol': u'wo', u'jav': u'jv', u'hrv': u'hr', u'mga': u'mga', u'hit': u'hit', u'gez': u'gez', u'ssw': u'ss', u'hil': u'hil', u'him': u'him', u'hin': u'hi', u'bas': u'bas', u'gba': u'gba', u'bad': u'bad', u'kua': u'kj', u'cre': u'cre', u'ban': u'ban', u'crh': u'crh', u'bam': u'bam', u'bak': u'ba', u'shn': u'shn', u'arp': u'arp', u'arw': u'arw', u'ara': u'ar', u'arc': u'arc', u'sel': u'sel', u'arn': u'arn', u'lus': u'lus', u'mus': u'mus', u'lua': u'lua', u'lub': u'lub', u'lug': u'lug', u'lui': u'lui', u'lun': u'lun', u'luo': u'luo', u'iku': u'iu', u'tur': u'tr', u'tuk': u'tk', u'tum': u'tum', u'mkd': u'mk', u'cop': u'cop', u'cos': u'co', u'ile': u'ie', u'ilo': u'ilo', u'gwi': u'gwi', u'und': u'und', u'tli': u'tli', u'tlh': u'tlh', u'por': u'pt', u'pon': u'pon', u'pol': u'pl', u'ang': u'ang', u'tgk': u'tg', u'tgl': u'tl', u'fra': u'fr', u'fre': u'fr', u'dum': u'dum', u'swa': u'sw', u'dua': u'dua', u'swe': u'sv', u'yap': u'yap', u'frm': u'frm', u'tiv': u'tiv', u'yao': u'yao', u'xal': u'xal', u'fry': u'fy', u'gay': u'gay', u'ota': u'ota', u'hmn': u'hmn', u'hmo': u'ho', u'an': u'arg', u'gaa': u'gaa', u'fur': u'fur', u'mlg': u'mg', u'slv': u'sl', u'fil': u'fil', u'mlt': u'mt', u'slk': u'sk', u'ful': u'ful', u'jpn': u'ja', u'vol': u'vo', u'vot': u'vot', u'ind': u'id', u'ave': u'ae', u'jpr': u'jpr', u'ava': u'ava', u'pap': u'pap', u'ewo': u'ewo', u'pau': u'pau', u'ewe': u'ewe', u'pag': u'pag', u'pal': u'pal', u'pam': u'pam', u'pan': u'pa', u'nog': u'nog', u'phn': u'phn', u'kir': u'ky', u'nia': u'nia', u'dgr': u'dgr', u'syr': u'syr', u'kin': u'rw', u'niu': u'niu', u'epo': u'eo', u'jbo': u'jbo', u'mic': u'mic', u'tha': u'th', u'hai': u'hai', u'gmh': u'gmh', u'ell': u'el', u'ady': u'ady', u'elx': u'elx', u'ada': u'ada', u'nav': u'nv', u'hat': u'ht', u'hau': u'ha', u'haw': u'haw', u'bin': u'bin', u'amh': u'am', u'bik': u'bik', u'bih': u'bh', u'mos': u'mos', u'moh': u'moh', u'mon': u'mn', u'bho': u'bho', u'mol': u'mo', u'bis': u'bi', u'tvl': u'tvl', u'ijo': u'ijo', u'est': u'et', u'kmb': u'kmb', u'peo': u'peo', u'umb': u'umb', u'tmh': u'tmh', u'fon': u'fon', u'hsb': u'hsb', u'run': u'rn', u'rus': u'ru', u'pli': u'pi', u'ace': u'ace', u'ach': u'ach', u'nde': u'nd', u'dzo': u'dz', u'kru': u'kru', u'srr': u'srr', u'ido': u'io', u'srp': u'sr', u'kro': u'kro', u'krc': u'krc', u'nds': u'nds', u'zun': u'zun', u'zul': u'zu', u'twi': u'tw', u'sog': u'sog', u'nso': u'nso', u'fro': u'fro', u'som': u'so', u'son': u'son', u'sot': u'st', u'vai': u'vai', u'her': u'hz', u'lol': u'lol', u'heb': u'he', u'loz': u'loz', u'gil': u'gil', u'was': u'was', u'war': u'war', u'bul': u'bg', u'wal': u'wal', u'bua': u'bua', u'bug': u'bug', u'aze': u'az', u'zha': u'za', u'zho': u'zh', u'nno': u'nn', u'uig': u'ug', u'myv': u'myv', u'inh': u'inh', u'khm': u'km', u'kho': u'kho', u'mya': u'my', u'kha': u'kha', u'ina': u'ia', u'nah': u'nah', u'tir': u'ti', u'nap': u'nap', u'grb': u'grb', u'grc': u'grc', u'nau': u'na', u'grn': u'gn', u'tig': u'tig', u'yor': u'yo', u'cor': u'kw', u'sqi': u'sq', u'dyu': u'dyu'}
+
+def get_code_from_language_uri(lang_uri):
+
+ if not lang_uri:
+ return None
+ if lang_uri.startswith(LANGUAGE_NS):
+ lang_uri = lang_uri[len(LANGUAGE_NS):]
+
+ return LANGUAGE_URI_MAP.get(lang_uri, None)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/wsgi.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,32 @@
+"""
+WSGI config for p4l project.
+
+This module contains the WSGI application used by Django's development server
+and any production WSGI deployments. It should expose a module-level variable
+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
+this application via the ``WSGI_APPLICATION`` setting.
+
+Usually you will have the standard Django WSGI application here, but it also
+might make sense to replace the whole Django WSGI application with a custom one
+that later delegates to the Django one. For example, you could introduce WSGI
+middleware here, or combine a Django application with an application of another
+framework.
+
+"""
+import os
+
+# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
+# if running multiple sites in the same mod_wsgi process. To fix this, use
+# mod_wsgi daemon mode with each site in its own daemon process, or use
+# os.environ["DJANGO_SETTINGS_MODULE"] = "p4l.settings"
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "p4l.settings")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/res/lib/lib_create_env.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,305 @@
+import sys
+import os
+import os.path
+import shutil
+import tarfile
+import zipfile
+import urllib
+import platform
+import patch
+import struct
+import glob
+import re
+
+join = os.path.join
+system_str = platform.system()
+
+URLS = {
+ #'': {'setup': '', 'url':'', 'local':''},
+ 'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz', 'local':"distribute-0.6.34.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'DJANGO': {'setup': 'django', 'url': 'https://github.com/IRI-Research/django/archive/698eff4a5da55a1b5a8b4ecddab2b2a85854d4da.tar.gz', 'local':"Django-1.5.2.dev20130524113953.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.3.0.tar.gz', 'local': 'six-1.3.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/archive/1.1.1.tar.gz', 'local':"django-extensions-1.1.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.7.6.tar.gz', 'local':"south-0.7.6.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'RDFLIB' : {'setup':'rdflib', 'url':'https://github.com/RDFLib/rdflib/archive/4.0.1.tar.gz', 'local': 'rdflib-4.0.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v1.2.3.tar.gz', 'local':'requests-1.2.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'SIMPLEJSON': {'setup': 'simplejson','url':'https://github.com/simplejson/simplejson/archive/v3.3.0.tar.gz', 'local': 'simplejson-3.3.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'ISODATE': {'setup': 'isodate','url':'https://pypi.python.org/packages/source/i/isodate/isodate-0.4.9.tar.gz', 'local': 'isodate-0.4.9.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'PYPARSING': {'setup': 'pyparsing','url':'http://downloads.sourceforge.net/project/pyparsing/pyparsing/pyparsing-1.5.7/pyparsing-1.5.7.tar.gz', 'local': 'pyparsing-1.5.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'SPARQLWRAPPER': {'setup': 'sparqlwrapper','url':'http://downloads.sourceforge.net/project/sparql-wrapper/sparql-wrapper-python/1.5.2/SPARQLWrapper-1.5.2.tar.gz', 'local': 'SPARQLWrapper-1.5.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'HTML5LIB': {'setup': 'html5lib','url':'https://github.com/html5lib/html5lib-python/archive/1.0b1.tar.gz', 'local': 'html5lib-python-1.0b1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+ 'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.tar.gz', 'local':"psycopg2-2.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
+}
+
+class ResourcesEnv(object):
+
+ def __init__(self, src_base, urls, normal_installs):
+ self.src_base = src_base
+ self.URLS = {}
+ self.__init_url(urls)
+ self.NORMAL_INSTALL = normal_installs
+
+ def get_src_base_path(self, fpath):
+ return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
+
+ def __add_package_def(self, key, dict):
+ self.URLS[key] = dict
+
+ def __init_url(self, urls):
+ for key, url_dict in urls.items():
+ url_dict_copy = url_dict.copy()
+ if not url_dict['url'].startswith("http://"):
+ url_dict_copy['url'] = self.get_src_base_path(url_dict['url'])
+ url_dict_copy['local'] = self.get_src_base_path(url_dict['local'])
+
+ self.__add_package_def(key, url_dict_copy )
+
+def ensure_dir(dir, logger):
+ logger.notify('Check directory %s' % dir)
+ if not os.path.exists(dir):
+ logger.notify('Creating directory %s' % dir)
+ os.makedirs(dir)
+
+def extend_parser(parser):
+ parser.add_option(
+ '--index-url',
+ metavar='INDEX_URL',
+ dest='index_url',
+ default='http://pypi.python.org/simple/',
+ help='base URL of Python Package Index')
+ parser.add_option(
+ '--type-install',
+ metavar='type_install',
+ dest='type_install',
+ help='type install : local, url, setup - default : local')
+ parser.add_option(
+ '--ignore-packages',
+ metavar='ignore_packages',
+ dest='ignore_packages',
+ default=None,
+ help='list of comma separated keys for package to ignore')
+
+def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
+ psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
+ shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
+ #extract psycopg2
+ zf = zipfile.ZipFile(psycopg2_src)
+ psycopg2_base_path = os.path.join(src_dir,"psycopg2")
+ zf.extractall(psycopg2_base_path)
+ zf.close()
+
+ psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
+ shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
+ shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.4.5-py2.7.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages')))
+
+
+def install_mysql(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
+
+ args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]
+ if option_str :
+ args.insert(4,option_str)
+ call_subprocess(args,
+ cwd=os.path.abspath(tmp_dir),
+ filter_stdout=filter_python_develop,
+ show_stdout=True,
+ extra_env=extra_env)
+
+ mysqlconfig_output = []
+
+ call_subprocess(['mysql_config', '--libmysqld-libs'],
+ cwd=os.path.abspath(tmp_dir),
+ filter_stdout=lambda line: mysqlconfig_output.append(line),
+ show_stdout=True)
+
+ mysqlconfig_output = "".join(mysqlconfig_output)
+ m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
+ if m:
+ repdylibpath = m.group(1)
+ else:
+ repdylibpath = '/usr/local/mysql/lib'
+
+ dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
+ def key_func(s):
+ m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
+ if m:
+ return int(m.group(1))
+ else:
+ return sys.maxint
+ dyliblist.sort(key=key_func)
+
+ if dyliblist:
+ dylibpath = dyliblist[0]
+ else:
+ dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
+
+ dylibname = os.path.basename(dylibpath)
+ sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
+
+ call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
+ cwd=os.path.abspath(tmp_dir),
+ filter_stdout=filter_python_develop,
+ show_stdout=True)
+
+
+def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
+
+ def install_lib(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
+ lib_src = os.path.join(src_dir,lib_name+".tar.gz")
+ logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
+ shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
+ tf = tarfile.open(lib_src,'r:gz')
+ lib_base_path = os.path.join(src_dir, lib_name)
+ logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
+ tf.extractall(lib_base_path)
+ tf.close()
+
+ lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
+
+ logger.notify(lib_name + " configure in " + lib_src_path)
+ call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
+ cwd=os.path.abspath(lib_src_path),
+ filter_stdout=filter_python_develop,
+ show_stdout=True)
+
+ logger.notify(lib_name + " make in " + lib_src_path)
+ call_subprocess(['make'],
+ cwd=os.path.abspath(lib_src_path),
+ filter_stdout=filter_python_develop,
+ show_stdout=True)
+
+ logger.notify(lib_name + "make install in " + lib_src_path)
+ call_subprocess(['make', 'install'],
+ cwd=os.path.abspath(lib_src_path),
+ filter_stdout=filter_python_develop,
+ show_stdout=True)
+ return install_lib
+
+install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'])
+install_zlib = gen_install_comp_lib("zlib", "ZLIB", [])
+
+
+def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
+
+ all_urls = URLS.copy()
+ if urls is not None:
+ all_urls.update(urls)
+
+ res_env = ResourcesEnv(src_base, all_urls, normal_installs)
+
+ def filter_python_develop(line):
+ if not line.strip():
+ return Logger.DEBUG
+ for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
+ 'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
+ 'creating ', 'Copying ']:
+ if line.startswith(prefix):
+ return Logger.DEBUG
+ return Logger.NOTIFY
+
+
+ def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
+ logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method))
+ if method == 'pip':
+ if sys.platform == 'win32':
+ args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_env.URLS[key][res_source_key]]
+ else:
+ args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS[key][res_source_key]]
+ if option_str :
+ args.insert(4,option_str)
+ if key == 'local':
+ if extra_env is None:
+ extra_env = {}
+ extra_env.append("PIP_DOWNLOAD_CACHE", res_env.get_src_base_path(""))
+ call_subprocess(args,
+ cwd=os.path.abspath(tmp_dir),
+ filter_stdout=filter_python_develop,
+ show_stdout=True,
+ extra_env=extra_env)
+ else:
+ if sys.platform == 'win32':
+ args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]]
+ else:
+ args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]]
+ if option_str :
+ args.insert(1,option_str)
+ call_subprocess(args,
+ cwd=os.path.abspath(tmp_dir),
+ filter_stdout=filter_python_develop,
+ show_stdout=True,
+ extra_env=extra_env)
+
+
+ def after_install(options, home_dir):
+
+ global logger
+
+ verbosity = options.verbose - options.quiet
+ logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
+
+
+ home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
+ base_dir = os.path.dirname(home_dir)
+ src_dir = os.path.join(home_dir, 'src')
+ tmp_dir = os.path.join(home_dir, 'tmp')
+ ensure_dir(src_dir, logger)
+ ensure_dir(tmp_dir, logger)
+ system_str = platform.system()
+
+ res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
+ if res_source_key is None:
+ res_source_key = 'local'
+
+ ignore_packages = []
+
+ if system_str == 'Windows':
+ default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
+ else:
+ default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
+
+ if options.ignore_packages :
+ ignore_packages = options.ignore_packages.split(",")
+
+ logger.indent += 2
+ try:
+ for key in res_env.NORMAL_INSTALL:
+ if key not in res_env.URLS:
+ logger.notify("%s not found in def : passing" % (key,))
+ install_options = res_env.URLS[key].get('install', None)
+ if install_options is None:
+ install_options = default_install_options
+ method = install_options.get('method', default_install_options['method'])
+ option_str = install_options.get('option_str', default_install_options['option_str'])
+ extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
+ if not extra_env:
+ extra_env = {}
+
+ if 'TMPDIR' not in extra_env:
+ extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
+ #isinstance(lst, (list, tuple))
+ if key not in ignore_packages:
+ logger.notify("install %s with method %s" % (key, repr(method)))
+ if callable(method):
+ method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
+ elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:
+ globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
+ else:
+ normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
+
+ logger.notify("Clear source dir")
+ shutil.rmtree(src_dir)
+
+ finally:
+ logger.indent -= 2
+ script_dir = join(base_dir, bin_dir)
+ logger.notify('Run "%s Package" to install new packages that provide builds'
+ % join(script_dir, 'easy_install'))
+
+ def adjust_options(options, args):
+ if not options_to_add:
+ pass
+ for opt in options_to_add:
+ test_opt = opt.split('=',1)[0]
+ #if not hasattr(options,test_opt) or getattr(options, test_opt) is None:
+ setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
+
+ return adjust_options, extend_parser, after_install
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/res/lib/patch.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,589 @@
+""" Patch utility to apply unified diffs
+
+ Brute-force line-by-line non-recursive parsing
+
+ Copyright (c) 2008-2010 anatoly techtonik
+ Available under the terms of MIT license
+
+ Project home: http://code.google.com/p/python-patch/
+
+
+ $Id: patch.py 76 2010-04-08 19:10:21Z techtonik $
+ $HeadURL: https://python-patch.googlecode.com/svn/trunk/patch.py $
+"""
+
+__author__ = "techtonik.rainforce.org"
+__version__ = "10.04"
+
+import copy
+import logging
+import re
+# cStringIO doesn't support unicode in 2.5
+from StringIO import StringIO
+from logging import debug, info, warning
+
+from os.path import exists, isfile, abspath
+from os import unlink
+
+
+#------------------------------------------------
+# Logging is controlled by "python_patch" logger
+
+debugmode = False
+
+logger = logging.getLogger("python_patch")
+loghandler = logging.StreamHandler()
+logger.addHandler(loghandler)
+
+debug = logger.debug
+info = logger.info
+warning = logger.warning
+
+#: disable library logging by default
+logger.setLevel(logging.CRITICAL)
+
+#------------------------------------------------
+
+
+def fromfile(filename):
+ """ Parse patch file and return Patch() object
+ """
+
+ info("reading patch from file %s" % filename)
+ fp = open(filename, "rb")
+ patch = Patch(fp)
+ fp.close()
+ return patch
+
+
+def fromstring(s):
+ """ Parse text string and return Patch() object
+ """
+
+ return Patch(
+ StringIO.StringIO(s)
+ )
+
+
+
+class HunkInfo(object):
+ """ Parsed hunk data container (hunk starts with @@ -R +R @@) """
+
+ def __init__(self):
+ self.startsrc=None #: line count starts with 1
+ self.linessrc=None
+ self.starttgt=None
+ self.linestgt=None
+ self.invalid=False
+ self.text=[]
+
+ def copy(self):
+ return copy.copy(self)
+
+# def apply(self, estream):
+# """ write hunk data into enumerable stream
+# return strings one by one until hunk is
+# over
+#
+# enumerable stream are tuples (lineno, line)
+# where lineno starts with 0
+# """
+# pass
+
+
+
+class Patch(object):
+
+ def __init__(self, stream=None):
+
+ # define Patch data members
+ # table with a row for every source file
+
+ #: list of source filenames
+ self.source=None
+ self.target=None
+ #: list of lists of hunks
+ self.hunks=None
+ #: file endings statistics for every hunk
+ self.hunkends=None
+
+ if stream:
+ self.parse(stream)
+
+ def copy(self):
+ return copy.copy(self)
+
+ def parse(self, stream):
+ """ parse unified diff """
+ self.source = []
+ self.target = []
+ self.hunks = []
+ self.hunkends = []
+
+ # define possible file regions that will direct the parser flow
+ header = False # comments before the patch body
+ filenames = False # lines starting with --- and +++
+
+ hunkhead = False # @@ -R +R @@ sequence
+ hunkbody = False #
+ hunkskip = False # skipping invalid hunk mode
+
+ header = True
+ lineends = dict(lf=0, crlf=0, cr=0)
+ nextfileno = 0
+ nexthunkno = 0 #: even if index starts with 0 user messages number hunks from 1
+
+ # hunkinfo holds parsed values, hunkactual - calculated
+ hunkinfo = HunkInfo()
+ hunkactual = dict(linessrc=None, linestgt=None)
+
+ fe = enumerate(stream)
+ for lineno, line in fe:
+
+ # analyze state
+ if header and line.startswith("--- "):
+ header = False
+ # switch to filenames state
+ filenames = True
+ #: skip hunkskip and hunkbody code until you read definition of hunkhead
+ if hunkbody:
+ # process line first
+ if re.match(r"^[- \+\\]", line):
+ # gather stats about line endings
+ if line.endswith("\r\n"):
+ self.hunkends[nextfileno-1]["crlf"] += 1
+ elif line.endswith("\n"):
+ self.hunkends[nextfileno-1]["lf"] += 1
+ elif line.endswith("\r"):
+ self.hunkends[nextfileno-1]["cr"] += 1
+
+ if line.startswith("-"):
+ hunkactual["linessrc"] += 1
+ elif line.startswith("+"):
+ hunkactual["linestgt"] += 1
+ elif not line.startswith("\\"):
+ hunkactual["linessrc"] += 1
+ hunkactual["linestgt"] += 1
+ hunkinfo.text.append(line)
+ # todo: handle \ No newline cases
+ else:
+ warning("invalid hunk no.%d at %d for target file %s" % (nexthunkno, lineno+1, self.target[nextfileno-1]))
+ # add hunk status node
+ self.hunks[nextfileno-1].append(hunkinfo.copy())
+ self.hunks[nextfileno-1][nexthunkno-1]["invalid"] = True
+ # switch to hunkskip state
+ hunkbody = False
+ hunkskip = True
+
+ # check exit conditions
+ if hunkactual["linessrc"] > hunkinfo.linessrc or hunkactual["linestgt"] > hunkinfo.linestgt:
+ warning("extra hunk no.%d lines at %d for target %s" % (nexthunkno, lineno+1, self.target[nextfileno-1]))
+ # add hunk status node
+ self.hunks[nextfileno-1].append(hunkinfo.copy())
+ self.hunks[nextfileno-1][nexthunkno-1]["invalid"] = True
+ # switch to hunkskip state
+ hunkbody = False
+ hunkskip = True
+ elif hunkinfo.linessrc == hunkactual["linessrc"] and hunkinfo.linestgt == hunkactual["linestgt"]:
+ self.hunks[nextfileno-1].append(hunkinfo.copy())
+ # switch to hunkskip state
+ hunkbody = False
+ hunkskip = True
+
+ # detect mixed window/unix line ends
+ ends = self.hunkends[nextfileno-1]
+ if ((ends["cr"]!=0) + (ends["crlf"]!=0) + (ends["lf"]!=0)) > 1:
+ warning("inconsistent line ends in patch hunks for %s" % self.source[nextfileno-1])
+ if debugmode:
+ debuglines = dict(ends)
+ debuglines.update(file=self.target[nextfileno-1], hunk=nexthunkno)
+ debug("crlf: %(crlf)d lf: %(lf)d cr: %(cr)d\t - file: %(file)s hunk: %(hunk)d" % debuglines)
+
+ if hunkskip:
+ match = re.match("^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))?", line)
+ if match:
+ # switch to hunkhead state
+ hunkskip = False
+ hunkhead = True
+ elif line.startswith("--- "):
+ # switch to filenames state
+ hunkskip = False
+ filenames = True
+ if debugmode and len(self.source) > 0:
+ debug("- %2d hunks for %s" % (len(self.hunks[nextfileno-1]), self.source[nextfileno-1]))
+
+ if filenames:
+ if line.startswith("--- "):
+ if nextfileno in self.source:
+ warning("skipping invalid patch for %s" % self.source[nextfileno])
+ del self.source[nextfileno]
+ # double source filename line is encountered
+ # attempt to restart from this second line
+ re_filename = "^--- ([^\t]+)"
+ match = re.match(re_filename, line)
+ # todo: support spaces in filenames
+ if match:
+ self.source.append(match.group(1).strip())
+ else:
+ warning("skipping invalid filename at line %d" % lineno)
+ # switch back to header state
+ filenames = False
+ header = True
+ elif not line.startswith("+++ "):
+ if nextfileno in self.source:
+ warning("skipping invalid patch with no target for %s" % self.source[nextfileno])
+ del self.source[nextfileno]
+ else:
+ # this should be unreachable
+ warning("skipping invalid target patch")
+ filenames = False
+ header = True
+ else:
+ if nextfileno in self.target:
+ warning("skipping invalid patch - double target at line %d" % lineno)
+ del self.source[nextfileno]
+ del self.target[nextfileno]
+ nextfileno -= 1
+ # double target filename line is encountered
+ # switch back to header state
+ filenames = False
+ header = True
+ else:
+ re_filename = "^\+\+\+ ([^\t]+)"
+ match = re.match(re_filename, line)
+ if not match:
+ warning("skipping invalid patch - no target filename at line %d" % lineno)
+ # switch back to header state
+ filenames = False
+ header = True
+ else:
+ self.target.append(match.group(1).strip())
+ nextfileno += 1
+ # switch to hunkhead state
+ filenames = False
+ hunkhead = True
+ nexthunkno = 0
+ self.hunks.append([])
+ self.hunkends.append(lineends.copy())
+ continue
+
+ if hunkhead:
+ match = re.match("^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))?", line)
+ if not match:
+ if nextfileno-1 not in self.hunks:
+ warning("skipping invalid patch with no hunks for file %s" % self.target[nextfileno-1])
+ # switch to header state
+ hunkhead = False
+ header = True
+ continue
+ else:
+ # switch to header state
+ hunkhead = False
+ header = True
+ else:
+ hunkinfo.startsrc = int(match.group(1))
+ hunkinfo.linessrc = 1
+ if match.group(3): hunkinfo.linessrc = int(match.group(3))
+ hunkinfo.starttgt = int(match.group(4))
+ hunkinfo.linestgt = 1
+ if match.group(6): hunkinfo.linestgt = int(match.group(6))
+ hunkinfo.invalid = False
+ hunkinfo.text = []
+
+ hunkactual["linessrc"] = hunkactual["linestgt"] = 0
+
+ # switch to hunkbody state
+ hunkhead = False
+ hunkbody = True
+ nexthunkno += 1
+ continue
+ else:
+ if not hunkskip:
+ warning("patch file incomplete - %s" % filename)
+ # sys.exit(?)
+ else:
+ # duplicated message when an eof is reached
+ if debugmode and len(self.source) > 0:
+ debug("- %2d hunks for %s" % (len(self.hunks[nextfileno-1]), self.source[nextfileno-1]))
+
+ info("total files: %d total hunks: %d" % (len(self.source), sum(len(hset) for hset in self.hunks)))
+
+
+ def apply(self):
+ """ apply parsed patch """
+
+ total = len(self.source)
+ for fileno, filename in enumerate(self.source):
+
+ f2patch = filename
+ if not exists(f2patch):
+ f2patch = self.target[fileno]
+ if not exists(f2patch):
+ warning("source/target file does not exist\n--- %s\n+++ %s" % (filename, f2patch))
+ continue
+ if not isfile(f2patch):
+ warning("not a file - %s" % f2patch)
+ continue
+ filename = f2patch
+
+ info("processing %d/%d:\t %s" % (fileno+1, total, filename))
+
+ # validate before patching
+ f2fp = open(filename)
+ hunkno = 0
+ hunk = self.hunks[fileno][hunkno]
+ hunkfind = []
+ hunkreplace = []
+ validhunks = 0
+ canpatch = False
+ for lineno, line in enumerate(f2fp):
+ if lineno+1 < hunk.startsrc:
+ continue
+ elif lineno+1 == hunk.startsrc:
+ hunkfind = [x[1:].rstrip("\r\n") for x in hunk.text if x[0] in " -"]
+ hunkreplace = [x[1:].rstrip("\r\n") for x in hunk.text if x[0] in " +"]
+ #pprint(hunkreplace)
+ hunklineno = 0
+
+ # todo \ No newline at end of file
+
+ # check hunks in source file
+ if lineno+1 < hunk.startsrc+len(hunkfind)-1:
+ if line.rstrip("\r\n") == hunkfind[hunklineno]:
+ hunklineno+=1
+ else:
+ debug("hunk no.%d doesn't match source file %s" % (hunkno+1, filename))
+ # file may be already patched, but we will check other hunks anyway
+ hunkno += 1
+ if hunkno < len(self.hunks[fileno]):
+ hunk = self.hunks[fileno][hunkno]
+ continue
+ else:
+ break
+
+ # check if processed line is the last line
+ if lineno+1 == hunk.startsrc+len(hunkfind)-1:
+ debug("file %s hunk no.%d -- is ready to be patched" % (filename, hunkno+1))
+ hunkno+=1
+ validhunks+=1
+ if hunkno < len(self.hunks[fileno]):
+ hunk = self.hunks[fileno][hunkno]
+ else:
+ if validhunks == len(self.hunks[fileno]):
+ # patch file
+ canpatch = True
+ break
+ else:
+ if hunkno < len(self.hunks[fileno]):
+ warning("premature end of source file %s at hunk %d" % (filename, hunkno+1))
+
+ f2fp.close()
+
+ if validhunks < len(self.hunks[fileno]):
+ if self._match_file_hunks(filename, self.hunks[fileno]):
+ warning("already patched %s" % filename)
+ else:
+ warning("source file is different - %s" % filename)
+ if canpatch:
+ backupname = filename+".orig"
+ if exists(backupname):
+ warning("can't backup original file to %s - aborting" % backupname)
+ else:
+ import shutil
+ shutil.move(filename, backupname)
+ if self.write_hunks(backupname, filename, self.hunks[fileno]):
+ warning("successfully patched %s" % filename)
+ unlink(backupname)
+ else:
+ warning("error patching file %s" % filename)
+ shutil.copy(filename, filename+".invalid")
+ warning("invalid version is saved to %s" % filename+".invalid")
+ # todo: proper rejects
+ shutil.move(backupname, filename)
+
+ # todo: check for premature eof
+
+
+ def can_patch(self, filename):
+ """ Check if specified filename can be patched. Returns None if file can
+ not be found among source filenames. False if patch can not be applied
+ clearly. True otherwise.
+
+ :returns: True, False or None
+ """
+ idx = self._get_file_idx(filename, source=True)
+ if idx == None:
+ return None
+ return self._match_file_hunks(filename, self.hunks[idx])
+
+
+ def _match_file_hunks(self, filepath, hunks):
+ matched = True
+ fp = open(abspath(filepath))
+
+ class NoMatch(Exception):
+ pass
+
+ lineno = 1
+ line = fp.readline()
+ hno = None
+ try:
+ for hno, h in enumerate(hunks):
+ # skip to first line of the hunk
+ while lineno < h.starttgt:
+ if not len(line): # eof
+ debug("check failed - premature eof before hunk: %d" % (hno+1))
+ raise NoMatch
+ line = fp.readline()
+ lineno += 1
+ for hline in h.text:
+ if hline.startswith("-"):
+ continue
+ if not len(line):
+ debug("check failed - premature eof on hunk: %d" % (hno+1))
+ # todo: \ No newline at the end of file
+ raise NoMatch
+ if line.rstrip("\r\n") != hline[1:].rstrip("\r\n"):
+ debug("file is not patched - failed hunk: %d" % (hno+1))
+ raise NoMatch
+ line = fp.readline()
+ lineno += 1
+
+ except NoMatch:
+ matched = False
+ # todo: display failed hunk, i.e. expected/found
+
+ fp.close()
+ return matched
+
+
+ def patch_stream(self, instream, hunks):
+ """ Generator that yields stream patched with hunks iterable
+
+ Converts lineends in hunk lines to the best suitable format
+ autodetected from input
+ """
+
+ # todo: At the moment substituted lineends may not be the same
+ # at the start and at the end of patching. Also issue a
+ # warning/throw about mixed lineends (is it really needed?)
+
+ hunks = iter(hunks)
+
+ srclineno = 1
+
+ lineends = {'\n':0, '\r\n':0, '\r':0}
+ def get_line():
+ """
+ local utility function - return line from source stream
+ collecting line end statistics on the way
+ """
+ line = instream.readline()
+ # 'U' mode works only with text files
+ if line.endswith("\r\n"):
+ lineends["\r\n"] += 1
+ elif line.endswith("\n"):
+ lineends["\n"] += 1
+ elif line.endswith("\r"):
+ lineends["\r"] += 1
+ return line
+
+ for hno, h in enumerate(hunks):
+ debug("hunk %d" % (hno+1))
+ # skip to line just before hunk starts
+ while srclineno < h.startsrc:
+ yield get_line()
+ srclineno += 1
+
+ for hline in h.text:
+ # todo: check \ No newline at the end of file
+ if hline.startswith("-") or hline.startswith("\\"):
+ get_line()
+ srclineno += 1
+ continue
+ else:
+ if not hline.startswith("+"):
+ get_line()
+ srclineno += 1
+ line2write = hline[1:]
+ # detect if line ends are consistent in source file
+ if sum([bool(lineends[x]) for x in lineends]) == 1:
+ newline = [x for x in lineends if lineends[x] != 0][0]
+ yield line2write.rstrip("\r\n")+newline
+ else: # newlines are mixed
+ yield line2write
+
+ for line in instream:
+ yield line
+
+
+ def write_hunks(self, srcname, tgtname, hunks):
+ src = open(srcname, "rb")
+ tgt = open(tgtname, "wb")
+
+ debug("processing target file %s" % tgtname)
+
+ tgt.writelines(self.patch_stream(src, hunks))
+
+ tgt.close()
+ src.close()
+ return True
+
+
+ def _get_file_idx(self, filename, source=None):
+ """ Detect index of given filename within patch.
+
+ :param filename:
+ :param source: search filename among sources (True),
+ targets (False), or both (None)
+ :returns: int or None
+ """
+ filename = abspath(filename)
+ if source == True or source == None:
+ for i,fnm in enumerate(self.source):
+ if filename == abspath(fnm):
+ return i
+ if source == False or source == None:
+ for i,fnm in enumerate(self.target):
+ if filename == abspath(fnm):
+ return i
+
+
+
+
+from optparse import OptionParser
+from os.path import exists
+import sys
+
+if __name__ == "__main__":
+ opt = OptionParser(usage="%prog [options] unipatch-file", version="python-patch %s" % __version__)
+ opt.add_option("--debug", action="store_true", dest="debugmode", help="debug mode")
+ (options, args) = opt.parse_args()
+
+ if not args:
+ opt.print_version()
+ opt.print_help()
+ sys.exit()
+ debugmode = options.debugmode
+ patchfile = args[0]
+ if not exists(patchfile) or not isfile(patchfile):
+ sys.exit("patch file does not exist - %s" % patchfile)
+
+
+ if debugmode:
+ loglevel = logging.DEBUG
+ logformat = "%(levelname)8s %(message)s"
+ else:
+ loglevel = logging.INFO
+ logformat = "%(message)s"
+ logger.setLevel(loglevel)
+ loghandler.setFormatter(logging.Formatter(logformat))
+
+
+
+ patch = fromfile(patchfile)
+ #pprint(patch)
+ patch.apply()
+
+ # todo: document and test line ends handling logic - patch.py detects proper line-endings
+ # for inserted hunks and issues a warning if patched file has incosistent line ends
Binary file virtualenv/res/src/Django-1.5.2.dev20130524113953.tar.gz has changed
Binary file virtualenv/res/src/SPARQLWrapper-1.5.2.tar.gz has changed
Binary file virtualenv/res/src/distribute-0.6.34.tar.gz has changed
Binary file virtualenv/res/src/django-extensions-1.1.1.tar.gz has changed
Binary file virtualenv/res/src/html5lib-python-1.0b1.tar.gz has changed
Binary file virtualenv/res/src/isodate-0.4.9.tar.gz has changed
Binary file virtualenv/res/src/psycopg2-2.5.tar.gz has changed
Binary file virtualenv/res/src/pyparsing-1.5.7.tar.gz has changed
Binary file virtualenv/res/src/rdflib-4.0.1.tar.gz has changed
Binary file virtualenv/res/src/requests-1.2.3.tar.gz has changed
Binary file virtualenv/res/src/simplejson-3.3.0.tar.gz has changed
Binary file virtualenv/res/src/six-1.3.0.tar.gz has changed
Binary file virtualenv/res/src/south-0.7.6.tar.gz has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/create_python_env.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,65 @@
+"""
+Call this like ``python create_python_env.py``; it will
+refresh the project-boot.py script
+
+-prerequisite:
+
+- virtualenv
+- distribute
+- psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility
+
+- python project-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear --type-install=local --ignore-packages=MYSQL <path_to_venv>
+- python project-boot.py --no-site-packages --clear --ignore-packages=MYSQL --type-install=local <path_to_venv>
+- For Linux :
+python project-boot.py --unzip-setuptools --no-site-packages --index-url=http://pypi.websushi.org/ --clear --type-install=local <path_to_venv>
+
+Probleme avec mysql :
+
+sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/dev/workspace/platform/virtualenv/web/env/venv_platform/lib/python2.7/site-packages/_mysql.so
+
+"""
+
+import os
+import subprocess
+import re
+import sys
+
+
+here = os.path.dirname(os.path.abspath(__file__))
+base_dir = here
+script_name = os.path.join(base_dir, 'project-boot.py')
+
+import virtualenv
+
+src_base = os.path.abspath(os.path.join(here,"..","res","src")).replace("\\","/")
+lib_path = os.path.abspath(os.path.join(here,"..","res","lib")).replace("\\","/")
+patch_path = os.path.abspath(os.path.join(here,"res","patch")).replace("\\","/")
+
+
+EXTRA_TEXT = "import sys\n"
+EXTRA_TEXT += "sys.path.append('%s')\n" % (lib_path)
+EXTRA_TEXT += "sys.path.append('%s')\n" % (os.path.abspath(os.path.join(here,"res")).replace("\\","/"))
+EXTRA_TEXT += "from res_create_env import generate_install_methods\n"
+EXTRA_TEXT += "adjust_options, extend_parser, after_install = generate_install_methods(path_locations, '%s', Logger, call_subprocess)\n" % (src_base)
+
+def main():
+ python_version = ".".join(map(str,sys.version_info[0:2]))
+ text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version)
+ if os.path.exists(script_name):
+ f = open(script_name)
+ cur_text = f.read()
+ f.close()
+ else:
+ cur_text = ''
+ print 'Updating %s' % script_name
+ if cur_text == 'text':
+ print 'No update'
+ else:
+ print 'Script changed; updating...'
+ f = open(script_name, 'w')
+ f.write(text)
+ f.close()
+
+if __name__ == '__main__':
+ main()
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/res/README Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,22 @@
+README - Platform virtualenv lib modifications
+-------------------------------------------------
+
+1. DJANGO-PISTON
+https://bitbucket.org/jespern/django-piston/overview
+------------------------------------------------------
+Model name collision with python-oauth.
+Described here: https://bitbucket.org/david/django-oauth/issue/3/collision-with-django-piston-on-syncdb
+
+Piston and Django-oauth use the same model for Tokens, and same related name to their ForeignKey User.
+One of the related_name has to be modified.
+See platform/virtualenv/web/res/patch/piston.diff
+
+
+2. PYTHON-OAUTH2
+https://github.com/simplegeo/python-oauth2
+---------------------------------------------
+Request paramters are not handled correctly, and sometimes appear twice in the request query_string.
+Described here: https://github.com/simplegeo/python-oauth2/issues#issue/21
+
+Modification made in get_normalized_parameters in order to avoid doubling the parameters, and making the request non-valid.
+See platform/virtualenv/web/res/patch/oauth2.diff
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/res/requirement.txt Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,13 @@
+-f ../../res/src/
+Django==1.5.2.dev20130524113953
+SPARQLWrapper==1.5.2
+South==0.7.6
+django-extensions==1.1.1
+html5lib==python-1.0b1
+isodate==0.4.9
+psycopg2==2.5
+pyparsing==1.5.7
+rdflib==4.0.1
+requests==1.2.3
+simplejson==3.3.0
+six==1.3.0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/res/res_create_env.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,31 @@
+import platform
+
+from lib_create_env import lib_generate_install_methods
+
+system_str = platform.system()
+
+
+INSTALLS = [ #(key,method, option_str, dict_extra_env)
+ 'SIX',
+ 'REQUESTS',
+ 'SIMPLEJSON',
+ 'ISODATE',
+ 'PYPARSING',
+ 'HTML5LIB',
+ 'PSYCOPG2',
+ 'SOUTH',
+ 'DJANGO',
+ 'DJANGO-EXTENSIONS',
+ 'SPARQLWRAPPER',
+ 'RDFLIB',
+]
+
+if system_str == "Linux":
+ INSTALLS.insert(2, 'DISTRIBUTE')
+
+OPTIONS_TO_ADD = ['clear', 'type_install=local', 'unzip_setuptools']
+if system_str != 'Linux':
+ OPTIONS_TO_ADD.append('use_distribute')
+
+def generate_install_methods(path_locations, src_base, Logger, call_subprocess):
+ return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS, OPTIONS_TO_ADD)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/res/srvr_requirements.txt Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,3 @@
+python-memcached
+uWSGI
+pytz
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/virtualenv/web/virtualenv.py Tue Aug 27 11:01:32 2013 +0200
@@ -0,0 +1,2581 @@
+#!/usr/bin/env python
+"""Create a "virtual" Python installation
+"""
+
+# If you change the version here, change it in setup.py
+# and docs/conf.py as well.
+__version__ = "1.9.1" # following best practices
+virtualenv_version = __version__ # legacy, again
+
+import base64
+import sys
+import os
+import codecs
+import optparse
+import re
+import shutil
+import logging
+import tempfile
+import zlib
+import errno
+import glob
+import distutils.sysconfig
+from distutils.util import strtobool
+import struct
+import subprocess
+
+if sys.version_info < (2, 5):
+ print('ERROR: %s' % sys.exc_info()[1])
+ print('ERROR: this script requires Python 2.5 or greater.')
+ sys.exit(101)
+
+try:
+ set
+except NameError:
+ from sets import Set as set
+try:
+ basestring
+except NameError:
+ basestring = str
+
+try:
+ import ConfigParser
+except ImportError:
+ import configparser as ConfigParser
+
+join = os.path.join
+py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
+
+is_jython = sys.platform.startswith('java')
+is_pypy = hasattr(sys, 'pypy_version_info')
+is_win = (sys.platform == 'win32')
+is_cygwin = (sys.platform == 'cygwin')
+is_darwin = (sys.platform == 'darwin')
+abiflags = getattr(sys, 'abiflags', '')
+
+user_dir = os.path.expanduser('~')
+if is_win:
+ default_storage_dir = os.path.join(user_dir, 'virtualenv')
+else:
+ default_storage_dir = os.path.join(user_dir, '.virtualenv')
+default_config_file = os.path.join(default_storage_dir, 'virtualenv.ini')
+
+if is_pypy:
+ expected_exe = 'pypy'
+elif is_jython:
+ expected_exe = 'jython'
+else:
+ expected_exe = 'python'
+
+
+REQUIRED_MODULES = ['os', 'posix', 'posixpath', 'nt', 'ntpath', 'genericpath',
+ 'fnmatch', 'locale', 'encodings', 'codecs',
+ 'stat', 'UserDict', 'readline', 'copy_reg', 'types',
+ 're', 'sre', 'sre_parse', 'sre_constants', 'sre_compile',
+ 'zlib']
+
+REQUIRED_FILES = ['lib-dynload', 'config']
+
+majver, minver = sys.version_info[:2]
+if majver == 2:
+ if minver >= 6:
+ REQUIRED_MODULES.extend(['warnings', 'linecache', '_abcoll', 'abc'])
+ if minver >= 7:
+ REQUIRED_MODULES.extend(['_weakrefset'])
+ if minver <= 3:
+ REQUIRED_MODULES.extend(['sets', '__future__'])
+elif majver == 3:
+ # Some extra modules are needed for Python 3, but different ones
+ # for different versions.
+ REQUIRED_MODULES.extend(['_abcoll', 'warnings', 'linecache', 'abc', 'io',
+ '_weakrefset', 'copyreg', 'tempfile', 'random',
+ '__future__', 'collections', 'keyword', 'tarfile',
+ 'shutil', 'struct', 'copy', 'tokenize', 'token',
+ 'functools', 'heapq', 'bisect', 'weakref',
+ 'reprlib'])
+ if minver >= 2:
+ REQUIRED_FILES[-1] = 'config-%s' % majver
+ if minver == 3:
+ import sysconfig
+ platdir = sysconfig.get_config_var('PLATDIR')
+ REQUIRED_FILES.append(platdir)
+ # The whole list of 3.3 modules is reproduced below - the current
+ # uncommented ones are required for 3.3 as of now, but more may be
+ # added as 3.3 development continues.
+ REQUIRED_MODULES.extend([
+ #"aifc",
+ #"antigravity",
+ #"argparse",
+ #"ast",
+ #"asynchat",
+ #"asyncore",
+ "base64",
+ #"bdb",
+ #"binhex",
+ #"bisect",
+ #"calendar",
+ #"cgi",
+ #"cgitb",
+ #"chunk",
+ #"cmd",
+ #"codeop",
+ #"code",
+ #"colorsys",
+ #"_compat_pickle",
+ #"compileall",
+ #"concurrent",
+ #"configparser",
+ #"contextlib",
+ #"cProfile",
+ #"crypt",
+ #"csv",
+ #"ctypes",
+ #"curses",
+ #"datetime",
+ #"dbm",
+ #"decimal",
+ #"difflib",
+ #"dis",
+ #"doctest",
+ #"dummy_threading",
+ "_dummy_thread",
+ #"email",
+ #"filecmp",
+ #"fileinput",
+ #"formatter",
+ #"fractions",
+ #"ftplib",
+ #"functools",
+ #"getopt",
+ #"getpass",
+ #"gettext",
+ #"glob",
+ #"gzip",
+ "hashlib",
+ #"heapq",
+ "hmac",
+ #"html",
+ #"http",
+ #"idlelib",
+ #"imaplib",
+ #"imghdr",
+ "imp",
+ "importlib",
+ #"inspect",
+ #"json",
+ #"lib2to3",
+ #"logging",
+ #"macpath",
+ #"macurl2path",
+ #"mailbox",
+ #"mailcap",
+ #"_markupbase",
+ #"mimetypes",
+ #"modulefinder",
+ #"multiprocessing",
+ #"netrc",
+ #"nntplib",
+ #"nturl2path",
+ #"numbers",
+ #"opcode",
+ #"optparse",
+ #"os2emxpath",
+ #"pdb",
+ #"pickle",
+ #"pickletools",
+ #"pipes",
+ #"pkgutil",
+ #"platform",
+ #"plat-linux2",
+ #"plistlib",
+ #"poplib",
+ #"pprint",
+ #"profile",
+ #"pstats",
+ #"pty",
+ #"pyclbr",
+ #"py_compile",
+ #"pydoc_data",
+ #"pydoc",
+ #"_pyio",
+ #"queue",
+ #"quopri",
+ #"reprlib",
+ "rlcompleter",
+ #"runpy",
+ #"sched",
+ #"shelve",
+ #"shlex",
+ #"smtpd",
+ #"smtplib",
+ #"sndhdr",
+ #"socket",
+ #"socketserver",
+ #"sqlite3",
+ #"ssl",
+ #"stringprep",
+ #"string",
+ #"_strptime",
+ #"subprocess",
+ #"sunau",
+ #"symbol",
+ #"symtable",
+ #"sysconfig",
+ #"tabnanny",
+ #"telnetlib",
+ #"test",
+ #"textwrap",
+ #"this",
+ #"_threading_local",
+ #"threading",
+ #"timeit",
+ #"tkinter",
+ #"tokenize",
+ #"token",
+ #"traceback",
+ #"trace",
+ #"tty",
+ #"turtledemo",
+ #"turtle",
+ #"unittest",
+ #"urllib",
+ #"uuid",
+ #"uu",
+ #"wave",
+ #"weakref",
+ #"webbrowser",
+ #"wsgiref",
+ #"xdrlib",
+ #"xml",
+ #"xmlrpc",
+ #"zipfile",
+ ])
+
+if is_pypy:
+ # these are needed to correctly display the exceptions that may happen
+ # during the bootstrap
+ REQUIRED_MODULES.extend(['traceback', 'linecache'])
+
+class Logger(object):
+
+ """
+ Logging object for use in command-line script. Allows ranges of
+ levels, to avoid some redundancy of displayed information.
+ """
+
+ DEBUG = logging.DEBUG
+ INFO = logging.INFO
+ NOTIFY = (logging.INFO+logging.WARN)/2
+ WARN = WARNING = logging.WARN
+ ERROR = logging.ERROR
+ FATAL = logging.FATAL
+
+ LEVELS = [DEBUG, INFO, NOTIFY, WARN, ERROR, FATAL]
+
+ def __init__(self, consumers):
+ self.consumers = consumers
+ self.indent = 0
+ self.in_progress = None
+ self.in_progress_hanging = False
+
+ def debug(self, msg, *args, **kw):
+ self.log(self.DEBUG, msg, *args, **kw)
+ def info(self, msg, *args, **kw):
+ self.log(self.INFO, msg, *args, **kw)
+ def notify(self, msg, *args, **kw):
+ self.log(self.NOTIFY, msg, *args, **kw)
+ def warn(self, msg, *args, **kw):
+ self.log(self.WARN, msg, *args, **kw)
+ def error(self, msg, *args, **kw):
+ self.log(self.ERROR, msg, *args, **kw)
+ def fatal(self, msg, *args, **kw):
+ self.log(self.FATAL, msg, *args, **kw)
+ def log(self, level, msg, *args, **kw):
+ if args:
+ if kw:
+ raise TypeError(
+ "You may give positional or keyword arguments, not both")
+ args = args or kw
+ rendered = None
+ for consumer_level, consumer in self.consumers:
+ if self.level_matches(level, consumer_level):
+ if (self.in_progress_hanging
+ and consumer in (sys.stdout, sys.stderr)):
+ self.in_progress_hanging = False
+ sys.stdout.write('\n')
+ sys.stdout.flush()
+ if rendered is None:
+ if args:
+ rendered = msg % args
+ else:
+ rendered = msg
+ rendered = ' '*self.indent + rendered
+ if hasattr(consumer, 'write'):
+ consumer.write(rendered+'\n')
+ else:
+ consumer(rendered)
+
+ def start_progress(self, msg):
+ assert not self.in_progress, (
+ "Tried to start_progress(%r) while in_progress %r"
+ % (msg, self.in_progress))
+ if self.level_matches(self.NOTIFY, self._stdout_level()):
+ sys.stdout.write(msg)
+ sys.stdout.flush()
+ self.in_progress_hanging = True
+ else:
+ self.in_progress_hanging = False
+ self.in_progress = msg
+
+ def end_progress(self, msg='done.'):
+ assert self.in_progress, (
+ "Tried to end_progress without start_progress")
+ if self.stdout_level_matches(self.NOTIFY):
+ if not self.in_progress_hanging:
+ # Some message has been printed out since start_progress
+ sys.stdout.write('...' + self.in_progress + msg + '\n')
+ sys.stdout.flush()
+ else:
+ sys.stdout.write(msg + '\n')
+ sys.stdout.flush()
+ self.in_progress = None
+ self.in_progress_hanging = False
+
+ def show_progress(self):
+ """If we are in a progress scope, and no log messages have been
+ shown, write out another '.'"""
+ if self.in_progress_hanging:
+ sys.stdout.write('.')
+ sys.stdout.flush()
+
+ def stdout_level_matches(self, level):
+ """Returns true if a message at this level will go to stdout"""
+ return self.level_matches(level, self._stdout_level())
+
+ def _stdout_level(self):
+ """Returns the level that stdout runs at"""
+ for level, consumer in self.consumers:
+ if consumer is sys.stdout:
+ return level
+ return self.FATAL
+
+ def level_matches(self, level, consumer_level):
+ """
+ >>> l = Logger([])
+ >>> l.level_matches(3, 4)
+ False
+ >>> l.level_matches(3, 2)
+ True
+ >>> l.level_matches(slice(None, 3), 3)
+ False
+ >>> l.level_matches(slice(None, 3), 2)
+ True
+ >>> l.level_matches(slice(1, 3), 1)
+ True
+ >>> l.level_matches(slice(2, 3), 1)
+ False
+ """
+ if isinstance(level, slice):
+ start, stop = level.start, level.stop
+ if start is not None and start > consumer_level:
+ return False
+ if stop is not None and stop <= consumer_level:
+ return False
+ return True
+ else:
+ return level >= consumer_level
+
+ #@classmethod
+ def level_for_integer(cls, level):
+ levels = cls.LEVELS
+ if level < 0:
+ return levels[0]
+ if level >= len(levels):
+ return levels[-1]
+ return levels[level]
+
+ level_for_integer = classmethod(level_for_integer)
+
+# create a silent logger just to prevent this from being undefined
+# will be overridden with requested verbosity main() is called.
+logger = Logger([(Logger.LEVELS[-1], sys.stdout)])
+
+def mkdir(path):
+ if not os.path.exists(path):
+ logger.info('Creating %s', path)
+ os.makedirs(path)
+ else:
+ logger.info('Directory %s already exists', path)
+
+def copyfileordir(src, dest):
+ if os.path.isdir(src):
+ shutil.copytree(src, dest, True)
+ else:
+ shutil.copy2(src, dest)
+
+def copyfile(src, dest, symlink=True):
+ if not os.path.exists(src):
+ # Some bad symlink in the src
+ logger.warn('Cannot find file %s (bad symlink)', src)
+ return
+ if os.path.exists(dest):
+ logger.debug('File %s already exists', dest)
+ return
+ if not os.path.exists(os.path.dirname(dest)):
+ logger.info('Creating parent directories for %s' % os.path.dirname(dest))
+ os.makedirs(os.path.dirname(dest))
+ if not os.path.islink(src):
+ srcpath = os.path.abspath(src)
+ else:
+ srcpath = os.readlink(src)
+ if symlink and hasattr(os, 'symlink') and not is_win:
+ logger.info('Symlinking %s', dest)
+ try:
+ os.symlink(srcpath, dest)
+ except (OSError, NotImplementedError):
+ logger.info('Symlinking failed, copying to %s', dest)
+ copyfileordir(src, dest)
+ else:
+ logger.info('Copying to %s', dest)
+ copyfileordir(src, dest)
+
+def writefile(dest, content, overwrite=True):
+ if not os.path.exists(dest):
+ logger.info('Writing %s', dest)
+ f = open(dest, 'wb')
+ f.write(content.encode('utf-8'))
+ f.close()
+ return
+ else:
+ f = open(dest, 'rb')
+ c = f.read()
+ f.close()
+ if c != content.encode("utf-8"):
+ if not overwrite:
+ logger.notify('File %s exists with different content; not overwriting', dest)
+ return
+ logger.notify('Overwriting %s with new content', dest)
+ f = open(dest, 'wb')
+ f.write(content.encode('utf-8'))
+ f.close()
+ else:
+ logger.info('Content %s already in place', dest)
+
+def rmtree(dir):
+ if os.path.exists(dir):
+ logger.notify('Deleting tree %s', dir)
+ shutil.rmtree(dir)
+ else:
+ logger.info('Do not need to delete %s; already gone', dir)
+
+def make_exe(fn):
+ if hasattr(os, 'chmod'):
+ oldmode = os.stat(fn).st_mode & 0xFFF # 0o7777
+ newmode = (oldmode | 0x16D) & 0xFFF # 0o555, 0o7777
+ os.chmod(fn, newmode)
+ logger.info('Changed mode of %s to %s', fn, oct(newmode))
+
+def _find_file(filename, dirs):
+ for dir in reversed(dirs):
+ files = glob.glob(os.path.join(dir, filename))
+ if files and os.path.isfile(files[0]):
+ return True, files[0]
+ return False, filename
+
+def _install_req(py_executable, unzip=False, distribute=False,
+ search_dirs=None, never_download=False):
+
+ if search_dirs is None:
+ search_dirs = file_search_dirs()
+
+ if not distribute:
+ egg_path = 'setuptools-*-py%s.egg' % sys.version[:3]
+ found, egg_path = _find_file(egg_path, search_dirs)
+ project_name = 'setuptools'
+ bootstrap_script = EZ_SETUP_PY
+ tgz_path = None
+ else:
+ # Look for a distribute egg (these are not distributed by default,
+ # but can be made available by the user)
+ egg_path = 'distribute-*-py%s.egg' % sys.version[:3]
+ found, egg_path = _find_file(egg_path, search_dirs)
+ project_name = 'distribute'
+ if found:
+ tgz_path = None
+ bootstrap_script = DISTRIBUTE_FROM_EGG_PY
+ else:
+ # Fall back to sdist
+ # NB: egg_path is not None iff tgz_path is None
+ # iff bootstrap_script is a generic setup script accepting
+ # the standard arguments.
+ egg_path = None
+ tgz_path = 'distribute-*.tar.gz'
+ found, tgz_path = _find_file(tgz_path, search_dirs)
+ bootstrap_script = DISTRIBUTE_SETUP_PY
+
+ if is_jython and os._name == 'nt':
+ # Jython's .bat sys.executable can't handle a command line
+ # argument with newlines
+ fd, ez_setup = tempfile.mkstemp('.py')
+ os.write(fd, bootstrap_script)
+ os.close(fd)
+ cmd = [py_executable, ez_setup]
+ else:
+ cmd = [py_executable, '-c', bootstrap_script]
+ if unzip and egg_path:
+ cmd.append('--always-unzip')
+ env = {}
+ remove_from_env = ['__PYVENV_LAUNCHER__']
+ if logger.stdout_level_matches(logger.DEBUG) and egg_path:
+ cmd.append('-v')
+
+ old_chdir = os.getcwd()
+ if egg_path is not None and os.path.exists(egg_path):
+ logger.info('Using existing %s egg: %s' % (project_name, egg_path))
+ cmd.append(egg_path)
+ if os.environ.get('PYTHONPATH'):
+ env['PYTHONPATH'] = egg_path + os.path.pathsep + os.environ['PYTHONPATH']
+ else:
+ env['PYTHONPATH'] = egg_path
+ elif tgz_path is not None and os.path.exists(tgz_path):
+ # Found a tgz source dist, let's chdir
+ logger.info('Using existing %s egg: %s' % (project_name, tgz_path))
+ os.chdir(os.path.dirname(tgz_path))
+ # in this case, we want to be sure that PYTHONPATH is unset (not
+ # just empty, really unset), else CPython tries to import the
+ # site.py that it's in virtualenv_support
+ remove_from_env.append('PYTHONPATH')
+ elif never_download:
+ logger.fatal("Can't find any local distributions of %s to install "
+ "and --never-download is set. Either re-run virtualenv "
+ "without the --never-download option, or place a %s "
+ "distribution (%s) in one of these "
+ "locations: %r" % (project_name, project_name,
+ egg_path or tgz_path,
+ search_dirs))
+ sys.exit(1)
+ elif egg_path:
+ logger.info('No %s egg found; downloading' % project_name)
+ cmd.extend(['--always-copy', '-U', project_name])
+ else:
+ logger.info('No %s tgz found; downloading' % project_name)
+ logger.start_progress('Installing %s...' % project_name)
+ logger.indent += 2
+ cwd = None
+ if project_name == 'distribute':
+ env['DONT_PATCH_SETUPTOOLS'] = 'true'
+
+ def _filter_ez_setup(line):
+ return filter_ez_setup(line, project_name)
+
+ if not os.access(os.getcwd(), os.W_OK):
+ cwd = tempfile.mkdtemp()
+ if tgz_path is not None and os.path.exists(tgz_path):
+ # the current working dir is hostile, let's copy the
+ # tarball to a temp dir
+ target = os.path.join(cwd, os.path.split(tgz_path)[-1])
+ shutil.copy(tgz_path, target)
+ try:
+ call_subprocess(cmd, show_stdout=False,
+ filter_stdout=_filter_ez_setup,
+ extra_env=env,
+ remove_from_env=remove_from_env,
+ cwd=cwd)
+ finally:
+ logger.indent -= 2
+ logger.end_progress()
+ if cwd is not None:
+ shutil.rmtree(cwd)
+ if os.getcwd() != old_chdir:
+ os.chdir(old_chdir)
+ if is_jython and os._name == 'nt':
+ os.remove(ez_setup)
+
+def file_search_dirs():
+ here = os.path.dirname(os.path.abspath(__file__))
+ dirs = ['.', here,
+ join(here, 'virtualenv_support')]
+ if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
+ # Probably some boot script; just in case virtualenv is installed...
+ try:
+ import virtualenv
+ except ImportError:
+ pass
+ else:
+ dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support'))
+ return [d for d in dirs if os.path.isdir(d)]
+
+def install_setuptools(py_executable, unzip=False,
+ search_dirs=None, never_download=False):
+ _install_req(py_executable, unzip,
+ search_dirs=search_dirs, never_download=never_download)
+
+def install_distribute(py_executable, unzip=False,
+ search_dirs=None, never_download=False):
+ _install_req(py_executable, unzip, distribute=True,
+ search_dirs=search_dirs, never_download=never_download)
+
+_pip_re = re.compile(r'^pip-.*(zip|tar.gz|tar.bz2|tgz|tbz)$', re.I)
+def install_pip(py_executable, search_dirs=None, never_download=False):
+ if search_dirs is None:
+ search_dirs = file_search_dirs()
+
+ filenames = []
+ for dir in search_dirs:
+ filenames.extend([join(dir, fn) for fn in os.listdir(dir)
+ if _pip_re.search(fn)])
+ filenames = [(os.path.basename(filename).lower(), i, filename) for i, filename in enumerate(filenames)]
+ filenames.sort()
+ filenames = [filename for basename, i, filename in filenames]
+ if not filenames:
+ filename = 'pip'
+ else:
+ filename = filenames[-1]
+ easy_install_script = 'easy_install'
+ if is_win:
+ easy_install_script = 'easy_install-script.py'
+ # There's two subtle issues here when invoking easy_install.
+ # 1. On unix-like systems the easy_install script can *only* be executed
+ # directly if its full filesystem path is no longer than 78 characters.
+ # 2. A work around to [1] is to use the `python path/to/easy_install foo`
+ # pattern, but that breaks if the path contains non-ASCII characters, as
+ # you can't put the file encoding declaration before the shebang line.
+ # The solution is to use Python's -x flag to skip the first line of the
+ # script (and any ASCII decoding errors that may have occurred in that line)
+ cmd = [py_executable, '-x', join(os.path.dirname(py_executable), easy_install_script), filename]
+ # jython and pypy don't yet support -x
+ if is_jython or is_pypy:
+ cmd.remove('-x')
+ if filename == 'pip':
+ if never_download:
+ logger.fatal("Can't find any local distributions of pip to install "
+ "and --never-download is set. Either re-run virtualenv "
+ "without the --never-download option, or place a pip "
+ "source distribution (zip/tar.gz/tar.bz2) in one of these "
+ "locations: %r" % search_dirs)
+ sys.exit(1)
+ logger.info('Installing pip from network...')
+ else:
+ logger.info('Installing existing %s distribution: %s' % (
+ os.path.basename(filename), filename))
+ logger.start_progress('Installing pip...')
+ logger.indent += 2
+ def _filter_setup(line):
+ return filter_ez_setup(line, 'pip')
+ try:
+ call_subprocess(cmd, show_stdout=False,
+ filter_stdout=_filter_setup)
+ finally:
+ logger.indent -= 2
+ logger.end_progress()
+
+def filter_ez_setup(line, project_name='setuptools'):
+ if not line.strip():
+ return Logger.DEBUG
+ if project_name == 'distribute':
+ for prefix in ('Extracting', 'Now working', 'Installing', 'Before',
+ 'Scanning', 'Setuptools', 'Egg', 'Already',
+ 'running', 'writing', 'reading', 'installing',
+ 'creating', 'copying', 'byte-compiling', 'removing',
+ 'Processing'):
+ if line.startswith(prefix):
+ return Logger.DEBUG
+ return Logger.DEBUG
+ for prefix in ['Reading ', 'Best match', 'Processing setuptools',
+ 'Copying setuptools', 'Adding setuptools',
+ 'Installing ', 'Installed ']:
+ if line.startswith(prefix):
+ return Logger.DEBUG
+ return Logger.INFO
+
+
+class UpdatingDefaultsHelpFormatter(optparse.IndentedHelpFormatter):
+ """
+ Custom help formatter for use in ConfigOptionParser that updates
+ the defaults before expanding them, allowing them to show up correctly
+ in the help listing
+ """
+ def expand_default(self, option):
+ if self.parser is not None:
+ self.parser.update_defaults(self.parser.defaults)
+ return optparse.IndentedHelpFormatter.expand_default(self, option)
+
+
+class ConfigOptionParser(optparse.OptionParser):
+ """
+ Custom option parser which updates its defaults by by checking the
+ configuration files and environmental variables
+ """
+ def __init__(self, *args, **kwargs):
+ self.config = ConfigParser.RawConfigParser()
+ self.files = self.get_config_files()
+ self.config.read(self.files)
+ optparse.OptionParser.__init__(self, *args, **kwargs)
+
+ def get_config_files(self):
+ config_file = os.environ.get('VIRTUALENV_CONFIG_FILE', False)
+ if config_file and os.path.exists(config_file):
+ return [config_file]
+ return [default_config_file]
+
+ def update_defaults(self, defaults):
+ """
+ Updates the given defaults with values from the config files and
+ the environ. Does a little special handling for certain types of
+ options (lists).
+ """
+ # Then go and look for the other sources of configuration:
+ config = {}
+ # 1. config files
+ config.update(dict(self.get_config_section('virtualenv')))
+ # 2. environmental variables
+ config.update(dict(self.get_environ_vars()))
+ # Then set the options with those values
+ for key, val in config.items():
+ key = key.replace('_', '-')
+ if not key.startswith('--'):
+ key = '--%s' % key # only prefer long opts
+ option = self.get_option(key)
+ if option is not None:
+ # ignore empty values
+ if not val:
+ continue
+ # handle multiline configs
+ if option.action == 'append':
+ val = val.split()
+ else:
+ option.nargs = 1
+ if option.action == 'store_false':
+ val = not strtobool(val)
+ elif option.action in ('store_true', 'count'):
+ val = strtobool(val)
+ try:
+ val = option.convert_value(key, val)
+ except optparse.OptionValueError:
+ e = sys.exc_info()[1]
+ print("An error occured during configuration: %s" % e)
+ sys.exit(3)
+ defaults[option.dest] = val
+ return defaults
+
+ def get_config_section(self, name):
+ """
+ Get a section of a configuration
+ """
+ if self.config.has_section(name):
+ return self.config.items(name)
+ return []
+
+ def get_environ_vars(self, prefix='VIRTUALENV_'):
+ """
+ Returns a generator with all environmental vars with prefix VIRTUALENV
+ """
+ for key, val in os.environ.items():
+ if key.startswith(prefix):
+ yield (key.replace(prefix, '').lower(), val)
+
+ def get_default_values(self):
+ """
+ Overridding to make updating the defaults after instantiation of
+ the option parser possible, update_defaults() does the dirty work.
+ """
+ if not self.process_default_values:
+ # Old, pre-Optik 1.5 behaviour.
+ return optparse.Values(self.defaults)
+
+ defaults = self.update_defaults(self.defaults.copy()) # ours
+ for option in self._get_all_options():
+ default = defaults.get(option.dest)
+ if isinstance(default, basestring):
+ opt_str = option.get_opt_string()
+ defaults[option.dest] = option.check_value(opt_str, default)
+ return optparse.Values(defaults)
+
+
+def main():
+ parser = ConfigOptionParser(
+ version=virtualenv_version,
+ usage="%prog [OPTIONS] DEST_DIR",
+ formatter=UpdatingDefaultsHelpFormatter())
+
+ parser.add_option(
+ '-v', '--verbose',
+ action='count',
+ dest='verbose',
+ default=0,
+ help="Increase verbosity")
+
+ parser.add_option(
+ '-q', '--quiet',
+ action='count',
+ dest='quiet',
+ default=0,
+ help='Decrease verbosity')
+
+ parser.add_option(
+ '-p', '--python',
+ dest='python',
+ metavar='PYTHON_EXE',
+ help='The Python interpreter to use, e.g., --python=python2.5 will use the python2.5 '
+ 'interpreter to create the new environment. The default is the interpreter that '
+ 'virtualenv was installed with (%s)' % sys.executable)
+
+ parser.add_option(
+ '--clear',
+ dest='clear',
+ action='store_true',
+ help="Clear out the non-root install and start from scratch")
+
+ parser.set_defaults(system_site_packages=False)
+ parser.add_option(
+ '--no-site-packages',
+ dest='system_site_packages',
+ action='store_false',
+ help="Don't give access to the global site-packages dir to the "
+ "virtual environment (default)")
+
+ parser.add_option(
+ '--system-site-packages',
+ dest='system_site_packages',
+ action='store_true',
+ help="Give access to the global site-packages dir to the "
+ "virtual environment")
+
+ parser.add_option(
+ '--unzip-setuptools',
+ dest='unzip_setuptools',
+ action='store_true',
+ help="Unzip Setuptools or Distribute when installing it")
+
+ parser.add_option(
+ '--relocatable',
+ dest='relocatable',
+ action='store_true',
+ help='Make an EXISTING virtualenv environment relocatable. '
+ 'This fixes up scripts and makes all .pth files relative')
+
+ parser.add_option(
+ '--distribute', '--use-distribute', # the second option is for legacy reasons here. Hi Kenneth!
+ dest='use_distribute',
+ action='store_true',
+ help='Use Distribute instead of Setuptools. Set environ variable '
+ 'VIRTUALENV_DISTRIBUTE to make it the default ')
+
+ parser.add_option(
+ '--no-setuptools',
+ dest='no_setuptools',
+ action='store_true',
+ help='Do not install distribute/setuptools (or pip) '
+ 'in the new virtualenv.')
+
+ parser.add_option(
+ '--no-pip',
+ dest='no_pip',
+ action='store_true',
+ help='Do not install pip in the new virtualenv.')
+
+ parser.add_option(
+ '--setuptools',
+ dest='use_distribute',
+ action='store_false',
+ help='Use Setuptools instead of Distribute. Set environ variable '
+ 'VIRTUALENV_SETUPTOOLS to make it the default ')
+
+ # Set this to True to use distribute by default, even in Python 2.
+ parser.set_defaults(use_distribute=False)
+
+ default_search_dirs = file_search_dirs()
+ parser.add_option(
+ '--extra-search-dir',
+ dest="search_dirs",
+ action="append",
+ default=default_search_dirs,
+ help="Directory to look for setuptools/distribute/pip distributions in. "
+ "You can add any number of additional --extra-search-dir paths.")
+
+ parser.add_option(
+ '--never-download',
+ dest="never_download",
+ action="store_true",
+ help="Never download anything from the network. Instead, virtualenv will fail "
+ "if local distributions of setuptools/distribute/pip are not present.")
+
+ parser.add_option(
+ '--prompt',
+ dest='prompt',
+ help='Provides an alternative prompt prefix for this environment')
+
+ if 'extend_parser' in globals():
+ extend_parser(parser)
+
+ options, args = parser.parse_args()
+
+ global logger
+
+ if 'adjust_options' in globals():
+ adjust_options(options, args)
+
+ verbosity = options.verbose - options.quiet
+ logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
+
+ if options.python and not os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
+ env = os.environ.copy()
+ interpreter = resolve_interpreter(options.python)
+ if interpreter == sys.executable:
+ logger.warn('Already using interpreter %s' % interpreter)
+ else:
+ logger.notify('Running virtualenv with interpreter %s' % interpreter)
+ env['VIRTUALENV_INTERPRETER_RUNNING'] = 'true'
+ file = __file__
+ if file.endswith('.pyc'):
+ file = file[:-1]
+ popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
+ raise SystemExit(popen.wait())
+
+ # Force --distribute on Python 3, since setuptools is not available.
+ if majver > 2:
+ options.use_distribute = True
+
+ if os.environ.get('PYTHONDONTWRITEBYTECODE') and not options.use_distribute:
+ print(
+ "The PYTHONDONTWRITEBYTECODE environment variable is "
+ "not compatible with setuptools. Either use --distribute "
+ "or unset PYTHONDONTWRITEBYTECODE.")
+ sys.exit(2)
+ if not args:
+ print('You must provide a DEST_DIR')
+ parser.print_help()
+ sys.exit(2)
+ if len(args) > 1:
+ print('There must be only one argument: DEST_DIR (you gave %s)' % (
+ ' '.join(args)))
+ parser.print_help()
+ sys.exit(2)
+
+ home_dir = args[0]
+
+ if os.environ.get('WORKING_ENV'):
+ logger.fatal('ERROR: you cannot run virtualenv while in a workingenv')
+ logger.fatal('Please deactivate your workingenv, then re-run this script')
+ sys.exit(3)
+
+ if 'PYTHONHOME' in os.environ:
+ logger.warn('PYTHONHOME is set. You *must* activate the virtualenv before using it')
+ del os.environ['PYTHONHOME']
+
+ if options.relocatable:
+ make_environment_relocatable(home_dir)
+ return
+
+ create_environment(home_dir,
+ site_packages=options.system_site_packages,
+ clear=options.clear,
+ unzip_setuptools=options.unzip_setuptools,
+ use_distribute=options.use_distribute,
+ prompt=options.prompt,
+ search_dirs=options.search_dirs,
+ never_download=options.never_download,
+ no_setuptools=options.no_setuptools,
+ no_pip=options.no_pip)
+ if 'after_install' in globals():
+ after_install(options, home_dir)
+
+def call_subprocess(cmd, show_stdout=True,
+ filter_stdout=None, cwd=None,
+ raise_on_returncode=True, extra_env=None,
+ remove_from_env=None):
+ cmd_parts = []
+ for part in cmd:
+ if len(part) > 45:
+ part = part[:20]+"..."+part[-20:]
+ if ' ' in part or '\n' in part or '"' in part or "'" in part:
+ part = '"%s"' % part.replace('"', '\\"')
+ if hasattr(part, 'decode'):
+ try:
+ part = part.decode(sys.getdefaultencoding())
+ except UnicodeDecodeError:
+ part = part.decode(sys.getfilesystemencoding())
+ cmd_parts.append(part)
+ cmd_desc = ' '.join(cmd_parts)
+ if show_stdout:
+ stdout = None
+ else:
+ stdout = subprocess.PIPE
+ logger.debug("Running command %s" % cmd_desc)
+ if extra_env or remove_from_env:
+ env = os.environ.copy()
+ if extra_env:
+ env.update(extra_env)
+ if remove_from_env:
+ for varname in remove_from_env:
+ env.pop(varname, None)
+ else:
+ env = None
+ try:
+ proc = subprocess.Popen(
+ cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
+ cwd=cwd, env=env)
+ except Exception:
+ e = sys.exc_info()[1]
+ logger.fatal(
+ "Error %s while executing command %s" % (e, cmd_desc))
+ raise
+ all_output = []
+ if stdout is not None:
+ stdout = proc.stdout
+ encoding = sys.getdefaultencoding()
+ fs_encoding = sys.getfilesystemencoding()
+ while 1:
+ line = stdout.readline()
+ try:
+ line = line.decode(encoding)
+ except UnicodeDecodeError:
+ line = line.decode(fs_encoding)
+ if not line:
+ break
+ line = line.rstrip()
+ all_output.append(line)
+ if filter_stdout:
+ level = filter_stdout(line)
+ if isinstance(level, tuple):
+ level, line = level
+ logger.log(level, line)
+ if not logger.stdout_level_matches(level):
+ logger.show_progress()
+ else:
+ logger.info(line)
+ else:
+ proc.communicate()
+ proc.wait()
+ if proc.returncode:
+ if raise_on_returncode:
+ if all_output:
+ logger.notify('Complete output from command %s:' % cmd_desc)
+ logger.notify('\n'.join(all_output) + '\n----------------------------------------')
+ raise OSError(
+ "Command %s failed with error code %s"
+ % (cmd_desc, proc.returncode))
+ else:
+ logger.warn(
+ "Command %s had error code %s"
+ % (cmd_desc, proc.returncode))
+
+
+def create_environment(home_dir, site_packages=False, clear=False,
+ unzip_setuptools=False, use_distribute=False,
+ prompt=None, search_dirs=None, never_download=False,
+ no_setuptools=False, no_pip=False):
+ """
+ Creates a new environment in ``home_dir``.
+
+ If ``site_packages`` is true, then the global ``site-packages/``
+ directory will be on the path.
+
+ If ``clear`` is true (default False) then the environment will
+ first be cleared.
+ """
+ home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
+
+ py_executable = os.path.abspath(install_python(
+ home_dir, lib_dir, inc_dir, bin_dir,
+ site_packages=site_packages, clear=clear))
+
+ install_distutils(home_dir)
+
+ if not no_setuptools:
+ if use_distribute:
+ install_distribute(py_executable, unzip=unzip_setuptools,
+ search_dirs=search_dirs, never_download=never_download)
+ else:
+ install_setuptools(py_executable, unzip=unzip_setuptools,
+ search_dirs=search_dirs, never_download=never_download)
+
+ if not no_pip:
+ install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
+
+ install_activate(home_dir, bin_dir, prompt)
+
+def is_executable_file(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+def path_locations(home_dir):
+ """Return the path locations for the environment (where libraries are,
+ where scripts go, etc)"""
+ # XXX: We'd use distutils.sysconfig.get_python_inc/lib but its
+ # prefix arg is broken: http://bugs.python.org/issue3386
+ if is_win:
+ # Windows has lots of problems with executables with spaces in
+ # the name; this function will remove them (using the ~1
+ # format):
+ mkdir(home_dir)
+ if ' ' in home_dir:
+ import ctypes
+ GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
+ size = max(len(home_dir)+1, 256)
+ buf = ctypes.create_unicode_buffer(size)
+ try:
+ u = unicode
+ except NameError:
+ u = str
+ ret = GetShortPathName(u(home_dir), buf, size)
+ if not ret:
+ print('Error: the path "%s" has a space in it' % home_dir)
+ print('We could not determine the short pathname for it.')
+ print('Exiting.')
+ sys.exit(3)
+ home_dir = str(buf.value)
+ lib_dir = join(home_dir, 'Lib')
+ inc_dir = join(home_dir, 'Include')
+ bin_dir = join(home_dir, 'Scripts')
+ if is_jython:
+ lib_dir = join(home_dir, 'Lib')
+ inc_dir = join(home_dir, 'Include')
+ bin_dir = join(home_dir, 'bin')
+ elif is_pypy:
+ lib_dir = home_dir
+ inc_dir = join(home_dir, 'include')
+ bin_dir = join(home_dir, 'bin')
+ elif not is_win:
+ lib_dir = join(home_dir, 'lib', py_version)
+ multiarch_exec = '/usr/bin/multiarch-platform'
+ if is_executable_file(multiarch_exec):
+ # In Mageia (2) and Mandriva distros the include dir must be like:
+ # virtualenv/include/multiarch-x86_64-linux/python2.7
+ # instead of being virtualenv/include/python2.7
+ p = subprocess.Popen(multiarch_exec, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ # stdout.strip is needed to remove newline character
+ inc_dir = join(home_dir, 'include', stdout.strip(), py_version + abiflags)
+ else:
+ inc_dir = join(home_dir, 'include', py_version + abiflags)
+ bin_dir = join(home_dir, 'bin')
+ return home_dir, lib_dir, inc_dir, bin_dir
+
+
+def change_prefix(filename, dst_prefix):
+ prefixes = [sys.prefix]
+
+ if is_darwin:
+ prefixes.extend((
+ os.path.join("/Library/Python", sys.version[:3], "site-packages"),
+ os.path.join(sys.prefix, "Extras", "lib", "python"),
+ os.path.join("~", "Library", "Python", sys.version[:3], "site-packages"),
+ # Python 2.6 no-frameworks
+ os.path.join("~", ".local", "lib","python", sys.version[:3], "site-packages"),
+ # System Python 2.7 on OSX Mountain Lion
+ os.path.join("~", "Library", "Python", sys.version[:3], "lib", "python", "site-packages")))
+
+ if hasattr(sys, 'real_prefix'):
+ prefixes.append(sys.real_prefix)
+ if hasattr(sys, 'base_prefix'):
+ prefixes.append(sys.base_prefix)
+ prefixes = list(map(os.path.expanduser, prefixes))
+ prefixes = list(map(os.path.abspath, prefixes))
+ # Check longer prefixes first so we don't split in the middle of a filename
+ prefixes = sorted(prefixes, key=len, reverse=True)
+ filename = os.path.abspath(filename)
+ for src_prefix in prefixes:
+ if filename.startswith(src_prefix):
+ _, relpath = filename.split(src_prefix, 1)
+ if src_prefix != os.sep: # sys.prefix == "/"
+ assert relpath[0] == os.sep
+ relpath = relpath[1:]
+ return join(dst_prefix, relpath)
+ assert False, "Filename %s does not start with any of these prefixes: %s" % \
+ (filename, prefixes)
+
+def copy_required_modules(dst_prefix):
+ import imp
+ # If we are running under -p, we need to remove the current
+ # directory from sys.path temporarily here, so that we
+ # definitely get the modules from the site directory of
+ # the interpreter we are running under, not the one
+ # virtualenv.py is installed under (which might lead to py2/py3
+ # incompatibility issues)
+ _prev_sys_path = sys.path
+ if os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
+ sys.path = sys.path[1:]
+ try:
+ for modname in REQUIRED_MODULES:
+ if modname in sys.builtin_module_names:
+ logger.info("Ignoring built-in bootstrap module: %s" % modname)
+ continue
+ try:
+ f, filename, _ = imp.find_module(modname)
+ except ImportError:
+ logger.info("Cannot import bootstrap module: %s" % modname)
+ else:
+ if f is not None:
+ f.close()
+ # special-case custom readline.so on OS X, but not for pypy:
+ if modname == 'readline' and sys.platform == 'darwin' and not (
+ is_pypy or filename.endswith(join('lib-dynload', 'readline.so'))):
+ dst_filename = join(dst_prefix, 'lib', 'python%s' % sys.version[:3], 'readline.so')
+ else:
+ dst_filename = change_prefix(filename, dst_prefix)
+ copyfile(filename, dst_filename)
+ if filename.endswith('.pyc'):
+ pyfile = filename[:-1]
+ if os.path.exists(pyfile):
+ copyfile(pyfile, dst_filename[:-1])
+ finally:
+ sys.path = _prev_sys_path
+
+
+def subst_path(prefix_path, prefix, home_dir):
+ prefix_path = os.path.normpath(prefix_path)
+ prefix = os.path.normpath(prefix)
+ home_dir = os.path.normpath(home_dir)
+ if not prefix_path.startswith(prefix):
+ logger.warn('Path not in prefix %r %r', prefix_path, prefix)
+ return
+ return prefix_path.replace(prefix, home_dir, 1)
+
+
+def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear):
+ """Install just the base environment, no distutils patches etc"""
+ if sys.executable.startswith(bin_dir):
+ print('Please use the *system* python to run this script')
+ return
+
+ if clear:
+ rmtree(lib_dir)
+ ## FIXME: why not delete it?
+ ## Maybe it should delete everything with #!/path/to/venv/python in it
+ logger.notify('Not deleting %s', bin_dir)
+
+ if hasattr(sys, 'real_prefix'):
+ logger.notify('Using real prefix %r' % sys.real_prefix)
+ prefix = sys.real_prefix
+ elif hasattr(sys, 'base_prefix'):
+ logger.notify('Using base prefix %r' % sys.base_prefix)
+ prefix = sys.base_prefix
+ else:
+ prefix = sys.prefix
+ mkdir(lib_dir)
+ fix_lib64(lib_dir)
+ stdlib_dirs = [os.path.dirname(os.__file__)]
+ if is_win:
+ stdlib_dirs.append(join(os.path.dirname(stdlib_dirs[0]), 'DLLs'))
+ elif is_darwin:
+ stdlib_dirs.append(join(stdlib_dirs[0], 'site-packages'))
+ if hasattr(os, 'symlink'):
+ logger.info('Symlinking Python bootstrap modules')
+ else:
+ logger.info('Copying Python bootstrap modules')
+ logger.indent += 2
+ try:
+ # copy required files...
+ for stdlib_dir in stdlib_dirs:
+ if not os.path.isdir(stdlib_dir):
+ continue
+ for fn in os.listdir(stdlib_dir):
+ bn = os.path.splitext(fn)[0]
+ if fn != 'site-packages' and bn in REQUIRED_FILES:
+ copyfile(join(stdlib_dir, fn), join(lib_dir, fn))
+ # ...and modules
+ copy_required_modules(home_dir)
+ finally:
+ logger.indent -= 2
+ mkdir(join(lib_dir, 'site-packages'))
+ import site
+ site_filename = site.__file__
+ if site_filename.endswith('.pyc'):
+ site_filename = site_filename[:-1]
+ elif site_filename.endswith('$py.class'):
+ site_filename = site_filename.replace('$py.class', '.py')
+ site_filename_dst = change_prefix(site_filename, home_dir)
+ site_dir = os.path.dirname(site_filename_dst)
+ writefile(site_filename_dst, SITE_PY)
+ writefile(join(site_dir, 'orig-prefix.txt'), prefix)
+ site_packages_filename = join(site_dir, 'no-global-site-packages.txt')
+ if not site_packages:
+ writefile(site_packages_filename, '')
+
+ if is_pypy or is_win:
+ stdinc_dir = join(prefix, 'include')
+ else:
+ stdinc_dir = join(prefix, 'include', py_version + abiflags)
+ if os.path.exists(stdinc_dir):
+ copyfile(stdinc_dir, inc_dir)
+ else:
+ logger.debug('No include dir %s' % stdinc_dir)
+
+ platinc_dir = distutils.sysconfig.get_python_inc(plat_specific=1)
+ if platinc_dir != stdinc_dir:
+ platinc_dest = distutils.sysconfig.get_python_inc(
+ plat_specific=1, prefix=home_dir)
+ if platinc_dir == platinc_dest:
+ # Do platinc_dest manually due to a CPython bug;
+ # not http://bugs.python.org/issue3386 but a close cousin
+ platinc_dest = subst_path(platinc_dir, prefix, home_dir)
+ if platinc_dest:
+ # PyPy's stdinc_dir and prefix are relative to the original binary
+ # (traversing virtualenvs), whereas the platinc_dir is relative to
+ # the inner virtualenv and ignores the prefix argument.
+ # This seems more evolved than designed.
+ copyfile(platinc_dir, platinc_dest)
+
+ # pypy never uses exec_prefix, just ignore it
+ if sys.exec_prefix != prefix and not is_pypy:
+ if is_win:
+ exec_dir = join(sys.exec_prefix, 'lib')
+ elif is_jython:
+ exec_dir = join(sys.exec_prefix, 'Lib')
+ else:
+ exec_dir = join(sys.exec_prefix, 'lib', py_version)
+ for fn in os.listdir(exec_dir):
+ copyfile(join(exec_dir, fn), join(lib_dir, fn))
+
+ if is_jython:
+ # Jython has either jython-dev.jar and javalib/ dir, or just
+ # jython.jar
+ for name in 'jython-dev.jar', 'javalib', 'jython.jar':
+ src = join(prefix, name)
+ if os.path.exists(src):
+ copyfile(src, join(home_dir, name))
+ # XXX: registry should always exist after Jython 2.5rc1
+ src = join(prefix, 'registry')
+ if os.path.exists(src):
+ copyfile(src, join(home_dir, 'registry'), symlink=False)
+ copyfile(join(prefix, 'cachedir'), join(home_dir, 'cachedir'),
+ symlink=False)
+
+ mkdir(bin_dir)
+ py_executable = join(bin_dir, os.path.basename(sys.executable))
+ if 'Python.framework' in prefix:
+ # OS X framework builds cause validation to break
+ # https://github.com/pypa/virtualenv/issues/322
+ if os.environ.get('__PYVENV_LAUNCHER__'):
+ os.unsetenv('__PYVENV_LAUNCHER__')
+ if re.search(r'/Python(?:-32|-64)*$', py_executable):
+ # The name of the python executable is not quite what
+ # we want, rename it.
+ py_executable = os.path.join(
+ os.path.dirname(py_executable), 'python')
+
+ logger.notify('New %s executable in %s', expected_exe, py_executable)
+ pcbuild_dir = os.path.dirname(sys.executable)
+ pyd_pth = os.path.join(lib_dir, 'site-packages', 'virtualenv_builddir_pyd.pth')
+ if is_win and os.path.exists(os.path.join(pcbuild_dir, 'build.bat')):
+ logger.notify('Detected python running from build directory %s', pcbuild_dir)
+ logger.notify('Writing .pth file linking to build directory for *.pyd files')
+ writefile(pyd_pth, pcbuild_dir)
+ else:
+ pcbuild_dir = None
+ if os.path.exists(pyd_pth):
+ logger.info('Deleting %s (not Windows env or not build directory python)' % pyd_pth)
+ os.unlink(pyd_pth)
+
+ if sys.executable != py_executable:
+ ## FIXME: could I just hard link?
+ executable = sys.executable
+ shutil.copyfile(executable, py_executable)
+ make_exe(py_executable)
+ if is_win or is_cygwin:
+ pythonw = os.path.join(os.path.dirname(sys.executable), 'pythonw.exe')
+ if os.path.exists(pythonw):
+ logger.info('Also created pythonw.exe')
+ shutil.copyfile(pythonw, os.path.join(os.path.dirname(py_executable), 'pythonw.exe'))
+ python_d = os.path.join(os.path.dirname(sys.executable), 'python_d.exe')
+ python_d_dest = os.path.join(os.path.dirname(py_executable), 'python_d.exe')
+ if os.path.exists(python_d):
+ logger.info('Also created python_d.exe')
+ shutil.copyfile(python_d, python_d_dest)
+ elif os.path.exists(python_d_dest):
+ logger.info('Removed python_d.exe as it is no longer at the source')
+ os.unlink(python_d_dest)
+ # we need to copy the DLL to enforce that windows will load the correct one.
+ # may not exist if we are cygwin.
+ py_executable_dll = 'python%s%s.dll' % (
+ sys.version_info[0], sys.version_info[1])
+ py_executable_dll_d = 'python%s%s_d.dll' % (
+ sys.version_info[0], sys.version_info[1])
+ pythondll = os.path.join(os.path.dirname(sys.executable), py_executable_dll)
+ pythondll_d = os.path.join(os.path.dirname(sys.executable), py_executable_dll_d)
+ pythondll_d_dest = os.path.join(os.path.dirname(py_executable), py_executable_dll_d)
+ if os.path.exists(pythondll):
+ logger.info('Also created %s' % py_executable_dll)
+ shutil.copyfile(pythondll, os.path.join(os.path.dirname(py_executable), py_executable_dll))
+ if os.path.exists(pythondll_d):
+ logger.info('Also created %s' % py_executable_dll_d)
+ shutil.copyfile(pythondll_d, pythondll_d_dest)
+ elif os.path.exists(pythondll_d_dest):
+ logger.info('Removed %s as the source does not exist' % pythondll_d_dest)
+ os.unlink(pythondll_d_dest)
+ if is_pypy:
+ # make a symlink python --> pypy-c
+ python_executable = os.path.join(os.path.dirname(py_executable), 'python')
+ if sys.platform in ('win32', 'cygwin'):
+ python_executable += '.exe'
+ logger.info('Also created executable %s' % python_executable)
+ copyfile(py_executable, python_executable)
+
+ if is_win:
+ for name in 'libexpat.dll', 'libpypy.dll', 'libpypy-c.dll', 'libeay32.dll', 'ssleay32.dll', 'sqlite.dll':
+ src = join(prefix, name)
+ if os.path.exists(src):
+ copyfile(src, join(bin_dir, name))
+
+ if os.path.splitext(os.path.basename(py_executable))[0] != expected_exe:
+ secondary_exe = os.path.join(os.path.dirname(py_executable),
+ expected_exe)
+ py_executable_ext = os.path.splitext(py_executable)[1]
+ if py_executable_ext == '.exe':
+ # python2.4 gives an extension of '.4' :P
+ secondary_exe += py_executable_ext
+ if os.path.exists(secondary_exe):
+ logger.warn('Not overwriting existing %s script %s (you must use %s)'
+ % (expected_exe, secondary_exe, py_executable))
+ else:
+ logger.notify('Also creating executable in %s' % secondary_exe)
+ shutil.copyfile(sys.executable, secondary_exe)
+ make_exe(secondary_exe)
+
+ if '.framework' in prefix:
+ if 'Python.framework' in prefix:
+ logger.debug('MacOSX Python framework detected')
+ # Make sure we use the the embedded interpreter inside
+ # the framework, even if sys.executable points to
+ # the stub executable in ${sys.prefix}/bin
+ # See http://groups.google.com/group/python-virtualenv/
+ # browse_thread/thread/17cab2f85da75951
+ original_python = os.path.join(
+ prefix, 'Resources/Python.app/Contents/MacOS/Python')
+ if 'EPD' in prefix:
+ logger.debug('EPD framework detected')
+ original_python = os.path.join(prefix, 'bin/python')
+ shutil.copy(original_python, py_executable)
+
+ # Copy the framework's dylib into the virtual
+ # environment
+ virtual_lib = os.path.join(home_dir, '.Python')
+
+ if os.path.exists(virtual_lib):
+ os.unlink(virtual_lib)
+ copyfile(
+ os.path.join(prefix, 'Python'),
+ virtual_lib)
+
+ # And then change the install_name of the copied python executable
+ try:
+ mach_o_change(py_executable,
+ os.path.join(prefix, 'Python'),
+ '@executable_path/../.Python')
+ except:
+ e = sys.exc_info()[1]
+ logger.warn("Could not call mach_o_change: %s. "
+ "Trying to call install_name_tool instead." % e)
+ try:
+ call_subprocess(
+ ["install_name_tool", "-change",
+ os.path.join(prefix, 'Python'),
+ '@executable_path/../.Python',
+ py_executable])
+ except:
+ logger.fatal("Could not call install_name_tool -- you must "
+ "have Apple's development tools installed")
+ raise
+
+ if not is_win:
+ # Ensure that 'python', 'pythonX' and 'pythonX.Y' all exist
+ py_exe_version_major = 'python%s' % sys.version_info[0]
+ py_exe_version_major_minor = 'python%s.%s' % (
+ sys.version_info[0], sys.version_info[1])
+ py_exe_no_version = 'python'
+ required_symlinks = [ py_exe_no_version, py_exe_version_major,
+ py_exe_version_major_minor ]
+
+ py_executable_base = os.path.basename(py_executable)
+
+ if py_executable_base in required_symlinks:
+ # Don't try to symlink to yourself.
+ required_symlinks.remove(py_executable_base)
+
+ for pth in required_symlinks:
+ full_pth = join(bin_dir, pth)
+ if os.path.exists(full_pth):
+ os.unlink(full_pth)
+ os.symlink(py_executable_base, full_pth)
+
+ if is_win and ' ' in py_executable:
+ # There's a bug with subprocess on Windows when using a first
+ # argument that has a space in it. Instead we have to quote
+ # the value:
+ py_executable = '"%s"' % py_executable
+ # NOTE: keep this check as one line, cmd.exe doesn't cope with line breaks
+ cmd = [py_executable, '-c', 'import sys;out=sys.stdout;'
+ 'getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))']
+ logger.info('Testing executable with %s %s "%s"' % tuple(cmd))
+ try:
+ proc = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE)
+ proc_stdout, proc_stderr = proc.communicate()
+ except OSError:
+ e = sys.exc_info()[1]
+ if e.errno == errno.EACCES:
+ logger.fatal('ERROR: The executable %s could not be run: %s' % (py_executable, e))
+ sys.exit(100)
+ else:
+ raise e
+
+ proc_stdout = proc_stdout.strip().decode("utf-8")
+ proc_stdout = os.path.normcase(os.path.abspath(proc_stdout))
+ norm_home_dir = os.path.normcase(os.path.abspath(home_dir))
+ if hasattr(norm_home_dir, 'decode'):
+ norm_home_dir = norm_home_dir.decode(sys.getfilesystemencoding())
+ if proc_stdout != norm_home_dir:
+ logger.fatal(
+ 'ERROR: The executable %s is not functioning' % py_executable)
+ logger.fatal(
+ 'ERROR: It thinks sys.prefix is %r (should be %r)'
+ % (proc_stdout, norm_home_dir))
+ logger.fatal(
+ 'ERROR: virtualenv is not compatible with this system or executable')
+ if is_win:
+ logger.fatal(
+ 'Note: some Windows users have reported this error when they '
+ 'installed Python for "Only this user" or have multiple '
+ 'versions of Python installed. Copying the appropriate '
+ 'PythonXX.dll to the virtualenv Scripts/ directory may fix '
+ 'this problem.')
+ sys.exit(100)
+ else:
+ logger.info('Got sys.prefix result: %r' % proc_stdout)
+
+ pydistutils = os.path.expanduser('~/.pydistutils.cfg')
+ if os.path.exists(pydistutils):
+ logger.notify('Please make sure you remove any previous custom paths from '
+ 'your %s file.' % pydistutils)
+ ## FIXME: really this should be calculated earlier
+
+ fix_local_scheme(home_dir)
+
+ if site_packages:
+ if os.path.exists(site_packages_filename):
+ logger.info('Deleting %s' % site_packages_filename)
+ os.unlink(site_packages_filename)
+
+ return py_executable
+
+
+def install_activate(home_dir, bin_dir, prompt=None):
+ home_dir = os.path.abspath(home_dir)
+ if is_win or is_jython and os._name == 'nt':
+ files = {
+ 'activate.bat': ACTIVATE_BAT,
+ 'deactivate.bat': DEACTIVATE_BAT,
+ 'activate.ps1': ACTIVATE_PS,
+ }
+
+ # MSYS needs paths of the form /c/path/to/file
+ drive, tail = os.path.splitdrive(home_dir.replace(os.sep, '/'))
+ home_dir_msys = (drive and "/%s%s" or "%s%s") % (drive[:1], tail)
+
+ # Run-time conditional enables (basic) Cygwin compatibility
+ home_dir_sh = ("""$(if [ "$OSTYPE" "==" "cygwin" ]; then cygpath -u '%s'; else echo '%s'; fi;)""" %
+ (home_dir, home_dir_msys))
+ files['activate'] = ACTIVATE_SH.replace('__VIRTUAL_ENV__', home_dir_sh)
+
+ else:
+ files = {'activate': ACTIVATE_SH}
+
+ # suppling activate.fish in addition to, not instead of, the
+ # bash script support.
+ files['activate.fish'] = ACTIVATE_FISH
+
+ # same for csh/tcsh support...
+ files['activate.csh'] = ACTIVATE_CSH
+
+ files['activate_this.py'] = ACTIVATE_THIS
+ if hasattr(home_dir, 'decode'):
+ home_dir = home_dir.decode(sys.getfilesystemencoding())
+ vname = os.path.basename(home_dir)
+ for name, content in files.items():
+ content = content.replace('__VIRTUAL_PROMPT__', prompt or '')
+ content = content.replace('__VIRTUAL_WINPROMPT__', prompt or '(%s)' % vname)
+ content = content.replace('__VIRTUAL_ENV__', home_dir)
+ content = content.replace('__VIRTUAL_NAME__', vname)
+ content = content.replace('__BIN_NAME__', os.path.basename(bin_dir))
+ writefile(os.path.join(bin_dir, name), content)
+
+def install_distutils(home_dir):
+ distutils_path = change_prefix(distutils.__path__[0], home_dir)
+ mkdir(distutils_path)
+ ## FIXME: maybe this prefix setting should only be put in place if
+ ## there's a local distutils.cfg with a prefix setting?
+ home_dir = os.path.abspath(home_dir)
+ ## FIXME: this is breaking things, removing for now:
+ #distutils_cfg = DISTUTILS_CFG + "\n[install]\nprefix=%s\n" % home_dir
+ writefile(os.path.join(distutils_path, '__init__.py'), DISTUTILS_INIT)
+ writefile(os.path.join(distutils_path, 'distutils.cfg'), DISTUTILS_CFG, overwrite=False)
+
+def fix_local_scheme(home_dir):
+ """
+ Platforms that use the "posix_local" install scheme (like Ubuntu with
+ Python 2.7) need to be given an additional "local" location, sigh.
+ """
+ try:
+ import sysconfig
+ except ImportError:
+ pass
+ else:
+ if sysconfig._get_default_scheme() == 'posix_local':
+ local_path = os.path.join(home_dir, 'local')
+ if not os.path.exists(local_path):
+ os.mkdir(local_path)
+ for subdir_name in os.listdir(home_dir):
+ if subdir_name == 'local':
+ continue
+ os.symlink(os.path.abspath(os.path.join(home_dir, subdir_name)), \
+ os.path.join(local_path, subdir_name))
+
+def fix_lib64(lib_dir):
+ """
+ Some platforms (particularly Gentoo on x64) put things in lib64/pythonX.Y
+ instead of lib/pythonX.Y. If this is such a platform we'll just create a
+ symlink so lib64 points to lib
+ """
+ if [p for p in distutils.sysconfig.get_config_vars().values()
+ if isinstance(p, basestring) and 'lib64' in p]:
+ logger.debug('This system uses lib64; symlinking lib64 to lib')
+ assert os.path.basename(lib_dir) == 'python%s' % sys.version[:3], (
+ "Unexpected python lib dir: %r" % lib_dir)
+ lib_parent = os.path.dirname(lib_dir)
+ top_level = os.path.dirname(lib_parent)
+ lib_dir = os.path.join(top_level, 'lib')
+ lib64_link = os.path.join(top_level, 'lib64')
+ assert os.path.basename(lib_parent) == 'lib', (
+ "Unexpected parent dir: %r" % lib_parent)
+ if os.path.lexists(lib64_link):
+ return
+ os.symlink('lib', lib64_link)
+
+def resolve_interpreter(exe):
+ """
+ If the executable given isn't an absolute path, search $PATH for the interpreter
+ """
+ if os.path.abspath(exe) != exe:
+ paths = os.environ.get('PATH', '').split(os.pathsep)
+ for path in paths:
+ if os.path.exists(os.path.join(path, exe)):
+ exe = os.path.join(path, exe)
+ break
+ if not os.path.exists(exe):
+ logger.fatal('The executable %s (from --python=%s) does not exist' % (exe, exe))
+ raise SystemExit(3)
+ if not is_executable(exe):
+ logger.fatal('The executable %s (from --python=%s) is not executable' % (exe, exe))
+ raise SystemExit(3)
+ return exe
+
+def is_executable(exe):
+ """Checks a file is executable"""
+ return os.access(exe, os.X_OK)
+
+############################################################
+## Relocating the environment:
+
+def make_environment_relocatable(home_dir):
+ """
+ Makes the already-existing environment use relative paths, and takes out
+ the #!-based environment selection in scripts.
+ """
+ home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
+ activate_this = os.path.join(bin_dir, 'activate_this.py')
+ if not os.path.exists(activate_this):
+ logger.fatal(
+ 'The environment doesn\'t have a file %s -- please re-run virtualenv '
+ 'on this environment to update it' % activate_this)
+ fixup_scripts(home_dir)
+ fixup_pth_and_egg_link(home_dir)
+ ## FIXME: need to fix up distutils.cfg
+
+OK_ABS_SCRIPTS = ['python', 'python%s' % sys.version[:3],
+ 'activate', 'activate.bat', 'activate_this.py']
+
+def fixup_scripts(home_dir):
+ # This is what we expect at the top of scripts:
+ shebang = '#!%s/bin/python' % os.path.normcase(os.path.abspath(home_dir))
+ # This is what we'll put:
+ new_shebang = '#!/usr/bin/env python%s' % sys.version[:3]
+ if is_win:
+ bin_suffix = 'Scripts'
+ else:
+ bin_suffix = 'bin'
+ bin_dir = os.path.join(home_dir, bin_suffix)
+ home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
+ for filename in os.listdir(bin_dir):
+ filename = os.path.join(bin_dir, filename)
+ if not os.path.isfile(filename):
+ # ignore subdirs, e.g. .svn ones.
+ continue
+ f = open(filename, 'rb')
+ try:
+ try:
+ lines = f.read().decode('utf-8').splitlines()
+ except UnicodeDecodeError:
+ # This is probably a binary program instead
+ # of a script, so just ignore it.
+ continue
+ finally:
+ f.close()
+ if not lines:
+ logger.warn('Script %s is an empty file' % filename)
+ continue
+ if not lines[0].strip().startswith(shebang):
+ if os.path.basename(filename) in OK_ABS_SCRIPTS:
+ logger.debug('Cannot make script %s relative' % filename)
+ elif lines[0].strip() == new_shebang:
+ logger.info('Script %s has already been made relative' % filename)
+ else:
+ logger.warn('Script %s cannot be made relative (it\'s not a normal script that starts with %s)'
+ % (filename, shebang))
+ continue
+ logger.notify('Making script %s relative' % filename)
+ script = relative_script([new_shebang] + lines[1:])
+ f = open(filename, 'wb')
+ f.write('\n'.join(script).encode('utf-8'))
+ f.close()
+
+def relative_script(lines):
+ "Return a script that'll work in a relocatable environment."
+ activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this"
+ # Find the last future statement in the script. If we insert the activation
+ # line before a future statement, Python will raise a SyntaxError.
+ activate_at = None
+ for idx, line in reversed(list(enumerate(lines))):
+ if line.split()[:3] == ['from', '__future__', 'import']:
+ activate_at = idx + 1
+ break
+ if activate_at is None:
+ # Activate after the shebang.
+ activate_at = 1
+ return lines[:activate_at] + ['', activate, ''] + lines[activate_at:]
+
+def fixup_pth_and_egg_link(home_dir, sys_path=None):
+ """Makes .pth and .egg-link files use relative paths"""
+ home_dir = os.path.normcase(os.path.abspath(home_dir))
+ if sys_path is None:
+ sys_path = sys.path
+ for path in sys_path:
+ if not path:
+ path = '.'
+ if not os.path.isdir(path):
+ continue
+ path = os.path.normcase(os.path.abspath(path))
+ if not path.startswith(home_dir):
+ logger.debug('Skipping system (non-environment) directory %s' % path)
+ continue
+ for filename in os.listdir(path):
+ filename = os.path.join(path, filename)
+ if filename.endswith('.pth'):
+ if not os.access(filename, os.W_OK):
+ logger.warn('Cannot write .pth file %s, skipping' % filename)
+ else:
+ fixup_pth_file(filename)
+ if filename.endswith('.egg-link'):
+ if not os.access(filename, os.W_OK):
+ logger.warn('Cannot write .egg-link file %s, skipping' % filename)
+ else:
+ fixup_egg_link(filename)
+
+def fixup_pth_file(filename):
+ lines = []
+ prev_lines = []
+ f = open(filename)
+ prev_lines = f.readlines()
+ f.close()
+ for line in prev_lines:
+ line = line.strip()
+ if (not line or line.startswith('#') or line.startswith('import ')
+ or os.path.abspath(line) != line):
+ lines.append(line)
+ else:
+ new_value = make_relative_path(filename, line)
+ if line != new_value:
+ logger.debug('Rewriting path %s as %s (in %s)' % (line, new_value, filename))
+ lines.append(new_value)
+ if lines == prev_lines:
+ logger.info('No changes to .pth file %s' % filename)
+ return
+ logger.notify('Making paths in .pth file %s relative' % filename)
+ f = open(filename, 'w')
+ f.write('\n'.join(lines) + '\n')
+ f.close()
+
+def fixup_egg_link(filename):
+ f = open(filename)
+ link = f.readline().strip()
+ f.close()
+ if os.path.abspath(link) != link:
+ logger.debug('Link in %s already relative' % filename)
+ return
+ new_link = make_relative_path(filename, link)
+ logger.notify('Rewriting link %s in %s as %s' % (link, filename, new_link))
+ f = open(filename, 'w')
+ f.write(new_link)
+ f.close()
+
+def make_relative_path(source, dest, dest_is_directory=True):
+ """
+ Make a filename relative, where the filename is dest, and it is
+ being referred to from the filename source.
+
+ >>> make_relative_path('/usr/share/something/a-file.pth',
+ ... '/usr/share/another-place/src/Directory')
+ '../another-place/src/Directory'
+ >>> make_relative_path('/usr/share/something/a-file.pth',
+ ... '/home/user/src/Directory')
+ '../../../home/user/src/Directory'
+ >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
+ './'
+ """
+ source = os.path.dirname(source)
+ if not dest_is_directory:
+ dest_filename = os.path.basename(dest)
+ dest = os.path.dirname(dest)
+ dest = os.path.normpath(os.path.abspath(dest))
+ source = os.path.normpath(os.path.abspath(source))
+ dest_parts = dest.strip(os.path.sep).split(os.path.sep)
+ source_parts = source.strip(os.path.sep).split(os.path.sep)
+ while dest_parts and source_parts and dest_parts[0] == source_parts[0]:
+ dest_parts.pop(0)
+ source_parts.pop(0)
+ full_parts = ['..']*len(source_parts) + dest_parts
+ if not dest_is_directory:
+ full_parts.append(dest_filename)
+ if not full_parts:
+ # Special case for the current directory (otherwise it'd be '')
+ return './'
+ return os.path.sep.join(full_parts)
+
+
+
+############################################################
+## Bootstrap script creation:
+
+def create_bootstrap_script(extra_text, python_version=''):
+ """
+ Creates a bootstrap script, which is like this script but with
+ extend_parser, adjust_options, and after_install hooks.
+
+ This returns a string that (written to disk of course) can be used
+ as a bootstrap script with your own customizations. The script
+ will be the standard virtualenv.py script, with your extra text
+ added (your extra text should be Python code).
+
+ If you include these functions, they will be called:
+
+ ``extend_parser(optparse_parser)``:
+ You can add or remove options from the parser here.
+
+ ``adjust_options(options, args)``:
+ You can change options here, or change the args (if you accept
+ different kinds of arguments, be sure you modify ``args`` so it is
+ only ``[DEST_DIR]``).
+
+ ``after_install(options, home_dir)``:
+
+ After everything is installed, this function is called. This
+ is probably the function you are most likely to use. An
+ example would be::
+
+ def after_install(options, home_dir):
+ subprocess.call([join(home_dir, 'bin', 'easy_install'),
+ 'MyPackage'])
+ subprocess.call([join(home_dir, 'bin', 'my-package-script'),
+ 'setup', home_dir])
+
+ This example immediately installs a package, and runs a setup
+ script from that package.
+
+ If you provide something like ``python_version='2.5'`` then the
+ script will start with ``#!/usr/bin/env python2.5`` instead of
+ ``#!/usr/bin/env python``. You can use this when the script must
+ be run with a particular Python version.
+ """
+ filename = __file__
+ if filename.endswith('.pyc'):
+ filename = filename[:-1]
+ f = codecs.open(filename, 'r', encoding='utf-8')
+ content = f.read()
+ f.close()
+ py_exe = 'python%s' % python_version
+ content = (('#!/usr/bin/env %s\n' % py_exe)
+ + '## WARNING: This file is generated\n'
+ + content)
+ return content.replace('##EXT' 'END##', extra_text)
+
+##EXTEND##
+
+def convert(s):
+ b = base64.b64decode(s.encode('ascii'))
+ return zlib.decompress(b).decode('utf-8')
+
+##file site.py
+SITE_PY = convert("""
+eJzFPf1z2zaWv/OvwMqToZTIdOK0vR2nzo2TOK3v3MTbpLO5dT1aSoIs1hTJ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M = 0xcefaedfe
+MH_MAGIC_64 = 0xfeedfacf
+MH_CIGAM_64 = 0xcffaedfe
+FAT_MAGIC = 0xcafebabe
+BIG_ENDIAN = '>'
+LITTLE_ENDIAN = '<'
+LC_LOAD_DYLIB = 0xc
+maxint = majver == 3 and getattr(sys, 'maxsize') or getattr(sys, 'maxint')
+
+
+class fileview(object):
+ """
+ A proxy for file-like objects that exposes a given view of a file.
+ Modified from macholib.
+ """
+
+ def __init__(self, fileobj, start=0, size=maxint):
+ if isinstance(fileobj, fileview):
+ self._fileobj = fileobj._fileobj
+ else:
+ self._fileobj = fileobj
+ self._start = start
+ self._end = start + size
+ self._pos = 0
+
+ def __repr__(self):
+ return '<fileview [%d, %d] %r>' % (
+ self._start, self._end, self._fileobj)
+
+ def tell(self):
+ return self._pos
+
+ def _checkwindow(self, seekto, op):
+ if not (self._start <= seekto <= self._end):
+ raise IOError("%s to offset %d is outside window [%d, %d]" % (
+ op, seekto, self._start, self._end))
+
+ def seek(self, offset, whence=0):
+ seekto = offset
+ if whence == os.SEEK_SET:
+ seekto += self._start
+ elif whence == os.SEEK_CUR:
+ seekto += self._start + self._pos
+ elif whence == os.SEEK_END:
+ seekto += self._end
+ else:
+ raise IOError("Invalid whence argument to seek: %r" % (whence,))
+ self._checkwindow(seekto, 'seek')
+ self._fileobj.seek(seekto)
+ self._pos = seekto - self._start
+
+ def write(self, bytes):
+ here = self._start + self._pos
+ self._checkwindow(here, 'write')
+ self._checkwindow(here + len(bytes), 'write')
+ self._fileobj.seek(here, os.SEEK_SET)
+ self._fileobj.write(bytes)
+ self._pos += len(bytes)
+
+ def read(self, size=maxint):
+ assert size >= 0
+ here = self._start + self._pos
+ self._checkwindow(here, 'read')
+ size = min(size, self._end - here)
+ self._fileobj.seek(here, os.SEEK_SET)
+ bytes = self._fileobj.read(size)
+ self._pos += len(bytes)
+ return bytes
+
+
+def read_data(file, endian, num=1):
+ """
+ Read a given number of 32-bits unsigned integers from the given file
+ with the given endianness.
+ """
+ res = struct.unpack(endian + 'L' * num, file.read(num * 4))
+ if len(res) == 1:
+ return res[0]
+ return res
+
+
+def mach_o_change(path, what, value):
+ """
+ Replace a given name (what) in any LC_LOAD_DYLIB command found in
+ the given binary with a new name (value), provided it's shorter.
+ """
+
+ def do_macho(file, bits, endian):
+ # Read Mach-O header (the magic number is assumed read by the caller)
+ cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags = read_data(file, endian, 6)
+ # 64-bits header has one more field.
+ if bits == 64:
+ read_data(file, endian)
+ # The header is followed by ncmds commands
+ for n in range(ncmds):
+ where = file.tell()
+ # Read command header
+ cmd, cmdsize = read_data(file, endian, 2)
+ if cmd == LC_LOAD_DYLIB:
+ # The first data field in LC_LOAD_DYLIB commands is the
+ # offset of the name, starting from the beginning of the
+ # command.
+ name_offset = read_data(file, endian)
+ file.seek(where + name_offset, os.SEEK_SET)
+ # Read the NUL terminated string
+ load = file.read(cmdsize - name_offset).decode()
+ load = load[:load.index('\0')]
+ # If the string is what is being replaced, overwrite it.
+ if load == what:
+ file.seek(where + name_offset, os.SEEK_SET)
+ file.write(value.encode() + '\0'.encode())
+ # Seek to the next command
+ file.seek(where + cmdsize, os.SEEK_SET)
+
+ def do_file(file, offset=0, size=maxint):
+ file = fileview(file, offset, size)
+ # Read magic number
+ magic = read_data(file, BIG_ENDIAN)
+ if magic == FAT_MAGIC:
+ # Fat binaries contain nfat_arch Mach-O binaries
+ nfat_arch = read_data(file, BIG_ENDIAN)
+ for n in range(nfat_arch):
+ # Read arch header
+ cputype, cpusubtype, offset, size, align = read_data(file, BIG_ENDIAN, 5)
+ do_file(file, offset, size)
+ elif magic == MH_MAGIC:
+ do_macho(file, 32, BIG_ENDIAN)
+ elif magic == MH_CIGAM:
+ do_macho(file, 32, LITTLE_ENDIAN)
+ elif magic == MH_MAGIC_64:
+ do_macho(file, 64, BIG_ENDIAN)
+ elif magic == MH_CIGAM_64:
+ do_macho(file, 64, LITTLE_ENDIAN)
+
+ assert(len(what) >= len(value))
+ do_file(open(path, 'r+b'))
+
+
+if __name__ == '__main__':
+ main()
+
+## TODO:
+## Copy python.exe.manifest
+## Monkeypatch distutils.sysconfig
Binary file virtualenv/web/virtualenv_support/distribute-0.6.34.tar.gz has changed
Binary file virtualenv/web/virtualenv_support/pip-1.3.1.tar.gz has changed
Binary file virtualenv/web/virtualenv_support/setuptools-0.6c11-py2.5.egg has changed
Binary file virtualenv/web/virtualenv_support/setuptools-0.6c11-py2.6.egg has changed
Binary file virtualenv/web/virtualenv_support/setuptools-0.6c11-py2.7.egg has changed