From 153583a0e2055f81ad5099625bc5dbc4de3161e5 Mon Sep 17 00:00:00 2001 From: Mostafa Sedaghat Joo Date: Sat, 13 Jun 2020 13:20:05 +0800 Subject: [PATCH 1/3] Update informant --- informant | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/informant b/informant index b1ccd0b..822b9c4 100755 --- a/informant +++ b/informant @@ -40,14 +40,14 @@ import shutil import sys import textwrap import time - +import os import docopt import feedparser import html2text from dateutil import parser as date_parser ARCH_NEWS = 'https://archlinux.org/feeds/news' -FILE_DEFAULT = '/var/cache/informant.dat' +FILE_DEFAULT = os.getenv("HOME")+'/.cache/informant.dat' RED = '\033[0;31m' CLEAR = '\033[0m' BOLD = '\033[1m' From bf8e95a40780ef358d41c4c741a0200d7c06c2de Mon Sep 17 00:00:00 2001 From: Mostafa Sedaghat Joo Date: Sat, 13 Jun 2020 13:56:53 +0800 Subject: [PATCH 2/3] Saving `informant.dat` file inside Home Saving `informant.dat` file inside Home --- informant | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/informant b/informant index 822b9c4..f164062 100755 --- a/informant +++ b/informant @@ -46,8 +46,10 @@ import feedparser import html2text from dateutil import parser as date_parser +USERNAME = os.getenv("SUDO_USER") or os.getenv("USER") +HOME = os.path.expanduser('~'+USERNAME) +FILE_DEFAULT = HOME+'/.cache/informant.dat' ARCH_NEWS = 'https://archlinux.org/feeds/news' -FILE_DEFAULT = os.getenv("HOME")+'/.cache/informant.dat' RED = '\033[0;31m' CLEAR = '\033[0m' BOLD = '\033[1m' From d079c049e8a7c8cf88f24b05dca5203811582056 Mon Sep 17 00:00:00 2001 From: Mostafa Sedaghat Joo Date: Sat, 13 Jun 2020 18:30:04 +0800 Subject: [PATCH 3/3] Update informant --- informant | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/informant b/informant index f164062..519e818 100755 --- a/informant +++ b/informant @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 """ informant - an Arch Linux News reader designed to also be used as a pacman hook @@ -40,15 +40,12 @@ import shutil import sys import textwrap import time -import os +import os, grp, pwd import docopt import feedparser import html2text from dateutil import parser as date_parser -USERNAME = os.getenv("SUDO_USER") or os.getenv("USER") -HOME = os.path.expanduser('~'+USERNAME) -FILE_DEFAULT = HOME+'/.cache/informant.dat' ARCH_NEWS = 'https://archlinux.org/feeds/news' RED = '\033[0;31m' CLEAR = '\033[0m' @@ -93,9 +90,22 @@ def prompt_yes_no(question, default): def get_save_name(): """ Return the name of the file to save read information to. """ + path = "" + user = os.getenv("SUDO_USER") or os.getenv("USER") if ARGV.get(FILE_OPT): - return ARGV.get(FILE_OPT) - return FILE_DEFAULT + path = ARGV.get(FILE_OPT) + else: + home = os.path.expanduser('~'+user) + path = home+'/.cache/informant.dat' + + """ Check if the file doesn't exist, create it with user ownership """ + if not os.path.exists(path): + with open(path, "w"): + uid = pwd.getpwnam(user).pw_uid + gid = grp.getgrnam("users").gr_gid + os.chown(path, uid, gid) + + return path def get_datfile(filename): """ Return a datfile, which should be a tuple with the first element