Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d426a9a
Update setup.py
RhinosF1 May 18, 2024
2028a07
Update setup.cfg
RhinosF1 May 18, 2024
35d33ad
Create iaupload.py
RhinosF1 May 18, 2024
7a6bb4f
Create __init__.py
RhinosF1 May 18, 2024
548a7c8
Create mwdeploy.py
RhinosF1 May 18, 2024
72eb198
Create mwscript.py
RhinosF1 May 18, 2024
f73ea37
Create __init__.py
RhinosF1 May 18, 2024
a406f34
Create test_iaupload.py
RhinosF1 May 18, 2024
a9ef43c
Create test_mwdeploy.py
RhinosF1 May 18, 2024
2e9adaa
Create test_mwscript.py
RhinosF1 May 18, 2024
ac7cad8
Update python.yml
RhinosF1 May 18, 2024
e201de1
Create check_read_only.py
RhinosF1 May 18, 2024
c7013e0
Create disable_puppet.py
RhinosF1 May 18, 2024
31f4c0f
Rename disable_puppet.py to cycle_puppet.py
RhinosF1 May 18, 2024
9cc3eba
Create disable-puppet.py
RhinosF1 May 18, 2024
c4a2424
Create enable-puppet.py
RhinosF1 May 18, 2024
87ad960
Update disable-puppet.py
RhinosF1 May 18, 2024
7a72148
Update enable-puppet.py
RhinosF1 May 18, 2024
d0b12e0
Update cycle_puppet.py
RhinosF1 May 18, 2024
9fa4f67
Rename disable-puppet.py to disable_puppet.py
RhinosF1 May 18, 2024
0ec2219
Rename enable-puppet.py to enable_puppet.py
RhinosF1 May 18, 2024
b6f0d70
Update cycle_puppet.py
RhinosF1 May 18, 2024
5e739b6
Update disable_puppet.py
RhinosF1 May 18, 2024
6733f12
Update enable_puppet.py
RhinosF1 May 18, 2024
5b526c1
Create requirements.txt
RhinosF1 May 18, 2024
bf88240
Update pythonchecks.txt
RhinosF1 May 18, 2024
ab00a16
Update setup.py (#5)
RhinosF1 May 18, 2024
235ac6b
Merge pull request #6 from miraheze/master
RhinosF1 May 18, 2024
31b180e
Update test_mwdeploy.py
RhinosF1 May 18, 2024
25bf9b6
Update test_mwdeploy.py
RhinosF1 May 18, 2024
826c4d1
Update test_mwscript.py
RhinosF1 May 18, 2024
242f34f
Update and rename disable_puppet.py to disable_puppet.py
RhinosF1 May 18, 2024
2876a95
Create __init__.py
RhinosF1 May 18, 2024
166e7c4
Rename cycle_puppet.py to cycle_puppet.py
RhinosF1 May 18, 2024
14ca30f
Rename enable_puppet.py to enable_puppet.py
RhinosF1 May 18, 2024
c6e1efd
Update test_mwdeploy.py
RhinosF1 May 18, 2024
5cc2a27
Update enable_puppet.py
RhinosF1 May 18, 2024
9a12e44
Update enable_puppet.py
RhinosF1 May 18, 2024
134dcc2
Update disable_puppet.py
RhinosF1 May 18, 2024
7400db2
Update cycle_puppet.py
RhinosF1 May 18, 2024
e782ff1
Update iaupload.py
RhinosF1 May 18, 2024
f5dd8e2
Update iaupload.py
RhinosF1 May 18, 2024
d2f7db1
Update disable_puppet.py
RhinosF1 May 18, 2024
26c4920
Update enable_puppet.py
RhinosF1 May 18, 2024
62c286a
Update python.yml
RhinosF1 May 18, 2024
3f3408b
Apply suggestions from code review
RhinosF1 May 18, 2024
aa11afa
Revert "Apply suggestions from code review"
May 18, 2024
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
8 changes: 0 additions & 8 deletions .github/pythonchecks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ flake8-noqa==1.3.2
coverage==7.3.2
setuptools==68.2.2; python_version == '3.12'
build==1.2.1
## ACTUAL
requests==2.28.1; python_version == '3.11'
requests==2.31.0; python_version == '3.12'
filelock==3.9.0; python_version == '3.11'
filelock==3.13.1; python_version == '3.12'
langcodes==3.3.0
internetarchive==3.3.0; python_version == '3.11'
internetarchive==3.5.0; python_version == '3.12'
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- name: Run tests
run: |
flake8 --exclude=*/__init__.py,dist/*,build/* --ignore=E501,W503,SFS301,T003,PT009
#coverage run --branch -m pytest tests
mypy miraheze --ignore-missing-imports --disallow-untyped-defs
coverage run --branch -m pytest tests
mypy miraheze --ignore-missing-imports

deploy:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions miraheze/mediawiki/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

12 changes: 12 additions & 0 deletions miraheze/mediawiki/check_read_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/python3

from requests import get
import sys
headers = {'host': 'meta.miraheze.org'}
response = get('https://localhost/w/api.php?action=query&meta=siteinfo&formatversion=2&format=json', headers=headers, verify=False).json()
if not response['query']['general']['readonly']:
print('Site is READ-WRITE')
sys.exit(0)
else:
print(response['query']['general']['readonlyreason'])
sys.exit(1)
Comment on lines +6 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential exceptions from network requests.

The script does not handle exceptions that may occur during the HTTP request (e.g., network errors, invalid responses). Consider adding error handling to manage these scenarios gracefully.

80 changes: 80 additions & 0 deletions miraheze/mediawiki/iaupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /usr/bin/python3

# Upload files to archive.org directly
# from the command line.
#
# Universal Omega 2022

import argparse
import internetarchive
import os
from datetime import datetime


class ArchiveUploader:
def __init__(self) -> None:
self.parser = argparse.ArgumentParser(
description='Uploads a file to archive.org.')
self.parser.add_argument(
'--title', dest='title', required=True,
help='The title of the file to be used on archive.org. Will be both the title and identifier. Required.')
self.parser.add_argument(
'--description', dest='description', default='',
help='The description of the file to be used on archive.org. Optional. Default: empty')
self.parser.add_argument(
'--mediatype', dest='mediatype', default='web',
help='The media type of the file to be used on archive.org. Optional. Default: web')
self.parser.add_argument(
'--subject', dest='subject', default='wikitide;wikiteam',
help='Subject (topics) of the file for archive.org. Multiple topics can be separated by a semicolon. Optional. Default: wikitide;wikiteam')
self.parser.add_argument(
'--collection', dest='collection', default='opensource',
help='The name of the collection to use on archive.org. Optional. Default: opensource')
self.parser.add_argument(
'--file', dest='file', required=True,
help='The local path to the file to be uploaded to archive.org. Required.')
self.parser.add_argument(
'--proxy', dest='proxy', default='http://bastion.wikitide.net:8080',
help='The proxy to use for requests to archive.org. Optional. Default: http://bastion.wikitide.net:8080')

def upload(self) -> None:
args = self.parser.parse_args()

item = internetarchive.get_item(args.title)

if args.proxy:
# set HTTP proxy to use for getting the item from archive.org
# we then also set the session proxy for the item to use for uploading
# but we can't get the item to set session proxy without also setting HTTP_PROXY here
os.environ['HTTP_PROXY'] = args.proxy
os.environ['HTTPS_PROXY'] = args.proxy

# set session proxy for uploading
item.session.proxies = {
'http': args.proxy,
'https': args.proxy,
}

# get last modification time from file to use as the publication date in archive.org
mtime = os.path.getmtime(args.file)
dt = datetime.fromtimestamp(mtime)
date = datetime.strftime(dt, '%Y-%m-%d')

# set metadata
# see https://archive.org/developers/metadata-schema for valid options
md = {
'collection': args.collection,
'date': date,
'description': args.description,
'mediatype': args.mediatype,
'subject': args.subject,
'title': args.title,
}

# actually upload the file
item.upload(args.file, metadata=md, verbose=True, queue_derive=False)
Comment on lines +41 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate user input before processing.

The script processes command line arguments directly without validating them, which could lead to security issues or errors. Consider adding validation for the command line arguments to ensure they meet expected formats and constraints.



if __name__ == '__main__':
uploader = ArchiveUploader()
uploader.upload()
Loading