Skip to content
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

Saving informant.dat file inside Home #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions informant
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -43,6 +43,7 @@ import subprocess
import sys
import textwrap
import time
import os, grp, pwd

# external
import docopt
Expand All @@ -51,7 +52,6 @@ import html2text
from dateutil import parser as date_parser

ARCH_NEWS = 'https://archlinux.org/feeds/news'
FILE_DEFAULT = '/var/cache/informant.dat'

# colors
RED = '\033[0;31m'
Expand Down Expand Up @@ -118,9 +118,22 @@ def running_from_pacman():

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
Expand Down