Browse Source

Multiprocessing suport!

tags/v2.0
spla 4 months ago
parent
commit
9b491802b2
2 changed files with 1214 additions and 867 deletions
  1. +65
    -6
      db-setup.py
  2. +1149
    -861
      pleroma-fed.py

+ 65
- 6
db-setup.py View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import getpass
import os
import sys
@@ -36,23 +37,24 @@ def write_parameter( parameter, file_path ):
pleroma_db_user = input("pleroma db user: ")
fediverse_db = input("fediverse db name: ")
fediverse_db_user = input("fediverse db user: ")
multiprocessing_processes = input("Multiprocessing processes: ")

with open(file_path, "w") as text_file:
print("pleroma_hostname: {}".format(pleroma_hostname), file=text_file)
print("pleroma_db: {}".format(pleroma_db), file=text_file)
print("pleroma_db_user: {}".format(pleroma_db_user), file=text_file)
print("pleroma_db_user: {}".format(pleroma_db_user), file=text_file)
print("fediverse_db: {}".format(fediverse_db), file=text_file)
print("fediverse_db_user: {}".format(fediverse_db_user), file=text_file)
print("multiprocessing_processes: {}".format(multiprocessing_processes), file=text_file)

def create_table(db, db_user, table, sql):

conn = None
try:

conn = None
conn = psycopg2.connect(database = db, user = db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()


print("Creating table.. "+table)
# Create the table in PostgreSQL database
cur.execute(sql)
@@ -136,7 +138,7 @@ if conn is not None:
print("\n")

############################################################
# Create needed tables
# Create needed tables
############################################################

print("Creating table...")
@@ -147,7 +149,7 @@ db = fediverse_db
db_user = fediverse_db_user
table = "federation"
sql = "create table "+table+" (server varchar(30) PRIMARY KEY, users int, federated_servers int, posts int, updated_at timestamptz,"
sql += "software varchar(10))"
sql += "software varchar(10), version varchar(40))"
create_table(db, db_user, table, sql)

#######################################
@@ -205,6 +207,63 @@ sql = "create table "+table+" (server varchar(30) PRIMARY KEY, added_at timestam
create_table(db, db_user, table, sql)

#######################################

db = fediverse_db
db_user = fediverse_db_user
table = "others_servers"
sql = "create table "+table+" (server varchar(30) PRIMARY KEY, added_at timestamptz, updated_at timestamptz, days varchar(30))"
create_table(db, db_user, table, sql)

#######################################################
# add column 'version' to federation table if not exist

conn = None
try:

conn = psycopg2.connect(database = db, user = db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()

cur.execute('alter table federation add column if not exists version varchar(40)')

conn.commit()

except (Exception, psycopg2.DatabaseError) as error:

print(error)

finally:

if conn is not None:

conn.close()

###########################################################################################################################
# add columns 'writefreely', 'writefreely_users', 'ravenvale' and 'ravenvale_users' to federated_servers table if not exist

conn = None
try:

conn = psycopg2.connect(database = db, user = db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()

cur.execute('alter table federated_servers add column if not exists writefreely int')
cur.execute('alter table federated_servers add column if not exists writefreely_users int')
cur.execute('alter table federated_servers add column if not exists ravenvale int')
cur.execute('alter table federated_servers add column if not exists ravenvale_users int')

conn.commit()

except (Exception, psycopg2.DatabaseError) as error:

print(error)

finally:

if conn is not None:

conn.close()

#####################################
print("Done!")
print("Now you can run setup.py!")
print("\n")

+ 1149
- 861
pleroma-fed.py
File diff suppressed because it is too large
View File


Loading…
Cancel
Save