3 zine scripts version

This commit is contained in:
Mara Karagianni 2021-04-13 19:05:34 +03:00
parent becb104052
commit 83a5377890
9 changed files with 403 additions and 0 deletions

BIN
01trial.pdf Normal file

Binary file not shown.

BIN
fireworks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
latest_trial.pdf Normal file

Binary file not shown.

82
make_zine.py Normal file
View file

@ -0,0 +1,82 @@
from fpdf import FPDF
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni 22 March 2021
"""
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font = 'helvetica'
text_font_size = 10
top_margin = 15
left_margin = 20
right_margin = 20
max_left_margin = 160
max_height = 166
current_x = 20
current_y = 30
max_y = 166
max_x = 160
cell_width = 120
cell_header_height = 16
cell_height = 8
pdf = FPDF(orientation="L", unit="mm", format="A4")
pdf.set_font(header_font, 'B', header_font_size)
pdf.set_margins(top=top_margin, left=left_margin, right=right_margin)
pdf.add_page()
print("TOP margin is {}".format(pdf.get_y()))
# Header
title = 'Painful Mailman Migrations'
pdf.cell(cell_width, cell_header_height, title, 0, ln=1, align='C')
pdf.dashed_line(
current_x, current_y, current_x+cell_width, current_y,
dash_length=3, space_length=3)
# set font for all text
pdf.set_font(text_font, size=text_font_size)
# file to get the text
filename = "./notes_sample"
text = open(filename).readlines()
# start x and y position
pdf.set_xy(current_x, current_y+9)
index = 0
for line in text:
# check current page height
if pdf.get_y() >= max_height and pdf.get_x() == max_left_margin:
# create new page/signature
pdf.add_page()
pdf.set_xy(current_x, current_y)
pdf.set_margins(top=top_margin, left=left_margin, right=right_margin)
print('NEW SIGNATURE')
if pdf.get_y() >= max_height:
print('*****')
print("BOTTOM OF PAGE, height is {}".format(pdf.get_y()))
print('*****')
pdf.set_xy(max_left_margin, current_y)
pdf.set_margins(
top=top_margin, left=max_left_margin, right=right_margin)
if line == "\n":
# debug if empty lines are detected
print('EMPTY LINE {}'.format(line))
print("x {}, y {}".format(pdf.get_x(), pdf.get_y()))
print('============')
pdf.multi_cell(cell_width, cell_height, text[index], 0, align='L')
index += 1
# save pdf file
pdf.output('trial.pdf')

138
make_zine2.py Normal file
View file

@ -0,0 +1,138 @@
from fpdf import FPDF
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni 22 March 2021
"""
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font = 'helvetica'
text_font_size = 10
top_margin = 15
left_margin = 20
right_margin = 20
max_left_margin = 160
max_height = 166
current_x = 20
current_y = 30
max_y = 166
max_x = 160
cell_width = 120
cell_header_height = 16
cell_height = 8
pdf = FPDF(orientation="L", unit="mm", format="A4")
pdf.set_font(header_font, 'B', header_font_size)
pdf.set_margins(top=top_margin, left=left_margin, right=right_margin)
pdf.add_page()
# Header
title = 'Painful Mailman Migrations'
pdf.cell(cell_width, cell_header_height, title, 0, ln=1, align='C')
pdf.dashed_line(
current_x, current_y, current_x+cell_width, current_y,
dash_length=3, space_length=3)
# set font for all text
pdf.set_font(text_font, size=text_font_size)
# file to get the text
filename = "./notes_sample"
text = open(filename).readlines()
# start x and y position
pdf.set_xy(current_x, current_y+9)
class Zine(FPDF):
def __init__(self):
super().__init__()
self.cur_x = current_x
self.cur_y = current_y
self.max_x = max_left_margin
self.max_y = max_height
self.w_cell = cell_width
self.text = text
def new_signature(self):
# create new page/signature
self.add_page()
self.set_xy(self.cur_x, self.cur_.y)
self.set_margins(top=15, left=20, right=20)
print('NEW SIGNATURE')
def new_page(self):
print('*****')
print("BOTTOM OF PAGE, height is {}".format(pdf.get_y()))
print('*****')
self.set_xy(self.x, self.y)
self.set_margins(
top=15, left=160, right=20)
def create_pages(self):
index = 0
for line in self.text:
# check current page height and if we are in the right side of page
if self.get_y() >= self.max_y and self.get_x() == self.max_x:
self.new_signature()
if self.get_y() >= self.max_y:
self.new_page()
self.multi_cell(
self.w_cell, 166, self.text[index], 0, align='L')
index += 1
# def create_pages(self):
# index = 0
# for line in self.text:
# # check current page height and if we are in the right side of page
# if pdf.get_y() >= self.max_y and pdf.get_x() == self.max_x:
# self.new_signature()
#
# if pdf.get_y() >= self.max_y:
# self.new_page()
#
# pdf.multi_cell(
# self.w_cell, cell_height, self.text[index], 0, align='L')
# index += 1
zine = Zine()
zine.create_pages()
pdf.output('new_trial.pdf')
# index = 0
# for line in text:
# # check current page height
# if pdf.get_y() >= max_height and pdf.get_x() == max_left_margin:
# # create new page/signature
# pdf.add_page()
# pdf.set_xy(current_x, current_y)
# pdf.set_margins(top=top_margin, left=left_margin, right=right_margin)
# print('NEW SIGNATURE')
#
# if pdf.get_y() >= max_height:
# print('*****')
# print("BOTTOM OF PAGE, height is {}".format(pdf.get_y()))
# print('*****')
#
# pdf.set_xy(max_left_margin, current_y)
# pdf.set_margins(
# top=top_margin, left=max_left_margin, right=right_margin)
#
# if line == "\n":
# # debug if empty lines are detected
# print('EMPTY LINE {}'.format(line))
#
# print("x {}, y {}".format(pdf.get_x(), pdf.get_y()))
# print('============')
#
# pdf.multi_cell(cell_width, cell_height, text[index], 0, align='L')
# index += 1
# save pdf file

