Skip to content

Commit

Permalink
Officially support Ubuntu 22.04 and 24.04 (#82)
Browse files Browse the repository at this point in the history
* fix package with ubuntu 22 ands 24

* fix isort

* fix CI
  • Loading branch information
submarcos authored Feb 7, 2025
1 parent 23f451b commit 09ef443
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 30 deletions.
39 changes: 22 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ jobs:
name: Test ${{ matrix.distro }}
runs-on: ubuntu-${{ matrix.version }}
needs: [ build ]
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
if: ${{ matrix.distro != 'docker' }}
with:
Expand All @@ -139,11 +139,14 @@ jobs:
with:
image: "convertit:latest"

- name: Prepare test server
run: docker run -d -p 8080:80 -v ./test:/var/www/ -v ./test/nginx.conf:/etc/nginx/conf.d/default.conf nginx:alpine

- name: Install package
if: ${{ matrix.distro != 'docker' }}
run: |
sudo apt-get -qq update
sudo apt-get -yqq install /home/runner/work/convertit/convertit/*.deb || exit 0;
sudo apt -qq update
sudo apt-get -yqq install --no-install-recommends /home/runner/work/convertit/convertit/*.deb || exit 0;
- name: Run docker image
if: ${{ matrix.distro == 'docker' }}
Expand All @@ -152,7 +155,7 @@ jobs:
- name: Test ODT / PDF conversion
run: |
wget -O myfile.pdf "http://localhost:6543/?url=https://file-examples.com/wp-content/storage/2017/10/file-sample_100kB.odt&from=application/vnd.oasis.opendocument.text"
wget -O myfile.pdf "http://localhost:6543/?url=http://172.17.0.1:8080/example.odt&from=application/vnd.oasis.opendocument.text"
if file -b --mime-type ./myfile.pdf |grep -q 'application/pdf'; then
echo "File is PDF";
Expand All @@ -165,7 +168,7 @@ jobs:
- name: Test ODT / DOC conversion
run: |
wget -O myfile.doc "http://localhost:6543/?url=https://file-examples.com/storage/fef4e75e176737761a179bf/2017/10/file-sample_100kB.odt&from=application/vnd.oasis.opendocument.text&to=application/msword"
wget -O myfile.doc "http://localhost:6543/?url=http://172.17.0.1:8080/example.odt&from=application/vnd.oasis.opendocument.text&to=application/msword"
if file -b --mime-type ./myfile.doc |grep -q 'application/msword'; then
echo "File is DOC";
Expand All @@ -178,7 +181,7 @@ jobs:
- name: Test SVG / PNG conversion
run: |
wget -O myfile.png "http://localhost:6543/?url=https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg&from=image/svg%2Bxml&to=image/png"
wget -O myfile.png "http://localhost:6543/?url=http://172.17.0.1:8080/example.svg&from=image/svg%2Bxml&to=image/png"
if file -b --mime-type ./myfile.png |grep -q 'image/png'; then
echo "File is PNG";
Expand All @@ -191,7 +194,7 @@ jobs:

- name: Test SVG / PDF conversion
run: |
wget -O myfile.pdf "http://localhost:6543/?url=https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg&from=image/svg%2Bxml&to=application/pdf"
wget -O myfile.pdf "http://localhost:6543/?url=http://172.17.0.1:8080/example.svg&from=image/svg%2Bxml&to=application/pdf"
if file -b --mime-type ./myfile.pdf |grep -q 'application/pdf'; then
echo "File is PDF";
Expand Down Expand Up @@ -244,6 +247,16 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}

- name: Download 22.04 debian artifact
uses: actions/download-artifact@v4
with:
name: debian-jammy

- name: Download 24.04 debian artifact
uses: actions/download-artifact@v4
with:
name: debian-noble

- name: Publish debian packages
run: |
if [[ "${{ github.ref }}" == *"dev"* ]]; then
Expand All @@ -255,20 +268,12 @@ jobs:
scp -P ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no /home/runner/work/convertit/convertit/convertit_*_amd64.deb ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/srv/packages/incoming/$DEB_COMPONENT/
if [[ "${{ github.ref }}" == *"dev"* ]]; then
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make focal_dev -C /srv/packages
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make jammy_dev -C /srv/packages
else
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make focal_main -C /srv/packages
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make jammy_main -C /srv/packages
fi
- name: Download 24.04 debian artifact
uses: actions/download-artifact@v4
with:
name: debian-noble

- name: Download 22.04 debian artifact
uses: actions/download-artifact@v4
with:
name: debian-jammy

- name: Attach debian packages as release binaries
uses: skx/github-action-publish-binaries@master
env:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ CHANGELOG
2.2.6.dev0
------------------

- Add Ubuntu 24.04 official support with debian package
- Add Ubuntu 22.04 official support with debian package
- Add Ubuntu 24.04 official support with debian package
- Update Docker image to ubuntu 24.04 base
- Use directly libreoffice instead of deprecated unoconv
- Move CI to github-action
Expand Down
14 changes: 13 additions & 1 deletion convertit/converters/unoconv.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import fcntl
import logging
import os
import subprocess
import tempfile
from functools import partial

from convertit import exists

log = logging.getLogger(__name__)


class Lock:
def __init__(self, filename):
Expand Down Expand Up @@ -48,9 +51,18 @@ def unoconv(output_path, output_format, source):


def convert(source, target, output_format):
log.error('Converting %s to %s with %s', source, target, output_format)
p = unoconv(target, output_format, source)
output = b'\n'.join([p.stdout.read(), p.stderr.read()])
if not os.path.exists(target):
log.error(output)
filename = os.path.basename(source)
# replace extenson with output_frmat
filename, _ = os.path.splitext(filename)
filename = filename + '.' + output_format

target_file = os.path.join(target, filename)

if not os.path.exists(target_file):
raise IOError(p.returncode, output.decode())


Expand Down
20 changes: 12 additions & 8 deletions convertit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,25 @@ def save(request, uploaded_file):
def download(request, url):
downloads_path = request.registry.settings['convertit.downloads_path']

message = "Sorry, there was an error fetching the document. Reason: %s"
message_template = "Sorry, there was an error fetching the document '{url}'. Reason: {e}"
try:
downloaded_filepath = download_file(url,
downloads_path,
headers=request.headers)
return downloaded_filepath
except ValueError as e:
log.error(message % str(e))
raise HTTPBadRequest(body=message % str(e), content_type='text/plain')
message = message_template.format(url=url, e=str(e))
log.error(message)
raise HTTPBadRequest(body=message, content_type='text/plain')
except urllib.error.HTTPError as e:
log.error(message % str(e))
raise HTTPError(body=message % str(e), status_int=e.getcode(),
message = message_template.format(url=url, e=str(e))
log.error(message)
raise HTTPError(body=message, status_int=e.getcode(),
content_type='text/plain')
except urllib.error.URLError as e:
log.error(message % str(e))
raise HTTPBadRequest(body=message % str(e), content_type='text/plain')
message = message_template.format(url=url, e=str(e))
log.error(message)
raise HTTPBadRequest(body=message, content_type='text/plain')


def get_input_mimetype(request, input_filepath):
Expand Down Expand Up @@ -152,11 +155,12 @@ def home_view(request, input_filepath, output_basename_generator):
output_filepath = os.path.join(converted_path, output_basename)

remove_old_files(request)

log.error(f"from: {input_mimetype} to {output_mimetype}, file: {output_filepath}")
convert = get_converter(request, input_mimetype, output_mimetype)

try:
convert(input_filepath, converted_path)
log.error(f"converted: {input_filepath} to {converted_path}")
except Exception as e:
msg = "Sorry, there was an error converting the document. Reason: %s"
log.error(msg % str(e))
Expand Down
2 changes: 1 addition & 1 deletion debian/postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e

adduser --system --group --home /run/convertit --no-create-home --quiet convertit || true
useradd --system --home /opt/convertit/home --create-home convertit || true
mkdir -p /var/cache/convertit || true
chown convertit:convertit /var/cache/convertit || true

Expand Down
4 changes: 2 additions & 2 deletions docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ keys = console
keys = generic

[logger_root]
level = WARN
level = INFO
handlers = console

[logger_convertit]
level = WARN
level = INFO
handlers =
qualname = convertit

Expand Down
Binary file added test/example.odt
Binary file not shown.
28 changes: 28 additions & 0 deletions test/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server {
listen 80;
server_name localhost;
root /var/www;
}

0 comments on commit 09ef443

Please sign in to comment.