GithubHelp home page GithubHelp logo

informant's Introduction

informant

An Arch Linux News reader designed to also be used as a pacman hook.

Originally I had wanted to make an interactive pacman hook, but pacman is not designed to work that way. So informant will instead interrupt pacman transactions to make sure you have read the news first.

Installation

You can install from my AUR package. In case anyone wants to use Github to create issues or contribute to the AUR package I have also mirrored the PKGBUILD.

Requirements are in requirements.txt. If you want to install it manually. NOTE: The provided pip requirements likely won't be as up to date as the Arch packages that AUR-installed informant will depend on, so your mileage may vary if you take this approach.

On the first run informant assumes that you have not read any of the most recent news items. Use the informant read command specified below to mark items as read.

How does it work?

informant provides 3 subcommands, 'check', 'list' and 'read'.

informant check - will check for any unread news items, if there is only one unread item it will print it and mark it as read. Informant check will exit with return code equal to the number of unread news items (even if there is only one). This is the command used by the pacman hook, so that if there are unread news items it will interrupt your pacman transaction.

informant list - will list the titles of the most recent news items (regardless of whether or not they have been read, unless the '--unread' option is given). There is also a '--reverse' option if you prefer to see them newest to oldest.

informant read - if given a news item, will print that item and mark it as read. You can specify a news item as either an index or a string matching the title. If you want to use an index it must only be that shown when running informant list (without '--unread' or '--reverse'). If no item is given, will begin looping through all unread items, printing each one and marking them as read with a prompt to continue. Passing the '--all' flag will mark all items as read without printing them.

More options can be found by reading informant --help or man informant.

About the pacman hook

informant provides a PreTransaction pacman hook, so that it can interrupt a pacman transaction if there are unread Arch Linux News items. This hook runs on Upgrades and Installs, but not Removes. If for some reason the hook (or informant) breaks in such a way that you cannot run a successful pacman transaction (even after trying to read the news) you should be able to pacman -Rsn informant.

informant installs its hook to /usr/share/libalpm/hooks/ so you should also be able to override the pacman hook by placing a new hook in /etc/pacman.d/hooks/00-informant.hook or disable it by placing a symlink to /dev/null in that location (e.g. ln -s /dev/null /etc/pacman.d/hooks/00-informant.hook).

More information on pacman hooks can be found in man alpm-hooks.

Configuration

Informant can be configured to check multiple feeds instead of just the Arch Linux News feed (whether having it do so is actually useful or not is left up to the user). Informant will check for an informantrc.json file in a few places. It will check in this order:

  • CLI provided option
  • $HOME/.informantrc.json
  • $XDG_CONFIG_HOME/informantrc.json
  • /etc/informantrc.json
  • for each directory ($d) in $XDG_CONFIG_DIRS it will look for $d/informantrc.json

NOTE: If you want the configuration file to be used in the pacman hook make sure to use a save location that will be accessible to informant when running as root/sudo.

Configuration Syntax

The syntax of informantrc.json is a JSON object containing one key (feeds) that is a list describing the feeds you want informant to check. Each feed is represented as a JSON object with the following keys:

  • name (optional) - used to show which feed each news item is from
  • url (required) - the feed URL
  • title-key (optional) - defaults to title, the key used to reference the news item title in the feed
  • body-key (optional) - defaults to summary, the key used to reference the news item body in the feed
  • timestamp-key (optional) - defaults to published, the key used to reference the news item date in the feed

An example is provided here as informanrc.json.example which configures informant to check the Arch Linux News feed as well as the Arch Linux 32 News feed.

informant's People

Contributors

950339342 avatar bradford-smith94 avatar codeclem avatar k4y4k avatar muhammedzakir avatar no1xsyzy avatar pierregoutagny avatar strykar avatar swoertz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

informant's Issues

Use psutil instead of shelling out to ps

The current code uses the subprocess module to invoke ps commands for process management. We should consider replacing these subprocess calls with the psutil library, which is not part of the standard library but provides a more robust interface for interacting with system processes.

Using psutil over subprocess to call ps has some advantages. Directly using psutil avoids the risks associated with parsing shell command output, which can be unstable. You have no mechanism to check or pin external shell dependencies like you do with python modules.

