Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
Prepping for release
Browse files Browse the repository at this point in the history
  • Loading branch information
lots0logs committed Jun 25, 2017
1 parent 7ed283f commit 305c51f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 44 deletions.
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/make -f

DESTDIR ?= /

all: install

install:
# Alerts Data
install -d dist/alerts.json $(DESTDIR)/var/lib/antergos-alerts/alerts.json

# ALPM Hook
install -d dist/antergos-alerts.hook $(DESTDIR)/usr/share/libalpm/hooks/antergos-alerts.hook

# Logo for desktop notification
install -d dist/logo-square32.png $(DESTDIR)/usr/share/antergos/logo-square32.png

# Antergos Alerts
install -dm755 src/antergos-alerts.py $(DESTDIR)/usr/bin/antergos-alerts

# Utility script for desktop notifications
install -dm755 src/antergos-notify.sh $(DESTDIR)/usr/bin/antergos-notify

uninstall:
# Alerts Data
rm -f $(DESTDIR)/var/lib/antergos-alerts/alerts.json

# ALPM Hook
rm -f $(DESTDIR)/usr/share/libalpm/hooks/antergos-alerts.hook

# Logo for desktop notification
rm -f $(DESTDIR)/usr/share/antergos/logo-square32.png

# Antergos Alerts
rm -f $(DESTDIR)/usr/bin/antergos-alerts

# Utility script for desktop notifications
rm -f $(DESTDIR)/usr/bin/antergos-notify


.PHONY: all install uninstall
2 changes: 1 addition & 1 deletion dist/alerts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"20170623": "weak-password-hashes"
"20170625": "cnchi-installer-weak-password-hashes"
}
2 changes: 1 addition & 1 deletion dist/antergos-alerts.hook
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Type = File
Target = var/lib/antergos-alerts/alerts.json

[Action]
Description = Check for new antergos alerts.
Description = Checking for new antergos alerts.
When = PostTransaction
Depends = antergos-alerts
Exec = /usr/bin/antergos-alerts
78 changes: 59 additions & 19 deletions src/antergos-alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@
APP_NAME = 'ANTERGOS_NOTIFY'
LOCALE_DIR = '/usr/share/locale'

data = open(os.path.normpath('../dist/alerts.json')).read()
ALERTS = json.loads(data)
ALERT_IDS = ALERTS.keys()
DOING_INSTALL = os.environ.get('CNCHI_RUNNING', False)
IS_GRAPHICAL_SESSION = os.environ.get('DISPLAY', False)

ALERTS_DIR = '/var/lib/antergos-alerts'
ALERTS_JSON = '/var/lib/antergos-alerts/alerts.json'
COMPLETED_JSON = '/var/lib/antergos-alerts/completed.json'

COMPLETED_ALERT_IDS = [] #json.loads('/var/cache/antergos-alerts/completed.json')
try:
with open(ALERTS_JSON) as data:
ALERTS = json.loads(data)
except (OSError, json.JSONDecodeError):
ALERTS = {}

try:
with open(COMPLETED_JSON) as data:
COMPLETED_ALERT_IDS = json.loads(data)
except (OSError, json.JSONDecodeError):
COMPLETED_ALERT_IDS = []


ALERT_IDS = ALERTS.keys()


def setup_gettext()-> None:
Expand All @@ -55,14 +71,21 @@ def setup_gettext()-> None:
pass


def print_notice_to_stdout(alert_slug: str) -> None:
prefix = colored('*', color='red', attrs=['bold', 'blink'])
def get_localized_alert_message() -> tuple:
subject = _('ATTENTION: Antergos System Message')

part1 = _('A new Antergos Alert has been issued.')
part2 = _('Alerts contain important information regarding your system.')
part3 = _('You can view the alert at the following URL')

return subject, part1, part2, part3


def print_notice_to_stdout(alert_slug: str) -> None:
prefix = colored('*', color='red', attrs=['bold', 'blink'])

subject, part1, part2, part3 = get_localized_alert_message()

