]> git.armaanb.net Git - lightcards.git/commitdiff
Stop using setuptools data_files for config
authorArmaan Bhojwani <me@armaanb.net>
Sat, 13 Feb 2021 19:01:01 +0000 (14:01 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 13 Feb 2021 19:02:10 +0000 (14:02 -0500)
Now it actually works predictably and understandably

README.md
lightcards/config.py
man/lightcards-config.5
man/lightcards-config.5.md
setup.py

index 9284e1e212a47ea8cb765eee5f515302ca130808..84fd20b8b2c4042a753d245af337684858243841 100644 (file)
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ See `lightcards --help` or `man lightcards` for usage information.
 `contrib/example.md` is an example input file. Lightcards takes the first table from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.
 
 ## Configuration
 `contrib/example.md` is an example input file. Lightcards takes the first table from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.
 
 ## Configuration
-An example config file is provided at `/usr/share/doc/lightcards/config.py`, or `~/.local/share/doc/lightcards/config.py` if installed without root privileges. Copy it to `~/.config/lightcards/config.py` or `/etc/lightcards/config.py` and modify the given values.
+Copy the config file at `/etc/lightcards/config.py` to `~/.config/lightcards/config.py` or `~/${XDG_CONFIG_HOME}/lightcards/config.py` and edit.
 
 ## License
 Copyright Armaan Bhojwani 2021, MIT license
 
 ## License
 Copyright Armaan Bhojwani 2021, MIT license
index 3c99dc263304795cfcee5b61791ba0a8fc7182ea..2b8b93880d6707e15f958507200338b1ab211d8a 100644 (file)
@@ -20,15 +20,7 @@ def read_file(file):
     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
     world = "/etc/lightcards/config.py"
     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
     world = "/etc/lightcards/config.py"
-    world_default = "/usr/share/doc/lightcards/config.py"
-    local_default = (
-        f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py"
-    )
-
-    if os.path.exists(world_default):
-        files.append(world_default)
-    if os.path.exists(local_default):
-        files.append(local_default)
+
     if os.path.exists(world):
         files.append(world)
     if os.path.exists(local_xdg):
     if os.path.exists(world):
         files.append(world)
     if os.path.exists(local_xdg):
index 24943f7d1fed65e8539297c4c1553ba33af67211..e41cd51568e050e2991ce45238ccfe742f1293c8 100644 (file)
@@ -10,12 +10,11 @@ lightcards-config - configuration file formats for
 .PP
 Configuration is done through the config.py file.
 This is an executed Python script and must have valid Python syntax.
 .PP
 Configuration is done through the config.py file.
 This is an executed Python script and must have valid Python syntax.
-An example config file is provided at
-/usr/share/doc/lightcards/config.py, or
-\[ti]/.local/share/doc/lightcards/config.py if installed locally.
-Copy this to \[ti]/.config/lightcards/config.py or
+.PP
+Copy the global config file from /etc/lightcards/config.py to
+\[ti]/.config/lightcards/config.py or
 $XDG_CONFIG_HOME/lightcards/config.py and make modifications! All
 $XDG_CONFIG_HOME/lightcards/config.py and make modifications! All
-possible options are listed in the sample config file.
+possible options are listed in the global config file.
 .SH SEE ALSO
 .PP
 \f[B]lightcards(1)\f[R]
 .SH SEE ALSO
 .PP
 \f[B]lightcards(1)\f[R]
index 5aa6b28ece56bd26b6fadef8072e5693d976e983..206b8f274e525e7f636a45a72f4e688d78fac709 100644 (file)
@@ -10,7 +10,9 @@ date: February 2021
 lightcards-config - configuration file formats for **lightcards(1)**
 
 # CONFIGURATION
 lightcards-config - configuration file formats for **lightcards(1)**
 
 # CONFIGURATION
-Configuration is done through the config.py file. This is an executed Python script and must have valid Python syntax. An example config file is provided at /usr/share/doc/lightcards/config.py, or ~/.local/share/doc/lightcards/config.py if installed locally. Copy this to ~/.config/lightcards/config.py or $XDG_CONFIG_HOME/lightcards/config.py and make modifications! All possible options are listed in the sample config file.
+Configuration is done through the config.py file. This is an executed Python script and must have valid Python syntax.
+
+Copy the global config file from /etc/lightcards/config.py to ~/.config/lightcards/config.py or $XDG_CONFIG_HOME/lightcards/config.py and make modifications! All possible options are listed in the global config file.
 
 # SEE ALSO
   **lightcards(1)**
 
 # SEE ALSO
   **lightcards(1)**
index d028ea7ae9cd12c718ae04c245fd9f7444458228..939a7218a215c98921d608bc8cc4da21aed0b3fc 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,10 +1,34 @@
 from setuptools import setup
 from setuptools import setup
-from os import path
+import os
+import shutil
 
 
-pwd = path.abspath(path.dirname(__file__))
-with open(path.join(pwd, "README.md"), encoding="utf-8") as f:
+pwd = os.path.abspath(os.path.dirname(__file__))
+with open(os.path.join(pwd, "README.md"), encoding="utf-8") as f:
     long_description = f.read()
 
     long_description = f.read()
 
+
+def mkdir(dir):
+    try:
+        os.makedirs(dir)
+    except FileExistsError:
+        pass
+
+
+if os.geteuid() == 0:
+    mkdir("/etc/lightcards/")
+    shutil.copyfile("./config.py", "/etc/lightcards/config.py")
+else:
+    xdg = os.environ.get("XDG_CONFIG_HOME")
+    home = os.path.expanduser("~")
+
+    if xdg:
+        mkdir(f"{xdg}/lightcards")
+        shutil.copyfile("./config.py", f"{xdg}/lightcards/config.py")
+    else:
+        mkdir(f"{home}/.config/lightcards")
+        shutil.copyfile("./config.py", f"{home}/.config/lightcards/config.py")
+
+
 setup(
     name="lightcards",
     version="0.7.0",
 setup(
     name="lightcards",
     version="0.7.0",
@@ -20,16 +44,6 @@ setup(
     data_files=[
         ("man/man1", ["man/lightcards.1"]),
         ("man/man5", ["man/lightcards-config.5"]),
     data_files=[
         ("man/man1", ["man/lightcards.1"]),
         ("man/man5", ["man/lightcards-config.5"]),
-        (
-            "share/doc/lightcards/",
-            [
-                "./config.py",
-                "./README.md",
-                "man/lightcards.1.md",
-                "man/lightcards-config.5.md",
-                "./LICENSE",
-            ],
-        ),
     ],
     entry_points={
         "console_scripts": ["lightcards=lightcards:main"],
     ],
     entry_points={
         "console_scripts": ["lightcards=lightcards:main"],