132
make_zine3.py Normal file
View file

@ -0,0 +1,132 @@
from fpdf import FPDF
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni 22 March 2021
"""
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font = 'helvetica'
text_font_size = 10
top_margin = 15
left_margin = 20
right_margin = 20
left_max_margin = 160
max_height = 166
left_x = 20
top_y = 30
cell_width = 120
cell_header_height = 16
cell_height = 8
# Image variables
img_x = 20
img_y = 80
img_len = 120
# file to get the text
filename = "./notes_sample"
class Zine(FPDF):
def add_new_signature(self, top_margin, left_margin, right_margin):
# create new page/signature
self.add_page()
self.set_margins(top_margin, left_margin, right_margin)
self.set_xy(left_margin, top_margin)
print('NEW SIGNATURE')
def move_to_page_right(self, top_margin, left_max_margin=160, right_margin=20):
print('*****')
print("BOTTOM OF PAGE, height is {}".format(self.get_y()))
print('*****')
self.set_margins(top_margin, left_max_margin, right_margin)
self.set_xy(left_max_margin, top_margin)
print("inside move_to_page_righ function, X IS {}".format(self.get_x()))
def position_img(self, img_filename, img_x, img_y, img_len):
self.image(img_filename, img_x, img_y, img_len)
def create_pages(self, filename, max_height, left_margin,
left_max_margin, img_len, top_margin, right_margin,
cell_width, cell_height):
index = 0
text = open(filename).readlines()
for line in text:
if index > len(text)-1:
break
try:
# check if we have an image
if "<img>" in line:
img_filename = line.split("<img>")[1]
import subprocess
img_size = subprocess.run(
["identify", "-format",
"%[fx:w/72] by %[fx:h/72] inches",
"./%s" % img_filename],
stdout=subprocess.PIPE, text=True)
img_height_inches = img_size.stdout.split(' ')[2]
img_width_inches = img_size.stdout.split(' ')[0]
img_height_mm = float(img_height_inches) * float(24.5)
img_width_mm = float(img_width_inches) * float(24.5)
previous_y = self.get_y()
self.position_img(img_filename,
self.get_x(), self.get_y(), img_width_mm)
#self.get_x(), self.get_y(), img_width_mm)
# use identify to get the image height and move page height
# to bottom of the image
self.set_xy(self.get_x(), previous_y+img_height_mm)
# Ommit the image line from writing it as text input
index += 1
# check current page height and if we are in the right side of page
if self.get_y() >= max_height and self.get_x() == left_max_margin:
print("ADD SIGNATURE")
self.add_new_signature(top_margin, left_margin, right_margin)
if self.get_y() >= max_height:
self.move_to_page_right(top_margin, left_max_margin, right_margin)
except AttributeError:
# first page
print("FIRST PAGE")
self.set_margins(top=top_margin, left=left_margin,
right=right_margin)
self.set_xy(left_margin, top_margin+9)
self.add_page()
variable_x = self.get_x()
self.multi_cell(cell_width, cell_height, text[index], 0, align='L')
self.set_xy(variable_x, self.get_y())
index += 1
# set font for all text
zine = Zine(orientation="L", unit="mm", format="A4")
# TODO move to a head function the below lines
# Header
title = 'Python Mailman Migrations'
#zine.set_font(header_font, 'B', header_font_size)
#zine.cell(cell_width, cell_header_height, title, 0, ln=1, align='C')
#zine.dashed_line(
# left_x, top_y, left_x+cell_width, top_y,
# dash_length=3, space_length=3)
zine.set_font(text_font, size=text_font_size)
zine.create_pages(filename, max_height, left_margin, left_max_margin, img_len,
top_margin, right_margin, cell_width, cell_height)
zine.output('latest_trial.pdf')

BIN
new_trial.pdf Normal file

Binary file not shown.

51
notes_sample Normal file
View file

@ -0,0 +1,51 @@
This tutorial will go through mailman3 installation with postfix in a Debian OS. It assumes that postfix (a Mail Transport Agent, aka MTP) and mailutils are already installed in the system and configured, and the system can send emails, e.x root user is sending admin related emails. It also assumes that python3, postgresql and apache2 are installed in the system too. A. SSH to the remote server enter root user and do a system update with apt update && apt upgrade. Install dependencies:
sudo apt install python3-dev python3-venv sassc lynx
install rust, needed for python Cryptography library later on
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# rustc --version
Install some more:
# apt-get install build-essential libssl-dev libffi-dev python3-dev cargo
https://docs.mailman3.org/en/latest/install/virtualenv.html#installing-dependencies
also GNU mailman wiki suggests to install
# apt install memcached
# apt install fail2ban
# apt install gettext
<img>fireworks.png<img>
* for the sass installation the easier for debian is to download from source and make a symbolic link to /usr/local/bin
# cd /usr/local/lib
# wget https://github.com/sass/dart-sass/releases/download/1.32.5/dart-sass-1.32.5-linux-x64.tar.gz
# tar -xf dart-sass-1.32.5-linux-x64.tar.gz
# chmod -R 755 dart-sass
# ln -s /usr/local/lib/dart-sass/sass /usr/local/bin/sass
# rm -f dart-sass-1.32.5-linux-x64.tar.gz
ref https://wiki.list.org/DOC/Howto_Install_Mailman3_On_Debian10
B. Create a postgresql database for mailman
https://docs.mailman3.org/en/latest/install/virtualenv.html#setup-database
C. Setup mailman user and directory
useradd -m -d /opt/mailman -s /usr/bin/bash mailman
chown dir for user
enter user mailman
https://docs.mailman3.org/en/latest/install/virtualenv.html#setup-mailman-user
D. Go to mailman's dir and create a virtualenv
python3 -m venv venv
https://docs.mailman3.org/en/latest/install/virtualenv.html#virtualenv-setup
E. Install Mailman and other python libraries
(venv)$ pip install wheel mailman psycopg2-binary
pip install mailman-web mailman-hyperkitty
mailman-web provides hyperkitty and postorius for the web interface, as well as shortcuts to django admin commands
Install the following for mailman-web application to be able to talk with apache2 server gateway
pip install pylibmc gunicorn
https://docs.mailman3.org/en/latest/install/virtualenv.html#installing-mailman-core
F. Mailman and hyperkitty configurations:
Exit mailman user and as a root we create
/etc/mailman3/ dir, make owner of this dir the user mailman and create the files mailman.cfg and settings.py in the /etc dir and mailman-hyperkitty.cfg in mailman's user dir (have a look at these files)
https://docs.mailman3.org/en/latest/install/virtualenv.html#installing-mailman-core
https://docs.mailman3.org/en/latest/install/virtualenv.html#initial-configuration

BIN
trial.pdf Normal file

Binary file not shown.