cprint(
f' =======>>> {subject} <<<======= ',
color='white',
Expand All @@ -84,25 +107,42 @@ def print_notice_to_stdout(alert_slug: str) -> None:
)


if __name__ == '__main__':
doing_install = os.environ.get('CNCHI_RUNNING', False)
is_graphical_session = os.environ.get('DISPLAY', False)

def do_alerts() -> None:
# Filter out completed alerts
ALERT_IDS = list(set(ALERT_IDS) - set(COMPLETED_ALERT_IDS))
# Sort by date
ALERT_IDS.sort()
alerts_ids = list(set(ALERT_IDS) - set(COMPLETED_ALERT_IDS))

setup_gettext()
alerts_ids.sort()

subject, part1, part2, part3 = get_localized_alert_message()

for alert_id in ALERT_IDS:
alert = ALERTS[alert_id]
environment = os.environ.copy()
environment['ALERT SUBJECT'] = subject
environment['ALERT_MESSAGE'] = f'{part1} {part2} {part3}'

print_notice_to_stdout(alert)
for alert_id in alerts_ids:
alert_slug = ALERTS[alert_id]

if is_graphical_session and not doing_install:
print_notice_to_stdout(alert_slug)

if IS_GRAPHICAL_SESSION:
# Display desktop notification.
environment['ALERT_URL'] = f'https://antergos.com/wiki/alerts/{alert_slug}'
try:
subprocess.check_call(['./antergos-notify.sh', alert])
subprocess.run(['./antergos-notify.sh'], env=environment, check=True)
except subprocess.CalledProcessError:
pass

COMPLETED_ALERT_IDS.append(alert_id)


if __name__ == '__main__':
if DOING_INSTALL:
sys.exit(0)

setup_gettext()
do_alerts()

with open(COMPLETED_JSON, 'w') as data:
data.write(json.dumps(COMPLETED_ALERT_IDS))

sys.exit(0)
25 changes: 2 additions & 23 deletions src/antergos-notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with antergos-notify; if not, see <http://www.gnu.org/licenses/>.

export TEXTDOMAIN="ANTERGOS_NOTIFY"
export GETTEXT='gettext "ANTERGOS_NOTIFY"'

# ===>>> BEGIN Translatable Strings <<<=== #

# Notification Subject
_subject=$(${GETTEXT} 'ATTENTION: Antergos System Message')

# Notification Body Part 1
_part1=$(${GETTEXT} 'A new Antergos Alert has been issued.')

# Notification Body Part 2
_part2=$(${GETTEXT} 'Alerts contain important information regarding your installed system.')

# Notification Body Part 3
_part3=$(${GETTEXT} 'You can view the alert at the following URL')

# ===>>> END Translatable Strings <<<=== #

_alert="/$1"
#_view_message="$(python -c "import html;print(html.escape(\"${_part3}\"))")"
#_view_message_link="<a href=\"https://antergos.com/wiki/alerts${_alert}\">${_view_message}</a>"
_view_message_link="https://antergos.com/wiki/alerts${_alert}"
_msg="${_part1} ${_part2} ${_part3}:\n\n${_view_message_link}\n"
_msg="${ALERT_MESSAGE}:\n\n${ALERT_URL}\n"


maybe_display_desktop_alert() {
Expand All @@ -50,7 +29,7 @@ maybe_display_desktop_alert() {
fi

_icon='/usr/share/antergos/logo-square32.png'
_command="/usr/bin/notify-send -u critical -a Antergos -i ${_icon} \"${_subject}\" \"${_msg}\""
_command="/usr/bin/notify-send -u critical -a Antergos -i ${_icon} \"${ALERT_SUBJECT}\" \"${_msg}\""
_addr='DBUS_SESSION_BUS_ADDRESS'

_processes=($(ps aux | grep '[d]bus-daemon --session' | awk '{print $2}' | xargs))
Expand Down

0 comments on commit 305c51f

Please sign in to comment.