Skip to content

Commit

Permalink
try to rewrite pull request QubesOS#9 to python
Browse files Browse the repository at this point in the history
  • Loading branch information
neowutran committed Jul 4, 2020
2 parents c30ec96 + b83e354 commit 1a2c600
Show file tree
Hide file tree
Showing 25 changed files with 1,296 additions and 447 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ rpm/
deb/
pkgs/
*.gz
debian/changelog.*
22 changes: 22 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[MASTER]
persistent=no
ignore=qubespdfconverter/tests

[MESSAGES CONTROL]
disable=
bad-continuation,
bare-except,
blacklisted-name,
deprecated-method,
duplicate-code,
expression-not-assigned,
file-ignored,
fixme,
invalid-name,
locally-disabled,
locally-enabled,
missing-docstring,
protected-access,
too-few-public-methods,
unused-argument,
wrong-import-order
27 changes: 12 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
sudo: required
dist: bionic
language: generic
install: git clone https://github.com/QubesOS/qubes-builder ~/qubes-builder
script: ~/qubes-builder/scripts/travis-build
env:
- DIST_DOM0=fc25 USE_QUBES_REPO_VERSION=4.0 USE_QUBES_REPO_TESTING=1
- DISTS_VM=fc30 USE_QUBES_REPO_VERSION=4.0 USE_QUBES_REPO_TESTING=1
- DISTS_VM=fc31 USE_QUBES_REPO_VERSION=4.0 USE_QUBES_REPO_TESTING=1
- DISTS_VM=stretch USE_QUBES_REPO_VERSION=4.0 USE_QUBES_REPO_TESTING=1
- DISTS_VM=buster USE_QUBES_REPO_VERSION=4.0 USE_QUBES_REPO_TESTING=1
- DIST_DOM0=fc31 USE_QUBES_REPO_VERSION=4.1 USE_QUBES_REPO_TESTING=1
- DISTS_VM=bullseye USE_QUBES_REPO_VERSION=4.1 USE_QUBES_REPO_TESTING=1
import:
- source: QubesOS/qubes-continuous-integration:R4.1/travis-base-r4.1.yml
- source: QubesOS/qubes-continuous-integration:R4.1/travis-dom0-r4.1.yml
- source: QubesOS/qubes-continuous-integration:R4.0/travis-dom0-r4.0.yml
- source: QubesOS/qubes-continuous-integration:R4.1/travis-vms-r4.1.yml

jobs:
include:
- script:
- shellcheck qpdf-convert-client qpdf-convert-server
- language: python
python:
- '3.7'
install:
- pip install --quiet -r ci/requirements.txt
script:
- python3 -m pylint --rcfile=.pylintrc qubespdfconverter
84 changes: 22 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,37 @@
#
#

RPMS_DIR=rpm/
VERSION := $(shell cat version)
PANDOC=pandoc -s -f markdown -t man
NAME := convert-pdf

help:
@echo "Qubes addons main Makefile:" ;\
echo "make rpms <--- make rpms and sign them";\
echo; \
echo "make clean <--- clean all the binary files";\
echo "make update-repo-current <-- copy newly generated rpms to qubes yum repo";\
echo "make update-repo-current-testing <-- same, but for -current-testing repo";\
echo "make update-repo-unstable <-- same, but to -testing repo";\
echo "make update-repo-installer -- copy dom0 rpms to installer repo"
@exit 0;

rpms: rpms-vm

rpms-dom0:
rpmbuild --define "_rpmdir rpm/" -bb rpm_spec/qpdf-converter-dom0.spec
rpm --addsign rpm/x86_64/qubes-pdf-converter-dom0*$(VERSION)*.rpm

rpms-vm:
rpmbuild --define "_rpmdir rpm/" -bb rpm_spec/qpdf-converter.spec
rpm --addsign rpm/x86_64/qubes-pdf-converter*$(VERSION)*.rpm

