Fix issue with Dockerfile

Add .dockerignore
Remove unused files
This commit is contained in:
Matthew Welch 2021-07-10 12:53:17 -07:00
parent db74dfa314
commit bb697eb320
6 changed files with 71 additions and 73 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
/venv
/.idea
/.git
.dockerignore
Dockerfile
.gitignore

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/.idea
__pycache__
/venv

View File

@ -15,4 +15,4 @@ COPY . /rpiwebapp
VOLUME /srv/games /srv/comics /srv/movies /srv/tv
VOLUME /rpiwebapp/socket
EXPOSE 80
CMD ["uwsgi", "--plugin=http,python", "-M", "-P=4", "--http=:80", "--file=rpiWebApp.py", "--callable=app"]
CMD ["uwsgi", "--plugin=http,python", "--processes=4", "--threads=2", "--http=:80", "--file=rpiWebApp.py", "--callable=app", "--enable-threads"]

View File

@ -7,7 +7,9 @@ import sqlalchemy
from comicapi.issuestring import IssueString
from flask import current_app
from flask_login import UserMixin, current_user
from sqlalchemy import ARRAY, BLOB, JSON, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, func, over
from sqlalchemy import ARRAY, TIMESTAMP, Boolean, Column, DateTime, Integer, Numeric, String, create_engine, \
func, over, REAL
from sqlalchemy.dialects.postgresql import BYTEA
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
@ -15,24 +17,13 @@ from sqlalchemy.pool import NullPool
from sqlalchemy.sql.expression import cast
from werkzeug.security import check_password_hash
from scripts import tmdb
RPI_IMDB_DATABASE = "/var/lib/rpiWebApp/imdb.db"
RPI_USER_DATABASE = "/var/lib/rpiWebApp/users.db"
MC_IMDB_DATABASE = "/mnt/c/Users/Matthew/Documents/MyPrograms/Websites/rpi_web_interface/imdb.db"
MC_USER_DATABASE = "/mnt/c/Users/Matthew/Documents/MyPrograms/Websites/rpi_web_interface/users.db"
IMDB_DATABASE = RPI_IMDB_DATABASE if os.path.exists(RPI_IMDB_DATABASE) else MC_IMDB_DATABASE
USER_DATABASE = RPI_USER_DATABASE if os.path.exists(RPI_USER_DATABASE) else MC_USER_DATABASE
engine = create_engine("***REMOVED***", poolclass=NullPool)
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
Base = declarative_base()
Base.metadata.schema = "rpiwebapp"
class Comic(Base):
@ -41,7 +32,7 @@ class Comic(Base):
path = Column(String, unique=True)
tagorigin = Column(String)
series = Column(String)
issue = Column(Integer)
issue = Column(REAL)
issuetext = Column(String)
title = Column(String)
publisher = Column(String)
@ -96,7 +87,7 @@ class ComicThumbnail(Base):
comic_id = Column(Integer)
pagenumber = Column(Integer)
image = Column(BLOB)
image = Column(BYTEA)
type = Column(String)
id = Column(Integer, primary_key=True, autoincrement=True)
@ -124,6 +115,7 @@ class Movie(Base):
directors_cut = Column(Boolean)
poster_path = Column(String)
backdrop_path = Column(String)
res_4k = Column(Boolean)
def __init__(self, data):
i = 0
@ -330,6 +322,9 @@ class TvMovieKeywords(Base):
current_app.logger.info(inspect.stack()[0][3] + "TvMovieKeywords" + " " + str(type(e)) + " " + str(e))
Base.metadata.create_all(engine)
"""class UserComicData(Base):
__tablename__ = "user_comic_data"
@ -371,13 +366,13 @@ def update_user_tv_movie_data(tmdb_id, parent_id, time, length, finished=False,
email = current_user.email
user_data = (
session.query(UserTvMovieData)
.filter(
.filter(
UserTvMovieData.tmdb_id == tmdb_id,
UserTvMovieData.user == email,
UserTvMovieData.extended == extended,
UserTvMovieData.directors_cut == directors_cut,
)
.one_or_none()
.one_or_none()
)
if user_data:
user_data.time = time
@ -388,7 +383,8 @@ def update_user_tv_movie_data(tmdb_id, parent_id, time, length, finished=False,
session.commit()
return user_data
else:
data = UserTvMovieData((email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
data = UserTvMovieData(
(email, tmdb_id, parent_id, time, length, finished, datetime.datetime.now(), extended, directors_cut))
session.add(data)
session.commit()
return data
@ -414,8 +410,10 @@ def add_tv_shows(tv_show_data):
try:
session = Session()
tv_show = TvShow(tv_show_data)
session.add(tv_show)
session.commit()
result = session.query(TvShow).filter(TvShow.tmdb_id == tv_show.tmdb_id).one_or_none()
if not result:
session.add(tv_show)
session.commit()
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
@ -428,6 +426,8 @@ def add_tv_episodes(episodes):
if not session.query(TvEpisode).filter(TvEpisode.tmdb_id == episode.tmdb_id).one_or_none():
session.add(episode)
session.commit()
else:
current_app.logger.info(f"TV episode: The TMDB id {episode.tmdb_id} for {episode.path} is already in the database.")
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
@ -535,7 +535,8 @@ def db_get_all_comics():
def db_get_series_by_publisher(publisher):
session = Session()
result = (
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear, Comic.issue).distinct(Comic.series).all()
session.query(Comic).filter(Comic.publisher == publisher).order_by(Comic.series, Comic.seriesyear,
Comic.issue).distinct(Comic.series).all()
)
series = result
return series
@ -544,7 +545,8 @@ def db_get_series_by_publisher(publisher):
def db_get_comics_in_series(series, publisher, series_year):
session = Session()
result = (
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series, Comic.seriesyear == series_year).order_by(Comic.issue).all()
session.query(Comic).filter(Comic.publisher == publisher, Comic.series == series,
Comic.seriesyear == series_year).order_by(Comic.issue).all()
)
comics = result
return comics
@ -565,7 +567,8 @@ def db_get_comic_by_id(comic_id):
def db_get_thumbnail_by_id_page(comic_id, pageNumber):
session = Session()
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id, ComicThumbnail.pagenumber == pageNumber).one_or_none()
thumbnail = session.query(ComicThumbnail).filter(ComicThumbnail.comic_id == comic_id,
ComicThumbnail.pagenumber == pageNumber).one_or_none()
return thumbnail
@ -680,13 +683,16 @@ def db_get_all_movies():
movies = session.query(Movie).order_by(Movie.title, Movie.year).all()
if current_user:
email = current_user.email
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
movies = [(movie,
session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(movie.tmdb_id, email)).first()[
0]) for movie in movies]
return movies
def db_get_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
session = Session()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
Movie.directors_cut == directors_cut).one_or_none()
return result
@ -700,19 +706,23 @@ def get_all_tv_movies():
session = Session()
movies = session.query(Movie).order_by(Movie.title, Movie.year).all()
shows = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
tv_movies = movies + shows
if current_user:
email = current_user.email
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in shows]
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
tv_movies = movies + shows
shows = [
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in shows]
movies = [
(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for
i in movies]
tv_movies = movies + shows
tv_movies = sorted(tv_movies, key=tv_movie_sort)
return tv_movies
def get_tv_movie_by_tmdb_id(tmdb_id, extended=False, directors_cut=False):
session = Session()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended, Movie.directors_cut == directors_cut).one_or_none()
result = session.query(Movie).filter(Movie.tmdb_id == tmdb_id, Movie.extended == extended,
Movie.directors_cut == directors_cut).one_or_none()
if not result:
result = session.query(TvShow).filter(TvShow.tmdb_id == tmdb_id).one_or_none()
return result
@ -727,7 +737,9 @@ def get_all_tv_shows():
result = session.query(TvShow).order_by(TvShow.title, TvShow.year).all()
if current_user:
email = current_user.email
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for i in result]
shows = [
(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, {})".format(i.tmdb_id, email)).first()[0]) for
i in result]
else:
shows = result
return shows
@ -741,7 +753,8 @@ def get_tv_show(tmdb_id):
def get_tv_show_episodes_by_tmdb_id(tmdb_id):
session = Session()
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season, TvEpisode.episode).all()
result = session.query(TvEpisode).filter(TvEpisode.parent_tmdb_id == tmdb_id).order_by(TvEpisode.season,
TvEpisode.episode).all()
return result
@ -756,13 +769,13 @@ def db_get_user_tv_movie_data(tmdb_id, extended=False, directors_cut=False):
email = current_user.email
result = (
session.query(UserTvMovieData)
.filter(
.filter(
UserTvMovieData.user == email,
UserTvMovieData.tmdb_id == tmdb_id,
UserTvMovieData.extended == extended,
UserTvMovieData.directors_cut == directors_cut,
)
.one_or_none()
.one_or_none()
)
return result
@ -770,14 +783,16 @@ def db_get_user_tv_movie_data(tmdb_id, extended=False, directors_cut=False):
def db_get_user_tv_show_episodes_data(parent_tmdb_id) -> list:
session = Session()
email = current_user.email
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
return result
def db_get_current_tv_show_episode_and_data(parent_tmdb_id, episodes):
session = Session()
email = current_user.email
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email, UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
result = session.query(UserTvMovieData).filter(UserTvMovieData.user == email,
UserTvMovieData.parent_tmdb == parent_tmdb_id).all()
if not result:
return episodes[0], None
most_recent_data = result[0]
@ -844,8 +859,8 @@ def db_search_table_columns_by_query(query, table, columns, group=[], order=[]):
results[column.name] = [
i[0]
for i in session.query(table, over(func.rank(), partition_by=group, order_by=order))
.filter(cast(column, sqlalchemy.String).ilike(final_query))
.all()
.filter(cast(column, sqlalchemy.String).ilike(final_query))
.all()
]
return results
@ -857,7 +872,8 @@ def db_search_comics(query):
results = db_search_table_columns_by_query(query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year])
series_results = db_search_table_columns_by_query(
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear], order=[Comic.issue]
query, Comic, [Comic.publisher, Comic.title, Comic.series, Comic.year], group=[Comic.series, Comic.seriesyear],
order=[Comic.issue]
)
for row in results["publisher"]:
if row["publisher"] not in publishers:
@ -876,7 +892,8 @@ def db_search_comics(query):
def db_search_movies(query):
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description], order=[Movie.title])
results = db_search_table_columns_by_query(query, Movie, [Movie.title, Movie.year, Movie.description],
order=[Movie.title])
movies = []
for movie in results["title"]:
if movie not in movies:
@ -889,13 +906,15 @@ def db_search_movies(query):
movies.append(movie)
session = Session()
email = current_user.email
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in movies]
movies = [(i, session.execute("SELECT rpiwebapp.is_movie_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in movies]
return movies
def db_search_tv_shows(query):
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description], order=[TvShow.title])
results = db_search_table_columns_by_query(query, TvShow, [TvShow.title, TvShow.year, TvShow.description],
order=[TvShow.title])
tv_shows = []
for show in results["title"]:
if show not in tv_shows:
@ -908,7 +927,8 @@ def db_search_tv_shows(query):
tv_shows.append(show)
session = Session()
email = current_user.email
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0]) for i in tv_shows]
shows = [(i, session.execute("SELECT rpiwebapp.is_tv_show_finished({}, '{}')".format(i.tmdb_id, email)).first()[0])
for i in tv_shows]
return shows

View File

@ -1,21 +0,0 @@
server_name rpi.narnian.us;
#location / { try_files $uri @rpiWebApp; }
location /static/ {
alias /usb/www/matthew/rpiWebApp/static/;
}
location / {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME "";
fastcgi_pass unix:/run/rpiWebApp/fcgi.sock;
}
location /games/download/ {
proxy_pass http://127.0.0.1:8080;
proxy_request_buffering off;
proxy_buffering off;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

View File

@ -1,8 +0,0 @@
#!/usr/bin/python3
from flup.server.fcgi import WSGIServer
from rpiWebApp import app
if __name__ == '__main__':
app.debug = True
WSGIServer(app, bindAddress='/run/rpiWebApp/fcgi.sock').run()