Skip to content
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
28 changes: 28 additions & 0 deletions conf/wikicurses.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
###
# Wikicurses configuration
# This file will automatically be copied to the user configuration path on first run
# User configuration stored in ~/.config/wikicurses/config (i.e. $HOME/.config/wikicurses/config)

[general]
default = Wikipedia_EN
mouse = False
hide_references = False

[keymap]
q = quit
c = contents
o = open
h = back
l = forward
left = back
right = forward

[Wikipedia_EN]
url = https://en.wikipedia.org/w/api.php

[Wiktionary_EN]
url = https://en.wiktionary.org/w/api.php

# Additional Languages
# [Wikipedia_DE]
# url = https://de.wikipdia.org/w/api.php
File renamed without changes.
File renamed without changes.
37 changes: 29 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
#!/usr/bin/env python3
#!/usr/bin/env python3

from setuptools import setup

import os.path
import sys
import warnings

# Changed paths to remove absolutes

files_spec = [
('share/wikicurses', ['conf/wikicurses.conf.dist']),
('share/zsh/site-functions', ['zsh/_wikicurses']),
('share/man/man1', ['docs/wikicurses.1']),
Copy link
Owner

Choose a reason for hiding this comment

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

Hm. Unfortunately man doesn't seem to check ~/.local/share/main by default, at least on Arch Linux. But I presume there's no better solution for user-local installs...

('share/man/man5', ['docs/wikicurses.conf.5'])
]

# Loop through and make the install relative to where we are now
# Concept from github:ytdl-org/youtube-dl/setup.py
root = os.path.dirname(os.path.abspath(__file__))
data_files = []
for dirname, files in files_spec:
resfiles = []
for fn in files:
if not os.path.exists(fn):
warnings.warn('Skipping file %s since it is not present. Type make to build all automatically generated files.' % fn)
else:
resfiles.append(fn)
data_files.append((dirname, resfiles))

setup(name='Wikicurses',
version='1.4',
version='1.4.1',
description='A simple curses interface for accessing Wikipedia.',
author='Ian D. Scott',
author_email='[email protected]',
license = "MIT",
url='http://github.com/ids1024/wikicurses/',
packages = ['wikicurses'],
data_files=[
('/etc', ['wikicurses.conf']),
('/usr/share/man/man1', ['wikicurses.1']),
('/usr/share/man/man5', ['wikicurses.conf.5']),
('/usr/share/zsh/site-functions', ['_wikicurses'])
],
data_files=data_files,
entry_points={'console_scripts': ['wikicurses = wikicurses.main:main']},
install_requires = ['beautifulsoup4', 'lxml', 'urwid'],
classifiers=[
Expand Down
16 changes: 0 additions & 16 deletions wikicurses.conf

This file was deleted.

17 changes: 15 additions & 2 deletions wikicurses/settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import sys
import os
import json
import collections
import configparser
import shutil
from wikicurses import formats
from urllib.parse import urlparse

default_configdir = os.environ['HOME'] + '/.config'
# TODO: This may cause issues with python 2.7; however, as of 01OCT2019, it is nearing sunset
Copy link
Owner

Choose a reason for hiding this comment

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

Running Wikicurses in Python 2 already fails immediately (syntax errors from yield from, which was added later). So that shouldn't be a problem.

(I personally don't see any reason now to support Python 2 in an application; maybe in a library.)

default_configdir = os.path.expanduser('~') + '/.config'
configpath = os.environ.get(
'XDG_CONFIG_HOME', default_configdir) + '/wikicurses'

configfile = os.path.join(configpath, "config")

os.makedirs(configpath, exist_ok=True)

if not os.path.isfile(configfile):
Copy link
Owner

Choose a reason for hiding this comment

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

Neat solution!

One thing I'm not so sure about: I think the current behavior using a global configuration file instead of copying like this might be better for disro packaging (rather than installing with pip). Arch Linux, at least, currently packages Wikicurses.

But then, maybe it would just complicate and confuse things too much to provide a mechanism for either copying or not copying...

I guess if we want this complexity, it might be best achieved by also checking for /etc/wikicurses.conf, and not copying the configuration if that exists.

# Copy the default config file
current_run_path = os.path.dirname(os.path.realpath(sys.argv[0]))
default_config = os.path.normpath(os.path.join(current_run_path, "../share/wikicurses/wikicurses.conf.dist"))
shutil.copyfile(default_config, configfile)

conf = configparser.ConfigParser()
conf.read(['/etc/wikicurses.conf', configpath + '/config'])
conf.read(configpath + '/config')

try:
mouse = conf.getboolean('general', 'mouse')
Expand Down
File renamed without changes.