Skip to content

Refactor manage.py and settings.py for improved configuration #671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
*~
*.orig
*.rej
tmp*
*.pyc
*.pyo
*~
#*
.svn
.tox
patchman.egg-info
build
dist
run
pyvenv.cfg
.vscode
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Django
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
media/
static/

# Virtual Environment
.env
.venv
*.xml
env/
venv/
ENV/

# IDE
.idea/
.vscode/
*.swp
*.swo
.DS_Store

# Project specific
/etc/patchman/local_settings.py
run/
*.db
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,27 @@ Errata for CentOS can be downloaded from https://cefs.steve-meier.de/ .
These errata are parsed and stored in the database. If a PackageUpdate
contains a package that is a security update in the errata, then that update is
marked as being a security update.

## Local Settings Configuration

The project uses a local settings file for configuration. To set up your local environment:

1. Copy the template file to create your local settings:
```bash
cp etc/patchman/local_settings.py.template /etc/patchman/local_settings.py
```

2. Edit `/etc/patchman/local_settings.py` with your specific configuration:
- Set a secure `SECRET_KEY`
- Configure your database settings
- Set appropriate `ALLOWED_HOSTS`
- Configure email settings
- Set up Celery and caching if needed

3. Make sure the settings file has the correct permissions:
```bash
sudo chown www-data /etc/patchman/local_settings.py
sudo chmod 640 /etc/patchman/local_settings.py
```

Note: The local settings file is not tracked in git to protect sensitive information. Make sure to keep your local settings file secure and never commit it to version control.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Django settings for patchman project.

DEBUG = False
DEBUG = True

ADMINS = (
('Your Name', 'you@example.com'),
('Admin', 'admin@example.com'),
)

DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3', # noqa disabled until django 5.1 is in use, see https://blog.pecar.me/django-sqlite-dblock
'ENGINE': 'patchman.sqlite3',
'NAME': '/var/lib/patchman/db/patchman.db',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'patchman.db',
'OPTIONS': {
'timeout': 30
}
Expand All @@ -26,11 +25,11 @@
LANGUAGE_CODE = 'en-us'

# Create a unique string here, and don't share it with anybody.
SECRET_KEY = ''
SECRET_KEY = 'change-this-in-production'

# Add the IP addresses that your web server will be listening on,
# instead of '*'
ALLOWED_HOSTS = ['127.0.0.1', '*']
ALLOWED_HOSTS = ['127.0.0.1']

# Maximum number of mirrors to add or refresh per repo
MAX_MIRRORS = 2
Expand All @@ -57,6 +56,11 @@
# }
# }

# Celery settings
CELERY_BROKER_URL = 'memory://'
CELERY_RESULT_BACKEND = 'cache'
CELERY_CACHE_BACKEND = 'memory'

from datetime import timedelta # noqa
from celery.schedules import crontab # noqa
CELERY_BEAT_SCHEDULE = {
Expand Down Expand Up @@ -84,4 +88,4 @@
'task': 'hosts.tasks.find_all_host_updates_homogenous',
'schedule': timedelta(hours=24),
},
}
}
29 changes: 7 additions & 22 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
#!/usr/bin/env python3

# Copyright 2019-2025 Marcus Furlong <[email protected]>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'patchman.settings')
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'patchman.settings.local')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
'Could not import Django. Are you sure it is installed and '
'available on your PYTHONPATH environment variable? Did you '
'forget to activate a virtual environment?'
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

Expand Down
Loading
Loading