Why does informant need sudo?

I was wondering if there is a specific reason why informant requires root privileges or membership in the informant group.

AFAIK that command doesn't do any changes to the system. And since the displayed news are publicly available on the arch website, this seems like an odd choice to me.

If this is meant to protect admins against users maliciously reading the news (something I never thought I'd write ๐Ÿ˜…), wouldn't it be more desirable to keep the data in the users home directory (like PR #17 suggests)?

Warn instead of breaking during offline operations

Running pacman -U with packages from the cache (coincidentally trying to solve network issues) fails:

(1/3) Checking Arch News ...  
<urlopen error [Errno -3] Temporary failure in name resolution>  

I assume this is because I'm not connected to the internet, but I'm running an operation that would otherwise not require internet access. Now I need to temporarily disable informant to be able to perform this operation. Can Informant catch these errors and warn about missing internet access instead of breaking?

(can confirm, after -Rns informant, the installation works flawlessly)

Add ability to use shortened commands

Hello there!

Is it possible to add the option to use shortened commands? For example:

  • instead of running informant check, run informant c;
  • instead of running informant list, run informant l;
  • instead of running informant read 0, run informant r 0

Display name of package or `informant read` command

I like this package, but I find every time it prevents me from upgrading (as intended) I forget the name of the package so I can't do informant read! If it reminded the user of the command when it prevents an upgrade that would be lovely.

Partial update when aborting update due to unread news

Consider the situation:

  1. User runs update.
  2. Pacman sync the local package database.
  3. Informant hook is run, and it detects unread news, aborting the update.
  4. User reads the news.
  5. User installs a new package on an outdated system, causing a partial update scenario, potentially breaking the system.

Aborting updates is the same as running pacman -Sy, it should never be done, unless the system is updated immediately afterwards. There is no guarantee for that with this hook.

Unable to read cache information: ("Connection broken: PermissionError(13, 'Permission denied')", PermissionError(13, 'Permission denied'))

On two different machines I have this error every time I run informant check:

$ informant check
ERROR: Unable to read cache information: ("Connection broken: PermissionError(13, 'Permission denied')", PermissionError(13, 'Permission denied'))
ERROR: Encountered feed error: <unknown>:6:-1: Opening and ending tag mismatch: hr line 6 and body

WARN: no news feed items, informant is performing no action

What could be the cause of this? Thank you!

Unable to save read information in informant.dat

On running informant read 0 on first use it returns the following error:
ERROR: Unable to save read information, please re-run with correct permissions to access "/var/cache/informant.dat".

informant is not the first pre-transaction hook that gets run

I noticed this the last time I went to update:

:: Running pre-transaction hooks...
(1/3) Removing linux initcpios...
(2/3) Remove DKMS modules
==> dkms remove acpi_call/1.1.0 -k 5.5.3-arch1-1
==> dkms remove vboxhost/6.1.2_OSE -k 5.5.3-1-ck-broadwell
==> dkms remove acpi_call/1.1.0 -k 5.5.3-1-ck-broadwell
==> dkms remove vboxhost/6.1.2_OSE -k 5.5.3-arch1-1
(3/3) Checking Arch News ...
sshd needs restarting after upgrading to openssh-8.2p1
Mon, 17 Feb 2020 01:35:04 +0000

After upgrading to openssh-8.2p1, the existing SSH daemon will be unable to accept
new connections. (See [FS#65517][1].) When upgrading remote hosts, please make sure
to restart the SSH daemon using `systemctl restart sshd` right after running `pacman
-Syu`. If you are upgrading to openssh-8.2p1-3 or higher, this restart will happen
automatically.

   [1]: https://bugs.archlinux.org/task/65517


error: command failed to execute correctly
error: failed to commit transaction (failed to run transaction hooks)
Errors occurred, no packages were upgraded.
Error installing repo packages

So stuff already starts happening before the hook gets a chance to run and stop things. So potentially it could fail to serve its purpose -- to prevent any changes before the user has a chance to read any relevant news. Is there a way to make sure the informant hook is run first?

News comes in too late

Firstly, this isn't necessarily an issue with Informant. It seems to be working okay (perhaps).

Today I tried a pacman -Syu and got the following error:

error: failed to commit transaction (conflicting files)
libxml2: /usr/lib/python3.10/site-packages/__pycache__/drv_libxml2.cpython-310.pyc exists in filesystem
libxml2: /usr/lib/python3.10/site-packages/__pycache__/libxml2.cpython-310.pyc exists in filesystem
Errors occurred, no packages were upgraded.

My first (probably incorrect) instinct was to delete these files. Rerunning the command then resulted in this:

:: Running pre-transaction hooks...
(1/3) Checking Arch News with Informant ...
:: informant: Stopping upgrade to print news
libxml2>=2.9.12-6 update may require manual intervention
Mon, 27 Dec 2021 06:17:35 +0000

The libxml2 package prior to version 2.9.12-6 was missing the compiled python
modules. This has been fixed in 2.9.12-6, so the upgrade may need to overwrite any
untracked pyc files created. If you get errors like these



    libxml2: /usr/lib/python3.10/site-packages/__pycache__/drv_libxml2.cpython-310.opt-1.pyc exists in filesystem
    libxml2: /usr/lib/python3.10/site-packages/__pycache__/drv_libxml2.cpython-310.pyc exists in filesystem
    libxml2: /usr/lib/python3.10/site-packages/__pycache__/libxml2.cpython-310.opt-1.pyc exists in filesystem
    libxml2: /usr/lib/python3.10/site-packages/__pycache__/libxml2.cpython-310.pyc exists in filesystem


when updating, use



    pacman -Syu --overwrite /usr/lib/python3.10/site-packages/__pycache__/\*


to perform the upgrade.


:: informant: You can re-run your pacman command to complete the upgrade
error: command failed to execute correctly
error: failed to commit transaction (failed to run transaction hooks)
Errors occurred, no packages were upgraded.

Which would have been pretty useful to have seen before :)

I installed Informant via the AUR, so my questions are:

  1. Is it possible to fail on news earlier?
  2. Is there a reason why we don't?

informant fails after major Python upgrade

`informant check
Traceback (most recent call last):
File "/usr/bin/informant", line 33, in
sys.exit(load_entry_point('informant==0.4.5', 'console_scripts', 'informant')())
File "/usr/bin/informant", line 22, in importlib_load_entry_point
for entry_point in distribution(dist_name).entry_points
File "/usr/lib/python3.10/importlib/metadata/init.py", line 919, in distribution
return Distribution.from_name(distribution_name)
File "/usr/lib/python3.10/importlib/metadata/init.py", line 518, in from_name
raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for informant

`

Error from CacheControl when permissions fail on cache directory

Heloo, after installing informant via yay and running informant check the following output was presented to me:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lockfile/linklockfile.py", line 19, in acquire
    open(self.unique_name, "wb").close()
FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/informant/a/3/a/4/1/peterbabic-b8ddc740.52293122153530957582761'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/informant", line 33, in <module>
    sys.exit(load_entry_point('informant==0.4.1', 'console_scripts', 'informant')())
  File "/usr/lib/python3.9/site-packages/informant/informant.py", line 176, in main
    run()
  File "/usr/lib/python3.9/site-packages/informant/informant.py", line 160, in run
    feed = Feed().entries
  File "/usr/lib/python3.9/site-packages/informant/feed.py", line 47, in __init__
    self.feed = self.fetch()  # the complete feed as returned by feedparser
  File "/usr/lib/python3.9/site-packages/informant/feed.py", line 69, in fetch
    return feedparser.parse(session.get(self.url).content)
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.9/site-packages/cachecontrol/adapter.py", line 53, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 533, in send
    return self.build_response(request, resp)
  File "/usr/lib/python3.9/site-packages/cachecontrol/adapter.py", line 97, in build_response
    self.controller.cache_response(request, response)
  File "/usr/lib/python3.9/site-packages/cachecontrol/controller.py", line 316, in cache_response
    self.cache.set(cache_url, self.serializer.dumps(request, response))
  File "/usr/lib/python3.9/site-packages/cachecontrol/caches/file_cache.py", line 126, in set
    with self.lock_class(name) as lock:
  File "/usr/lib/python3.9/site-packages/lockfile/__init__.py", line 197, in __enter__
    self.acquire()
  File "/usr/lib/python3.9/site-packages/lockfile/linklockfile.py", line 21, in acquire
    raise LockFailed("failed to create %s" % self.unique_name)
lockfile.LockFailed: failed to create /var/cache/informant/a/3/a/4/1/peterbabic-b8ddc740.52293122153530957582761

Improve informant read

Couldn't informant read just have to be run once, and we hit Space or a key to confirm reading each of the 10 news post's instead of something like for run in {1..10}; do informant; done?

informant version

Hello, I think there is an error in informant --version output. I recently updated to version v0.2.2

But I get the version to be v0.2.0 when I run informant in my terminal:

$ informant --version
informant v0.2.0

Probably the error is due to the below code:

ARGV = docopt.docopt(__doc__, version='informant v0.2.0')

Fails after Python 3.10 update

:: Running pre-transaction hooks...
(1/1) Checking Arch News with Informant ...
Traceback (most recent call last):
  File "/usr/bin/informant", line 33, in <module>
    sys.exit(load_entry_point('informant==0.4.5', 'console_scripts', 'informant')())
  File "/usr/bin/informant", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 919, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 518, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for informant
error: command failed to execute correctly
error: failed to commit transaction (failed to run transaction hooks)
Errors occurred, no packages were upgraded.
Done - Press enter to exit

[Solved] Error with "informant read --all"

Hi,

I got this error on 4 different Arch machines, all having the same output:

$ informant read --all
Traceback (most recent call last):
  File "/usr/bin/informant", line 33, in <module>
    sys.exit(load_entry_point('informant==0.4.2', 'console_scripts', 'informant')())
  File "/usr/lib/python3.9/site-packages/informant/informant.py", line 178, in main
    run()
  File "/usr/lib/python3.9/site-packages/informant/informant.py", line 171, in run
    read_cmd(feed)
  File "/usr/lib/python3.9/site-packages/informant/informant.py", line 120, in read_cmd
    entry.mark_as_read(entry)
TypeError: mark_as_read() takes 1 positional argument but 2 were given

This happened a couple of weeks ago, around maybe v0.4 update?

The user is in the informantgroup.

Also:

$ ls -ld /var/cache/informant
drwxrwsr-x 4 root informant 4096 Feb  7 11:08 /var/cache/informant

Could you please kindly take a look to see if it's a bug?

Thank you.

Computer froze during pacman install, informant now hangs infinitely

I was in the middle of fixing one of my AUR packages, I ran makepkg -si and my pc froze sometime after the pre transaction hooks. Informant is causing some unexpected behavior since it now hangs forever during any operation even with sudo. This is all I can get out of it now. Network does not seem to matter, but it does fail when no network is present.

$ sudo informant -d check
Getting datfile from "/var/lib/informant.dat"
cfg_fname: None
config: {}
cli args: {'--all': False,
 '--config': None,
 '--debug': True,
 '--file': None,
 '--help': False,
 '--no-cache': False,
 '--raw': False,
 '--reverse': False,
 '--unread': False,
 '--version': False,
 '<item>': None,
 'check': True,
 'list': False,
 'read': False}

Removing /var/lib/informant.dat or reinstalling does nothing.

Informant prevents installation from local cache if there is no internet connection

Trying to reinstall a package from the local cache without internet connection (I broke systemd-networkd...), Informant popped up with the following error:

: Running pre-transaction hooks...
(1/2) Checking Arch News with Informant ...
Unable to read cache informantion: HTTPSConnectionPool(host='archlinux.org', port=443): Max retries exceeded with url: /feeds/news/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f1ee58406a0>: Failed to establish a new connection: [Errno -2] Name or service not known'))
Encountered feed error: <urlopen error [Errno -2] Name or service not known>
error: command failed to execute correctly
error: failed to commit transaction (failed to run transaction hooks)
Errors occurred, no packages were upgraded.

I think informant should only warn without preventing the installation if it cannot retrieve the RSS feed (at least when doing a local installation, but I don't think this can be easily detected).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.