update-repo-current:
for vmrepo in ../yum/current-release/current/vm/* ; do \
dist=$$(basename $$vmrepo) ;\
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter*$(VERSION)*$$dist*.rpm $$vmrepo/rpm/ ;\
done
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter-dom0-*$(VERSION)*.rpm ../yum/current-release/current/dom0/rpm/

update-repo-current-testing:
for vmrepo in ../yum/current-release/current-testing/vm/* ; do \
dist=$$(basename $$vmrepo) ;\
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter*$(VERSION)*$$dist*.rpm $$vmrepo/rpm/ ;\
done
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter-dom0-*$(VERSION)*.rpm ../yum/current-release/current-testing/dom0/rpm/

update-repo-unstable:
for vmrepo in ../yum/current-release/unstable/vm/* ; do \
dist=$$(basename $$vmrepo) ;\
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter*$(VERSION)*$$dist*.rpm $$vmrepo/rpm/ ;\
done
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter-dom0-*$(VERSION)*.rpm ../yum/current-release/unstable/dom0/rpm/

update-repo-template:
for vmrepo in ../template-builder/yum_repo_qubes/* ; do \
dist=$$(basename $$vmrepo) ;\
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter*$(VERSION)*$$dist*.rpm $$vmrepo/rpm/ ;\
done

update-repo-installer:
ln -f $(RPMS_DIR)/x86_64/qubes-pdf-converter-dom0-*$(VERSION)*.rpm ../installer/yum/qubes-dom0/rpm/

build:
make manpages -C doc

install-vm:
make install -C doc
install -D qvm-convert-pdf $(DESTDIR)/usr/bin/qvm-convert-pdf
install -D qpdf-convert-client $(DESTDIR)/usr/lib/qubes/qpdf-convert-client
install -D qpdf-convert-server $(DESTDIR)/usr/lib/qubes/qpdf-convert-server
install-vm: build
install -d $(DESTDIR)/usr/share/man/man1
install -D qvm-$(NAME).1.gz $(DESTDIR)/usr/share/man/man1/
python3 setup.py install -O1 $(PYTHON_PREFIX_ARG) --root $(DESTDIR)
install -d $(DESTDIR)/etc/qubes-rpc
ln -s ../../usr/lib/qubes/qpdf-convert-server $(DESTDIR)/etc/qubes-rpc/qubes.PdfConvert
install -D qvm-convert-pdf.gnome $(DESTDIR)/usr/lib/qubes/qvm-convert-pdf.gnome
install -d $(DESTDIR)/usr/share/nautilus-python/extensions
install -m 0755 qvm_convert_pdf_nautilus.py $(DESTDIR)/usr/share/nautilus-python/extensions
install -m 0644 qvm_convert_pdf_nautilus.py $(DESTDIR)/usr/share/nautilus-python/extensions
install -d $(DESTDIR)/usr/share/kde4/services
install -m 0644 qvm-convert-pdf.desktop $(DESTDIR)/usr/share/kde4/services

install-dom0:
python3 setup.py install -O1 --root $(DESTDIR)
# not needed in dom0
rm -f $(DESTDIR)/usr/bin/qvm-convert-pdf
rm -f $(DESTDIR)/usr/lib/qubes/qpdf-convert-server

qvm-$(NAME).1: README.md
$(PANDOC) $< > $@

qvm-$(NAME).1.gz: qvm-$(NAME).1
gzip -f $<

build: qvm-$(NAME).1.gz


clean:
rm -rf debian/changelog.*
rm -rf pkgs
rm -f qvm-$(NAME).1.gz
8 changes: 4 additions & 4 deletions Makefile.builder
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ifeq ($(PACKAGE_SET),dom0)
RPM_SPEC_FILES := rpm_spec/qpdf-converter-dom0.spec
else ifeq ($(PACKAGE_SET),vm)
ifneq ($(filter $(DISTRIBUTION), debian qubuntu),)
# needs python 3.7+ - exclude stretch, jessie, and centos[78]
ifeq ($(filter $(DIST), stretch jessie centos7 centos8),)
DEBIAN_BUILD_DIRS := debian
RPM_SPEC_FILES := rpm_spec/qpdf-converter.spec
ARCH_BUILD_DIRS := archlinux
endif

RPM_SPEC_FILES := rpm_spec/qpdf-converter.spec
ARCH_BUILD_DIRS := archlinux
endif

# vim: filetype=make
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ qvm-convert-pdf - converts a potentially untrusted file to a safe-to-view pdf
SYNOPSIS
-----------
```bash
qvm-convert-pdf <file to convert>
qvm-convert-pdf <file to convert>...
```

DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion archlinux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ arch=(x86_64)
pkgdesc=$(grep "Summary:" ./rpm_spec/qpdf-converter.spec.in | sed 's/Summary://' | xargs)
url=$(git remote get-url origin)
license=(GPL)
depends=(libreoffice graphicsmagick zenity poppler python-nautilus file net-tools)
depends=(libreoffice graphicsmagick zenity poppler python-nautilus python-click python-pillow python-tqdm python-magic)

build() {
ln -s "$srcdir"/../ "$srcdir/src"
Expand Down
6 changes: 6 additions & 0 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# WARNING: those requirements are used only for travis-ci.org
# they SHOULD NOT be used under normal conditions; use system package manager
click
pillow
pylint
tqdm
11 changes: 5 additions & 6 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
qubes-pdf-converter (3.0.0-1) unstable; urgency=medium

[ Neowutran ]
* Add support for libreoffice files type
* Add support for password protected files
qubes-pdf-converter (2.1.8-1) unstable; urgency=medium

-- Marek Marczykowski-Górecki <[email protected]> Sat, 25 Apr 2020 20:41:05 +0100
[ Frédéric Pierret (fepitre) ]
* Drop python2

-- Marek Marczykowski-Górecki <[email protected]> Mon, 25 May 2020 04:16:24 +0200

qubes-pdf-converter (2.1.7-1) unstable; urgency=medium

Expand Down
12 changes: 11 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ Build-Depends: pandoc, debhelper (>= 9)
# For the futures version of debian, delete the "compat" file, and add the line below in "Build-Depends"
# debhelper-compat (= 12)
Standards-Version: 4.5.0
X-Python3-Version: >= 3.7
Homepage: https://github.com/QubesOS/qubes-app-linux-pdf-converter

Package: qubes-pdf-converter
Section: admin
Architecture: any
Depends: poppler-utils, net-tools, file, libreoffice, graphicsmagick, python-nautilus, ${misc:Depends}
Depends:
poppler-utils,
libreoffice,
graphicsmagick,
python3-nautilus | python-nautilus,
python3-click,
python3-pillow,
python3-tqdm,
python3-magic,
${misc:Depends}
Description: The Qubes service for converting untrusted PDF files into trusted ones
3 changes: 2 additions & 1 deletion debian/qubes-pdf-converter.install
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
usr/lib/qubes/qpdf-convert-client
usr/lib/qubes/qpdf-convert-server
etc/qubes-rpc/qubes.PdfConvert
usr/bin/qvm-convert-pdf
Expand All @@ -7,3 +6,5 @@ usr/share/nautilus-python/extensions
usr/share/nautilus-python/extensions/qvm_convert_pdf_nautilus.py
usr/share/kde4/services/qvm-convert-pdf.desktop
usr/share/man/man1/qvm-convert-pdf.1.gz
usr/lib/python3/dist-packages/qubespdfconverter
usr/lib/python3/dist-packages/qubespdfconverter-*.egg-info
5 changes: 5 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export PYTHON_PREFIX_ARG=--install-layout=deb

export DESTDIR=$(shell readlink -m .)/debian/tmp

Expand All @@ -11,3 +12,7 @@ export DESTDIR=$(shell readlink -m .)/debian/tmp

override_dh_auto_install:
make install-vm

override_dh_missing:
dh_missing --fail-missing

21 changes: 9 additions & 12 deletions dev_tools/run.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/bin/bash
trap 'echo "Conversion failed!" 1>&2' ERR
relative_directory=$(dirname "$0")
password=toor
password=too

rm "$relative_directory"/files_success/*.trusted.pdf
rm -f "$relative_directory"/files_success/*.trusted.pdf

for file in "$relative_directory"/files_success/*; do
echo "Converting $file"
set -eE
$(coproc "$relative_directory"/../qpdf-convert-client "$file" "$password"; "$relative_directory"/../qpdf-convert-server <&"${COPROC[0]}" >&"${COPROC[1]}")
set +eE
sed 's#CLIENT_VM_CMD\s*=.*$#CLIENT_VM_CMD = ["'"$relative_directory"'/../qubespdfconverter/server.py"]#g' "$relative_directory"/../qubespdfconverter/client.py | python3 - -a "$relative_directory"/files_success/ --password "$password" "$file"
error_code=$?
if [ $error_code -ne 0 ]; then
echo "Conversion failed!"
exit 1
fi
done
sleep 10 && mv /home/user/QubesUntrustedPDFs/* "$relative_directory"/files_success/




for file in "$relative_directory"/files_error/*; do
echo "Converting $file"
$(coproc "$relative_directory"/../qpdf-convert-client "$file" "$password"; "$relative_directory"/../qpdf-convert-server <&"${COPROC[0]}" >&"${COPROC[1]}")
sed 's#CLIENT_VM_CMD\s*=.*$#CLIENT_VM_CMD = ["'"$relative_directory"'/../qubespdfconverter/server.py"]#g' "$relative_directory"/../qubespdfconverter/client.py | python3 - -a "$relative_directory"/files_errors/ --password "$password" "$file"
error_code=$?
if [ $error_code -eq 0 ]; then
echo "The conversion should be failing"
Expand All @@ -27,4 +25,3 @@ for file in "$relative_directory"/files_error/*; do
done

echo "Everything seems to be OK"
exit 0
Loading

0 comments on commit 1a2c600

Please sign in to comment.