Compare commits
23 Commits
wip_revisi
...
master
Author | SHA1 | Date |
---|---|---|
François Poulain | 41e7200fc1 | |
François Poulain | ae576d1a38 | |
François Poulain | 75eae59ee4 | |
François Poulain | 3f20b966cd | |
François Poulain | 83b6d71850 | |
François Poulain | 2b169ee80f | |
François Poulain | 8ea43a3727 | |
François Poulain | 3aa82a786f | |
François Poulain | 11114ce004 | |
François Poulain | d020005721 | |
François Poulain | 926b1bd91f | |
François Poulain | 734deddfc5 | |
François Poulain | 9360cc134e | |
François Poulain | e4816bc2ee | |
François Poulain | 7ce36668ea | |
François Poulain | db6bd48e20 | |
François Poulain | 578e02bb3e | |
François Poulain | c8a075fc7a | |
François Poulain | cc923c59a2 | |
François Poulain | 8c3944b5bf | |
François Poulain | 1bfcbd6086 | |
François Poulain | 08cc965af4 | |
François Poulain | cb563ffca5 |
99
README.md
99
README.md
|
@ -4,13 +4,25 @@ Convertisseur Drupal 6 vers SPIP pour le site web libre à lire
|
||||||
|
|
||||||
**Table of content**
|
**Table of content**
|
||||||
|
|
||||||
- [Give a try](#give-a-try)
|
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Deployment](#deployment)
|
- [Usage](#usage)
|
||||||
- [Structure](#structure)
|
- [Structure](#structure)
|
||||||
- [Development](#development)
|
- [Development](#development)
|
||||||
|
|
||||||
## Give a try
|
## Installation
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
On a Debian-based host - running at least Debian Stretch, you will need the
|
||||||
|
following packages:
|
||||||
|
- python3
|
||||||
|
- virtualenv
|
||||||
|
- make
|
||||||
|
- git (recommended for getting the source)
|
||||||
|
- python3-mysqldb (optional, in case of a MySQL / MariaDB database)
|
||||||
|
- python3-psycopg2 (optional, in case of a PostgreSQL database)
|
||||||
|
|
||||||
|
### Let's go
|
||||||
|
|
||||||
On a Debian-based host - running at least Debian Stretch:
|
On a Debian-based host - running at least Debian Stretch:
|
||||||
|
|
||||||
|
@ -37,76 +49,14 @@ Then try:
|
||||||
```
|
```
|
||||||
$ make inspectdb
|
$ make inspectdb
|
||||||
$ make check
|
$ make check
|
||||||
$ venv/bin/python manage.py import --help
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Usage
|
||||||
### Requirements
|
|
||||||
|
|
||||||
On a Debian-based host - running at least Debian Stretch, you will need the
|
See:
|
||||||
following packages:
|
```
|
||||||
- python3
|
$ venv/bin/python manage.py import --help
|
||||||
- virtualenv
|
```
|
||||||
- make
|
|
||||||
- git (recommended for getting the source)
|
|
||||||
- python3-mysqldb (optional, in case of a MySQL / MariaDB database)
|
|
||||||
- python3-psycopg2 (optional, in case of a PostgreSQL database)
|
|
||||||
|
|
||||||
### Quick start
|
|
||||||
|
|
||||||
It assumes that you already have the application source code locally - the best
|
|
||||||
way is by cloning this repository - and that you are in this folder.
|
|
||||||
|
|
||||||
1. Define your local configuration in a file named `config.env`, which can be
|
|
||||||
copied from `config.env.example` and edited to suits your needs.
|
|
||||||
|
|
||||||
Depending on your environment, you will have to create your database and the
|
|
||||||
user at first.
|
|
||||||
|
|
||||||
2. Run `make init`.
|
|
||||||
|
|
||||||
Note that if there is no `config.env` file, it will be created interactively.
|
|
||||||
|
|
||||||
That's it! Your environment is now initialized with the application installed.
|
|
||||||
To update it, once the source code is checked out, simply run `make update`.
|
|
||||||
|
|
||||||
You can also check that your application is well configured by running
|
|
||||||
`make check`.
|
|
||||||
|
|
||||||
### Manual installation
|
|
||||||
|
|
||||||
If you don't want to use the `Makefile` facilities, here is what is done behind the scene.
|
|
||||||
|
|
||||||
It assumes that you have downloaded the last release of drupal2spip_lal,
|
|
||||||
extracted it and that you moved to that folder.
|
|
||||||
|
|
||||||
1. Start by creating a new virtual environment under `./venv` and activate it:
|
|
||||||
|
|
||||||
$ virtualenv --system-site-packages ./venv
|
|
||||||
$ source ./venv/bin/activate
|
|
||||||
|
|
||||||
2. Install the required Python packages depending on your environment:
|
|
||||||
|
|
||||||
$ pip install -r requirements/production.txt
|
|
||||||
... or ...
|
|
||||||
$ pip install -r requirements/development.txt
|
|
||||||
|
|
||||||
3. Configure the application by setting the proper environment variables
|
|
||||||
depending on your environment. You can use the `config.env.example` which
|
|
||||||
give you the main variables with example values.
|
|
||||||
|
|
||||||
$ cp config.env.example config.env
|
|
||||||
$ nano config.env
|
|
||||||
$ chmod go-rwx config.env
|
|
||||||
|
|
||||||
Note that this `./config.env` file will be loaded by default when the
|
|
||||||
application starts. If you don't want that, just move this file away or set
|
|
||||||
the `READ_CONFIG_FILE` environment variable to `0`.
|
|
||||||
|
|
||||||
4. Create the database tables - it assumes that you have created the database
|
|
||||||
and set the proper configuration to use it:
|
|
||||||
|
|
||||||
$ ./manage.py migrate
|
|
||||||
|
|
||||||
That's it!
|
That's it!
|
||||||
|
|
||||||
|
@ -120,9 +70,7 @@ Two environments are defined - either for requirements and settings:
|
||||||
- `development`: for local application development and testing. It uses a
|
- `development`: for local application development and testing. It uses a
|
||||||
SQLite3 database and enable debugging by default, add some useful settings
|
SQLite3 database and enable debugging by default, add some useful settings
|
||||||
and applications for development purpose - i.e. the `django-debug-toolbar`.
|
and applications for development purpose - i.e. the `django-debug-toolbar`.
|
||||||
- `production`: for production. It checks that configuration is set and
|
- `production`: for production. Unused here.
|
||||||
correct, try to optimize performances and enforce some settings - i.e. HTTPS
|
|
||||||
related ones.
|
|
||||||
|
|
||||||
### Local changes
|
### Local changes
|
||||||
|
|
||||||
|
@ -157,9 +105,10 @@ There is some additional rules when developing, which are mainly wrappers for
|
||||||
- `make test`: test the whole application
|
- `make test`: test the whole application
|
||||||
- `make lint`: check the Python code syntax
|
- `make lint`: check the Python code syntax
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
drupal2spip_lal is developed by François Poulain (April) and licensed under the
|
drupal2spip_lal is developed by François Poulain (April) and licensed under the
|
||||||
[AGPLv3+](LICENSE). Its basis comes from https://forge.cliss21.org/cliss21/cookiecutter-django/
|
[AGPLv3+](LICENSE). Its basis comes from https://forge.cliss21.org/cliss21/cookiecutter-django/
|
||||||
|
|
||||||
|
It embed code from Drupal 6 in drupal2spip_lal/base/php. This code is licensed
|
||||||
|
under the [GPLv2+](LICENSE).
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from subprocess import PIPE, Popen
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.models import F
|
||||||
from django.utils.timezone import make_aware, now
|
from django.utils.timezone import make_aware, now
|
||||||
|
|
||||||
import request
|
import mediafile
|
||||||
|
import requests
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from drupal2spip_lal.drupal import models as drupal
|
from drupal2spip_lal.drupal import models as drupal
|
||||||
from drupal2spip_lal.spip import models as spip
|
from drupal2spip_lal.spip import models as spip
|
||||||
|
|
||||||
# Questions
|
logger = logging.getLogger('drupal2spip_lal')
|
||||||
# - quelle utilisation des rubriques ?
|
|
||||||
# - quelle hiérarchie des mots clés ?
|
|
||||||
# - autobr sélectif ?
|
|
||||||
# - importer les drupaleries ? (fn, toc, etc.) + autobr selon le format
|
|
||||||
# - convertir en format SPIP ?
|
|
||||||
|
|
||||||
|
|
||||||
def convert_timestamp(timestamp):
|
def convert_timestamp(timestamp):
|
||||||
|
@ -41,7 +42,7 @@ def strong_to_dl(html):
|
||||||
for key, group in grouped_items:
|
for key, group in grouped_items:
|
||||||
group = list(group)
|
group = list(group)
|
||||||
if key and len(group) > 2:
|
if key and len(group) > 2:
|
||||||
dl = ['<dl>']
|
dl = ['<dl class="strong_to_dl">']
|
||||||
for elem in group:
|
for elem in group:
|
||||||
match = re.match(is_strong, elem).groupdict()
|
match = re.match(is_strong, elem).groupdict()
|
||||||
dl += [
|
dl += [
|
||||||
|
@ -55,21 +56,71 @@ def strong_to_dl(html):
|
||||||
return '\n'.join(r)
|
return '\n'.join(r)
|
||||||
|
|
||||||
|
|
||||||
|
def probe_video(path):
|
||||||
|
with Popen(
|
||||||
|
['ffprobe', '-print_format', 'json', '-show_streams', path],
|
||||||
|
stdout=PIPE,
|
||||||
|
stderr=PIPE,
|
||||||
|
) as proc:
|
||||||
|
streams = json.load(proc.stdout)['streams']
|
||||||
|
return [s for s in streams if s["codec_type"] == "video"]
|
||||||
|
|
||||||
|
|
||||||
|
def download(src, filename, force_download):
|
||||||
|
if src and src.startswith('/'):
|
||||||
|
src = 'http://{}{}'.format(settings.DRUPAL_FQDN, src)
|
||||||
|
elif src and src.startswith('sites/default/files/'):
|
||||||
|
src = 'http://{}/{}'.format(settings.DRUPAL_FQDN, src)
|
||||||
|
elif src and src.startswith('files/'):
|
||||||
|
src = 'http://{}/{}'.format(settings.DRUPAL_FQDN, src)
|
||||||
|
elif not re.match(r'^(https?)?://', src):
|
||||||
|
raise ValueError('Impossible de localiser: {}'.format(src))
|
||||||
|
|
||||||
|
path = os.path.join(settings.SPIP_LOGO_DIR, filename)
|
||||||
|
|
||||||
|
if not os.access(path, os.F_OK) or force_download:
|
||||||
|
r = requests.get(src, stream=True)
|
||||||
|
with open(path, 'wb') as fd:
|
||||||
|
for chunk in r.iter_content(chunk_size=128):
|
||||||
|
fd.write(chunk)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_extension(path):
|
||||||
|
ext = path.split('.')[-1]
|
||||||
|
if len(ext) < 2 or len(ext) > 4:
|
||||||
|
logger.warn('Extension curieuse: {}'.format(path))
|
||||||
|
ext = None
|
||||||
|
return ext or 'unknown'
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_document(src, filename, force_download):
|
||||||
|
extension = get_extension(filename)
|
||||||
|
directory = os.path.join(settings.SPIP_LOGO_DIR, extension)
|
||||||
|
if not os.access(directory, os.F_OK):
|
||||||
|
try:
|
||||||
|
os.mkdir(directory)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn('Echec à creer le dossier: {}'.format(e))
|
||||||
|
|
||||||
|
cible = os.path.join(extension, filename)
|
||||||
|
path = None
|
||||||
|
try:
|
||||||
|
path = download(src, cible, force_download)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn('Echec au download: {}'.format(e))
|
||||||
|
return extension, cible, path
|
||||||
|
|
||||||
|
|
||||||
def fetch_and_remove_logo(article, force_download):
|
def fetch_and_remove_logo(article, force_download):
|
||||||
def fetch_logo(src):
|
def fetch_logo(src):
|
||||||
"""
|
"""
|
||||||
SPIP gère les logos à la façon d'un hack : un fichier dans IMG nommé
|
SPIP gère les logos à la façon d'un hack : un fichier dans IMG nommé
|
||||||
'arton{}.{}'.format(article.pk, ext)
|
'arton{}.{}'.format(article.pk, ext)
|
||||||
"""
|
"""
|
||||||
ext = src.split('.')[-1]
|
extension = get_extension(src)
|
||||||
filename = 'arton{}.{}'.format(article.pk, ext)
|
filename = 'arton{}.{}'.format(article.pk, extension)
|
||||||
path = os.path.join(settings.SPIP_LOGO_DIR, filename)
|
download(src, filename, force_download)
|
||||||
|
|
||||||
if not os.access(path, os.R_OK) or force_download:
|
|
||||||
r = request.get(src, stream=True)
|
|
||||||
with open(path, 'wb') as fd:
|
|
||||||
for chunk in r.iter_content(chunk_size=128):
|
|
||||||
fd.write(chunk)
|
|
||||||
|
|
||||||
def remove_img(img):
|
def remove_img(img):
|
||||||
has_siblings = [
|
has_siblings = [
|
||||||
|
@ -87,10 +138,7 @@ def fetch_and_remove_logo(article, force_download):
|
||||||
|
|
||||||
src = img and img.attrs.get('src', None)
|
src = img and img.attrs.get('src', None)
|
||||||
|
|
||||||
if src and src.startswith('/'):
|
if src and re.match(r'^(https?)?://|^/', src):
|
||||||
src = 'http://{}{}'.format(settings.DRUPAL_FQDN, src)
|
|
||||||
|
|
||||||
if src and re.match(r'^(https?)?://', src):
|
|
||||||
fetch_logo(src)
|
fetch_logo(src)
|
||||||
remove_img(img)
|
remove_img(img)
|
||||||
article.descriptif = str(soup)
|
article.descriptif = str(soup)
|
||||||
|
@ -104,12 +152,124 @@ def fetch_and_remove_logo(article, force_download):
|
||||||
article.texte = str(soup)
|
article.texte = str(soup)
|
||||||
|
|
||||||
article.save()
|
article.save()
|
||||||
|
elif src:
|
||||||
|
logger.warn('Article {} has ignored logo: {}'.format(article.pk, src))
|
||||||
|
|
||||||
|
|
||||||
def sanitarize_html(html):
|
def filter_html(html):
|
||||||
html = strong_to_dl(html)
|
def auto_p(html):
|
||||||
|
"""
|
||||||
|
La façon la plus simple de reproduire le comportement de drupal
|
||||||
|
est de reprendre le code php.
|
||||||
|
"""
|
||||||
|
current_path = os.path.dirname(__file__)
|
||||||
|
script = os.path.join(current_path, 'php/auto_p.php')
|
||||||
|
try:
|
||||||
|
with Popen(['php', '-f', script], stdin=PIPE, stdout=PIPE) as proc:
|
||||||
|
stdout = proc.communicate(html.encode('utf8'))
|
||||||
|
return stdout[0].decode('utf8')
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError("Echec de auto_p: {}".format(e))
|
||||||
|
|
||||||
|
def auto_a(html):
|
||||||
|
soup = bs(html, 'html.parser')
|
||||||
|
|
||||||
|
email_pattern = re.compile(r'(\b[\w\.\+_-]+@(\w+\.)+\w+\b)')
|
||||||
|
for line in soup.find_all(string=email_pattern):
|
||||||
|
if line.parent.name == 'a':
|
||||||
|
continue
|
||||||
|
a_string = email_pattern.sub(
|
||||||
|
r'<a class= "auto-a" href="mailto:\1">\1</a>', line.string
|
||||||
|
)
|
||||||
|
a_soup = bs(a_string, 'html.parser')
|
||||||
|
line.replace_with(a_soup)
|
||||||
|
|
||||||
|
protocols = [
|
||||||
|
'http',
|
||||||
|
'https',
|
||||||
|
'ftp',
|
||||||
|
'news',
|
||||||
|
'nntp',
|
||||||
|
'tel',
|
||||||
|
'telnet',
|
||||||
|
'mailto',
|
||||||
|
'irc',
|
||||||
|
'ssh',
|
||||||
|
'sftp',
|
||||||
|
'webcal',
|
||||||
|
'rtsp',
|
||||||
|
]
|
||||||
|
link_pattern = re.compile(
|
||||||
|
r'((\b({})s?)?://(\w+\.)+\w+/?[^\s]*)'.format('|'.join(protocols))
|
||||||
|
)
|
||||||
|
for line in soup.find_all(string=link_pattern):
|
||||||
|
if line.parent.name == 'a':
|
||||||
|
continue
|
||||||
|
a_string = link_pattern.sub(
|
||||||
|
r'<a class="auto-a" href="\1">\1</a>', line.string
|
||||||
|
)
|
||||||
|
a_soup = bs(a_string, 'html.parser')
|
||||||
|
line.replace_with(a_soup)
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
|
html = auto_p(html)
|
||||||
|
html = auto_a(html)
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
def footnotes(html):
|
||||||
|
bracket_pattern = re.compile(r'\[\s*(/?)\s*(fn|footnote)\s*(\s[^\]]*)?\]')
|
||||||
|
html = bracket_pattern.sub(r'<\1\2\3>', html)
|
||||||
|
|
||||||
soup = bs(html, 'html.parser')
|
soup = bs(html, 'html.parser')
|
||||||
return str(soup)
|
|
||||||
|
index = 1
|
||||||
|
seen_values = []
|
||||||
|
for fn in soup.find_all(['fn', 'footnote']):
|
||||||
|
if 'value' in fn.attrs and fn.attrs['value'] in seen_values:
|
||||||
|
value = fn.attrs['value']
|
||||||
|
fn.clear()
|
||||||
|
elif 'value' in fn.attrs and fn.attrs['value']:
|
||||||
|
value = fn.attrs['value']
|
||||||
|
seen_values.append(value)
|
||||||
|
else:
|
||||||
|
value = ""
|
||||||
|
seen_values.append(str(index))
|
||||||
|
index += 1
|
||||||
|
if value:
|
||||||
|
spip_fn = fn.wrap(soup.new_tag('spip:fn', value=value))
|
||||||
|
else:
|
||||||
|
spip_fn = fn.wrap(soup.new_tag('spip:fn'))
|
||||||
|
spip_fn.fn.unwrap()
|
||||||
|
|
||||||
|
html = str(soup)
|
||||||
|
# Spip a eu la bonne idée de choisir les crochets et chevrons
|
||||||
|
# pour indiquer les réfs.
|
||||||
|
spip_fn_open_pattern = re.compile(r'<spip:fn>')
|
||||||
|
spip_fn_close_pattern = re.compile(r'</spip:fn>')
|
||||||
|
spip_fn_value_pattern = re.compile(r'<spip:fn value="([^"]+)">')
|
||||||
|
|
||||||
|
html = spip_fn_open_pattern.sub(r'[[', html)
|
||||||
|
html = spip_fn_close_pattern.sub(r']]', html)
|
||||||
|
html = spip_fn_value_pattern.sub(r'[[<\1>', html)
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
def sanitarize_html(html, node_fmt):
|
||||||
|
html = strong_to_dl(html)
|
||||||
|
|
||||||
|
if node_fmt == 'PHP code':
|
||||||
|
raise NotImplementedError("Ce node est au format PHP.")
|
||||||
|
elif node_fmt == 'Filtered HTML':
|
||||||
|
html = filter_html(html)
|
||||||
|
elif node_fmt == 'Full HTML':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise NotImplementedError("Ce node est dans un format inconnu.")
|
||||||
|
|
||||||
|
html = footnotes(html)
|
||||||
|
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
def convert_node(node, options):
|
def convert_node(node, options):
|
||||||
|
@ -127,24 +287,36 @@ def convert_node(node, options):
|
||||||
type='article', url__in=list(node_urls.values_list('dst', flat=True))
|
type='article', url__in=list(node_urls.values_list('dst', flat=True))
|
||||||
)
|
)
|
||||||
|
|
||||||
spip_urls.count()
|
if spip_urls.exists():
|
||||||
if spip_urls.exists() and (
|
article_id = spip_urls.first().id_objet
|
||||||
sorted(spip_urls.values_list('url', flat=True))
|
if (
|
||||||
!= sorted(node_urls.values_list('dst', flat=True))
|
sorted(spip_urls.values_list('url', flat=True))
|
||||||
or len(set(spip_urls.values_list('id_objet', flat=True))) != 1
|
!= sorted(node_urls.values_list('dst', flat=True))
|
||||||
):
|
or len(set(spip_urls.values_list('id_objet', flat=True))) != 1
|
||||||
# incohérence dans les urls
|
or spip.Urls.objects.filter(
|
||||||
raise NotImplementedError
|
type='article', id_objet=article_id
|
||||||
|
).count()
|
||||||
|
!= spip_urls.count()
|
||||||
|
):
|
||||||
|
# incohérence dans les urls
|
||||||
|
raise ValueError(
|
||||||
|
"Cet article existe déjà dans SPIP sans qu'il soit possible "
|
||||||
|
"de s'assurer qu'il s'agisse d'un import prééexistant."
|
||||||
|
)
|
||||||
|
|
||||||
|
node_fmt = node.published_revision.format.name
|
||||||
|
|
||||||
article = None
|
article = None
|
||||||
article_attributes = {
|
article_attributes = {
|
||||||
'date': convert_timestamp(node.published_revision.timestamp),
|
'date': convert_timestamp(node.created),
|
||||||
'date_modif': convert_timestamp(node.changed),
|
'date_modif': convert_timestamp(node.changed),
|
||||||
'date_redac': convert_timestamp(node.created),
|
'date_redac': convert_timestamp(node.created),
|
||||||
'descriptif': sanitarize_html(node.published_revision.teaser),
|
'descriptif': sanitarize_html(
|
||||||
|
node.published_revision.teaser, node_fmt
|
||||||
|
),
|
||||||
'maj': convert_timestamp(node.changed),
|
'maj': convert_timestamp(node.changed),
|
||||||
'statut': 'publie' if node.status else 'prepa',
|
'statut': 'publie' if node.status else 'prepa',
|
||||||
'texte': sanitarize_html(node.published_revision.body),
|
'texte': sanitarize_html(node.published_revision.body, node_fmt),
|
||||||
'titre': node.title,
|
'titre': node.title,
|
||||||
}
|
}
|
||||||
if not spip_urls.exists():
|
if not spip_urls.exists():
|
||||||
|
@ -159,14 +331,23 @@ def convert_node(node, options):
|
||||||
]
|
]
|
||||||
spip.Urls.objects.bulk_create(urls)
|
spip.Urls.objects.bulk_create(urls)
|
||||||
|
|
||||||
print('Article {} created from node {}.'.format(article.pk, node.pk))
|
logger.info(
|
||||||
|
'Article {} created from node {}.'.format(article.pk, node.pk)
|
||||||
|
)
|
||||||
|
|
||||||
elif update:
|
elif update:
|
||||||
article = spip.Articles(
|
article = spip.Articles(
|
||||||
pk=spip_urls.last().id_objet, **article_attributes
|
pk=spip_urls.last().id_objet, **article_attributes
|
||||||
)
|
)
|
||||||
article.save()
|
article.save()
|
||||||
print('Article {} updated from node {}.'.format(article.pk, node.pk))
|
logger.info(
|
||||||
|
'Article {} updated from node {}.'.format(article.pk, node.pk)
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
'Skipped node {}. Try --update to update it.'.format(node.pk)
|
||||||
|
)
|
||||||
|
|
||||||
if article:
|
if article:
|
||||||
user_attributes = {
|
user_attributes = {
|
||||||
|
@ -186,6 +367,10 @@ def convert_node(node, options):
|
||||||
|
|
||||||
fetch_and_remove_logo(article, force_download)
|
fetch_and_remove_logo(article, force_download)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Terms
|
||||||
|
#######
|
||||||
|
|
||||||
for term_node in node.termnode_set.all():
|
for term_node in node.termnode_set.all():
|
||||||
groupe, _ = spip.GroupesMots.objects.get_or_create(
|
groupe, _ = spip.GroupesMots.objects.get_or_create(
|
||||||
titre=term_node.data.theme.name,
|
titre=term_node.data.theme.name,
|
||||||
|
@ -203,3 +388,83 @@ def convert_node(node, options):
|
||||||
spip.MotsLiens.objects.get_or_create(
|
spip.MotsLiens.objects.get_or_create(
|
||||||
mot=mot, id_objet=article.pk, objet='article'
|
mot=mot, id_objet=article.pk, objet='article'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Uploads
|
||||||
|
#########
|
||||||
|
|
||||||
|
images_mimes = [
|
||||||
|
'image/png',
|
||||||
|
'image/jpeg',
|
||||||
|
'image/svg+xml',
|
||||||
|
'image/gif',
|
||||||
|
]
|
||||||
|
audio_mimes = ['application/ogg', 'audio/x-wav', 'audio/mpeg']
|
||||||
|
video_mimes = ['video/mp4']
|
||||||
|
|
||||||
|
for upload in node.upload_set.filter(
|
||||||
|
revision=F('node__published_revision')
|
||||||
|
):
|
||||||
|
is_audio = upload.file.filemime in audio_mimes
|
||||||
|
is_image = upload.file.filemime in images_mimes
|
||||||
|
is_video = upload.file.filemime in video_mimes
|
||||||
|
|
||||||
|
extension, fichier, path = fetch_document(
|
||||||
|
upload.file.filepath, upload.file.filename, force_download
|
||||||
|
)
|
||||||
|
|
||||||
|
document_attributes = {
|
||||||
|
'fichier': fichier,
|
||||||
|
}
|
||||||
|
document_defaults = {
|
||||||
|
'extension': extension,
|
||||||
|
'media': 'file',
|
||||||
|
'titre': upload.description,
|
||||||
|
'date': convert_timestamp(upload.file.timestamp),
|
||||||
|
'taille': upload.file.filesize,
|
||||||
|
'date_publication': convert_timestamp(upload.file.timestamp),
|
||||||
|
'mode': 'image' if is_image else 'document',
|
||||||
|
}
|
||||||
|
if is_image:
|
||||||
|
document_defaults['media'] = 'image'
|
||||||
|
try:
|
||||||
|
m = Image.open(path)
|
||||||
|
document_defaults['hauteur'] = m.height
|
||||||
|
document_defaults['largeur'] = m.width
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn('Echec de lecture: {}'.format(e))
|
||||||
|
elif is_audio:
|
||||||
|
document_defaults['media'] = 'audio'
|
||||||
|
try:
|
||||||
|
m = mediafile.MediaFile(path)
|
||||||
|
document_defaults['duree'] = m.length
|
||||||
|
if m.artist and m.album:
|
||||||
|
document_defaults['credits'] = '{} / {}'.format(
|
||||||
|
m.artist, m.album
|
||||||
|
)
|
||||||
|
elif m.artist:
|
||||||
|
document_defaults['credits'] = m.artist
|
||||||
|
elif m.album:
|
||||||
|
document_defaults['credits'] = m.album
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn('Echec de lecture: {}'.format(e))
|
||||||
|
elif is_video:
|
||||||
|
document_defaults['media'] = 'video'
|
||||||
|
try:
|
||||||
|
m = probe_video(path)[0]
|
||||||
|
document_defaults['duree'] = float(m.get('duration', 0))
|
||||||
|
document_defaults['hauteur'] = m.get('height', 0)
|
||||||
|
document_defaults['largeur'] = m.get('width', 0)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn('Echec de lecture: {}'.format(e))
|
||||||
|
|
||||||
|
document, _ = spip.Documents.objects.update_or_create(
|
||||||
|
**document_attributes,
|
||||||
|
defaults={**document_defaults, 'maj': now},
|
||||||
|
)
|
||||||
|
spip.DocumentsLiens.objects.get_or_create(
|
||||||
|
document=document,
|
||||||
|
id_objet=article.pk,
|
||||||
|
objet='article',
|
||||||
|
rang_lien=upload.weight,
|
||||||
|
)
|
||||||
|
|
|
@ -1,18 +1,81 @@
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.core.validators import URLValidator
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
from drupal2spip_lal.base.convert import convert_node
|
from drupal2spip_lal.base.convert import convert_node
|
||||||
from drupal2spip_lal.drupal.models import Node
|
from drupal2spip_lal.drupal.models import Node, UrlAlias
|
||||||
|
|
||||||
|
logger = logging.getLogger('drupal2spip_lal')
|
||||||
|
|
||||||
|
|
||||||
|
def validate_url(url):
|
||||||
|
try:
|
||||||
|
URLValidator(schemes=['http', 'https'])(url)
|
||||||
|
return requests.get(url).content.decode()
|
||||||
|
except Exception as e:
|
||||||
|
raise argparse.ArgumentTypeError(e)
|
||||||
|
|
||||||
|
|
||||||
|
def nodes_from_index(html):
|
||||||
|
aprilorg_url = re.compile(
|
||||||
|
r'^https?://(www\.)?april.org/(fr/)?(?P<uri>[0-9a-z/-]+)'
|
||||||
|
)
|
||||||
|
|
||||||
|
def april_link(tag):
|
||||||
|
return tag.name == 'a' and aprilorg_url.match(
|
||||||
|
tag.attrs.get('href', '')
|
||||||
|
)
|
||||||
|
|
||||||
|
soup = bs(html, 'html.parser')
|
||||||
|
|
||||||
|
aprilorg_href = [
|
||||||
|
a.attrs.get('href', '') for a in soup.find_all(april_link)
|
||||||
|
]
|
||||||
|
|
||||||
|
aprilorg_uri = [
|
||||||
|
aprilorg_url.match(href).group('uri') for href in aprilorg_href
|
||||||
|
]
|
||||||
|
|
||||||
|
nodes_alias = UrlAlias.objects.filter(
|
||||||
|
Q(src__in=aprilorg_uri) | Q(dst__in=aprilorg_uri)
|
||||||
|
).values_list('src', flat=True)
|
||||||
|
|
||||||
|
nodes_pk = [
|
||||||
|
int(re.match(r'node/(?P<pk>\d+)', src).group('pk'))
|
||||||
|
for src in nodes_alias
|
||||||
|
]
|
||||||
|
|
||||||
|
return nodes_pk
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Import Drupal nodes to SPIP articles."
|
help = "Import Drupal nodes to SPIP articles."
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'--user',
|
||||||
|
nargs='*',
|
||||||
|
type=str,
|
||||||
|
help='Selects users nodes to be imported. Default is nobody.',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--node',
|
'--node',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
type=int,
|
type=int,
|
||||||
help='Selects what nodes should be imported. Default is none.',
|
help='Selects what nodes to be imported. Default is none.',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--from-index',
|
||||||
|
type=validate_url,
|
||||||
|
help='Selects nodes to be imported by scrapping list at given URL. '
|
||||||
|
'Default is none.',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--update',
|
'--update',
|
||||||
|
@ -26,7 +89,20 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
[
|
qs = Node.objects.none()
|
||||||
convert_node(n, options)
|
if options['node']:
|
||||||
for n in Node.objects.filter(pk__in=options.get('node', []))
|
qs |= Node.objects.filter(pk__in=options['node'])
|
||||||
]
|
if options['user']:
|
||||||
|
qs |= Node.objects.filter(user__name__in=options['user'])
|
||||||
|
if options['from_index']:
|
||||||
|
qs |= Node.objects.filter(
|
||||||
|
pk__in=nodes_from_index(options['from_index'])
|
||||||
|
)
|
||||||
|
|
||||||
|
for n in qs:
|
||||||
|
try:
|
||||||
|
convert_node(n, options)
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(
|
||||||
|
"L'import du node {} a échoué : {}".format(n.pk, e)
|
||||||
|
)
|
||||||
|
|
|
@ -91,6 +91,9 @@ DB_RELATIONS = {
|
||||||
'auteurs_liens': {
|
'auteurs_liens': {
|
||||||
'id_auteur': ('id_auteur', 'auteurs', 'auteur'),
|
'id_auteur': ('id_auteur', 'auteurs', 'auteur'),
|
||||||
},
|
},
|
||||||
|
'documents_liens': {
|
||||||
|
'id_document': ('id_document', 'documents', 'document'),
|
||||||
|
},
|
||||||
'mots': {
|
'mots': {
|
||||||
'id_groupe': ('id_groupe', 'groupes_mots', 'groupe'),
|
'id_groupe': ('id_groupe', 'groupes_mots', 'groupe'),
|
||||||
},
|
},
|
||||||
|
@ -131,6 +134,7 @@ DB_PARAMS = {
|
||||||
'url_site': {'default': ''},
|
'url_site': {'default': ''},
|
||||||
'virtuel': {'default': ''},
|
'virtuel': {'default': ''},
|
||||||
'visites': {'default': 0},
|
'visites': {'default': 0},
|
||||||
|
'composition_lock': {'default': 0},
|
||||||
},
|
},
|
||||||
'auteurs': {
|
'auteurs': {
|
||||||
'alea_actuel': {'default': ''},
|
'alea_actuel': {'default': ''},
|
||||||
|
@ -150,10 +154,26 @@ DB_PARAMS = {
|
||||||
'statut': {'default': '0minirezo'},
|
'statut': {'default': '0minirezo'},
|
||||||
'url_site': {'default': ''},
|
'url_site': {'default': ''},
|
||||||
'webmestre': {'default': 'non'},
|
'webmestre': {'default': 'non'},
|
||||||
|
'composition_lock': {'default': 0},
|
||||||
},
|
},
|
||||||
'auteurs_liens': {
|
'auteurs_liens': {
|
||||||
'vu': {'default': 'non'},
|
'vu': {'default': 'non'},
|
||||||
},
|
},
|
||||||
|
'documents': {
|
||||||
|
'id_vignette': {'default': 0},
|
||||||
|
'brise': {'default': 0},
|
||||||
|
'credits': {'default': ''},
|
||||||
|
'distant': {'default': 'non'},
|
||||||
|
'duree': {'default': 0},
|
||||||
|
'hauteur': {'default': 0},
|
||||||
|
'largeur': {'default': 0},
|
||||||
|
'statut': {'default': 'prop'},
|
||||||
|
'composition_lock': {'default': 0},
|
||||||
|
},
|
||||||
|
'documents_liens': {
|
||||||
|
'vu': {'default': 'non'},
|
||||||
|
'rang_lien': {'default': 0},
|
||||||
|
},
|
||||||
'groupes_mots': {
|
'groupes_mots': {
|
||||||
'unseul': {'default': 'non'},
|
'unseul': {'default': 'non'},
|
||||||
'obligatoire': {'default': 'non'},
|
'obligatoire': {'default': 'non'},
|
||||||
|
@ -161,6 +181,10 @@ DB_PARAMS = {
|
||||||
'minirezo': {'default': 'oui'},
|
'minirezo': {'default': 'oui'},
|
||||||
'comite': {'default': 'oui'},
|
'comite': {'default': 'oui'},
|
||||||
'forum': {'default': 'non'},
|
'forum': {'default': 'non'},
|
||||||
|
'composition_lock': {'default': 0},
|
||||||
|
},
|
||||||
|
'mots': {
|
||||||
|
'composition_lock': {'default': 0},
|
||||||
},
|
},
|
||||||
'urls': {
|
'urls': {
|
||||||
'id_parent': {'default': 0},
|
'id_parent': {'default': 0},
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
require 'drupal6/modules/filter/filter.module';
|
||||||
|
|
||||||
|
$contents = file_get_contents("php://stdin");
|
||||||
|
|
||||||
|
$contents = _filter_autop($contents);
|
||||||
|
|
||||||
|
echo($contents);
|
||||||
|
?>
|
|
@ -0,0 +1,339 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
File diff suppressed because it is too large
Load Diff
|
@ -248,6 +248,63 @@ SESSION_COOKIE_PATH = APP_LOCATION
|
||||||
# https://docs.djangoproject.com/en/stable/ref/settings/#csrf-cookie-path
|
# https://docs.djangoproject.com/en/stable/ref/settings/#csrf-cookie-path
|
||||||
CSRF_COOKIE_PATH = APP_LOCATION
|
CSRF_COOKIE_PATH = APP_LOCATION
|
||||||
|
|
||||||
|
# LOGGING
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# https://docs.djangoproject.com/en/stable/topics/logging/
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': False,
|
||||||
|
'formatters': {
|
||||||
|
'verbose': {
|
||||||
|
'format': '%(asctime)s - %(levelname)s - %(module)s: %(message)s',
|
||||||
|
},
|
||||||
|
'colored': {
|
||||||
|
'()': 'colorlog.ColoredFormatter',
|
||||||
|
'format': (
|
||||||
|
'%(log_color)s%(asctime)s - '
|
||||||
|
'%(levelname)s - %(name)s: %(message)s'
|
||||||
|
),
|
||||||
|
'log_colors': {
|
||||||
|
'DEBUG': 'bold_cyan',
|
||||||
|
'INFO': 'green',
|
||||||
|
'WARNING': 'yellow',
|
||||||
|
'ERROR': 'red',
|
||||||
|
'CRITICAL': 'bold_red',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'colored',
|
||||||
|
},
|
||||||
|
'file': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'class': 'logging.handlers.TimedRotatingFileHandler',
|
||||||
|
'filename': var_dir('log/drupal2spip_lal.log'),
|
||||||
|
'formatter': 'verbose',
|
||||||
|
'when': 'midnight',
|
||||||
|
'interval': 1,
|
||||||
|
'backupCount': 30,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'django': {
|
||||||
|
'level': 'WARNING',
|
||||||
|
'handlers': ['file', 'console'],
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
'drupal2spip_lal': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'handlers': ['file', 'console'],
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if not os.path.isdir(var_dir('log')):
|
||||||
|
os.mkdir(var_dir('log'), mode=0o750)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
|
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -6,12 +6,10 @@ Production settings.
|
||||||
- load secret key from environment variables
|
- load secret key from environment variables
|
||||||
- set other production configurations
|
- set other production configurations
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
from .base import TEMPLATES, env, var_dir
|
from .base import TEMPLATES, env
|
||||||
|
|
||||||
# CONFIGURATION VALIDATION
|
# CONFIGURATION VALIDATION
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -54,53 +52,6 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
# LOGGING
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# https://docs.djangoproject.com/en/stable/topics/logging/
|
|
||||||
LOGGING = {
|
|
||||||
'version': 1,
|
|
||||||
'disable_existing_loggers': False,
|
|
||||||
'formatters': {
|
|
||||||
'verbose': {
|
|
||||||
'format': '%(asctime)s - %(levelname)s - %(module)s: %(message)s'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'handlers': {
|
|
||||||
'mail_admins': {
|
|
||||||
'level': 'ERROR',
|
|
||||||
'class': 'django.utils.log.AdminEmailHandler',
|
|
||||||
},
|
|
||||||
'file': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'class': 'logging.handlers.TimedRotatingFileHandler',
|
|
||||||
'filename': var_dir('log/drupal2spip_lal.log'),
|
|
||||||
'formatter': 'verbose',
|
|
||||||
'when': 'midnight',
|
|
||||||
'interval': 1,
|
|
||||||
'backupCount': 30,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'loggers': {
|
|
||||||
'django': {
|
|
||||||
'level': 'WARNING',
|
|
||||||
'handlers': ['file'],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
'django.request': {
|
|
||||||
'level': 'WARNING',
|
|
||||||
'handlers': ['file', 'mail_admins'],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
'drupal2spip_lal': {
|
|
||||||
'level': 'INFO',
|
|
||||||
'handlers': ['file', 'mail_admins'],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if not os.path.isdir(var_dir('log')):
|
|
||||||
os.mkdir(var_dir('log'), mode=0o750)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
|
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
django >=3.0,<3.1 # https://www.djangoproject.com/
|
django >=3.0,<3.1 # https://www.djangoproject.com/
|
||||||
django-environ ==0.4.5 # https://github.com/joke2k/django-environ
|
django-environ ==0.4.5 # https://github.com/joke2k/django-environ
|
||||||
|
mysqlclient >=1.3.13
|
||||||
|
|
||||||
# PHP
|
# PHP
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -9,5 +10,14 @@ phpserialize
|
||||||
|
|
||||||
# HTML
|
# HTML
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
request
|
requests
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
colorlog
|
||||||
|
|
||||||
|
# Media
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
mediafile
|
||||||
|
pillow
|
||||||
|
|
Loading…
Reference in New Issue