Removed references to GMail, enhance usb mount

master
Quentin Duchemin 2019-01-10 10:13:42 +01:00
parent dedb468116
commit 776a1e5588
6 changed files with 13 additions and 89 deletions

View File

@ -319,12 +319,6 @@ type = custom/script
exec = ~/.config/polybar/scripts/filesystem.sh
interval = 60
[module/gmail]
type = custom/script
exec = ~/.config/polybar/scripts/gmail/launch.py
tail = true
click-left = xdg-open https://mail.google.com
[module/system-uptime-pretty]
type = custom/script
exec = ~/.config/polybar/scripts/system-uptime-pretty.sh

View File

@ -1 +0,0 @@
*.json

View File

@ -1,28 +0,0 @@
#!/usr/bin/env python
import os
import pathlib
import httplib2
import webbrowser
from oauth2client import client, file
SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
DIR = os.path.dirname(os.path.realpath(__file__))
CLIENT_SECRETS_PATH = os.path.join(DIR, 'client_secrets.json')
CREDENTIALS_PATH = os.path.join(DIR, 'credentials.json')
storage = file.Storage(CREDENTIALS_PATH)
if pathlib.Path(CREDENTIALS_PATH).is_file():
credentials = storage.get()
credentials.refresh(httplib2.Http())
print('Credentials successfully refreshed')
else:
flow = client.flow_from_clientsecrets(CLIENT_SECRETS_PATH, scope=SCOPE,
redirect_uri=REDIRECT_URI)
auth_uri = flow.step1_get_authorize_url()
webbrowser.open(auth_uri)
auth_code = input('Enter the auth code: ')
credentials = flow.step2_exchange(auth_code)
storage.put(credentials)
print('Credentials successfully created')

View File

@ -1,50 +0,0 @@
#!/usr/bin/env python
import os
import pathlib
import subprocess
import time
import argparse
from apiclient import discovery, errors
from oauth2client import client, file
from httplib2 import ServerNotFoundError
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--prefix', default='')
parser.add_argument('-c', '--color', default='#e06c75')
parser.add_argument('-ns', '--nosound', action='store_true')
args = parser.parse_args()
DIR = os.path.dirname(os.path.realpath(__file__))
CREDENTIALS_PATH = os.path.join(DIR, 'credentials.json')
unread_prefix = '%{F' + args.color + '}' + args.prefix + ' %{F-}'
error_prefix = '%{F' + args.color + '}\uf06a %{F-}'
count_was = 0
def update_count(count_was):
gmail = discovery.build('gmail', 'v1', credentials=file.Storage(CREDENTIALS_PATH).get())
labels = gmail.users().labels().get(userId='me', id='INBOX').execute()
count = labels['messagesUnread']
if count > 0:
print(unread_prefix + str(count), flush=True)
else:
print(args.prefix, flush=True)
if not args.nosound and count_was < count and count > 0:
subprocess.run(['canberra-gtk-play', '-i', 'message'])
return count
while True:
try:
if pathlib.Path(CREDENTIALS_PATH).is_file():
count_was = update_count(count_was)
time.sleep(10)
else:
print(error_prefix + 'credentials not found', flush=True)
time.sleep(2)
except (errors.HttpError, ServerNotFoundError, OSError) as error:
print(error_prefix + str(error), flush=True)
time.sleep(5)
except client.AccessTokenRefreshError:
print(error_prefix + 'revoked/expired credentials', flush=True)
time.sleep(5)

View File

@ -1,17 +1,21 @@
#!/bin/sh
# Dependencies : jq ; udisks2
# Some updates by Quentin Duchemin on 18/03/07
# - Add label in lsblk selection
# - Add symbols from Material Google font
# - Remove term emulator opening and unused parts
# - Remove udiskctl power-off because we cannot mount again the removable device
# - Change printed name from vendor of the device to partition name (arbitrary choice)
# On 18/11/20
# - Change jq rm == '1' to rm == true
usb_print() {
devices=$(lsblk -Jplno NAME,TYPE,RM,SIZE,MOUNTPOINT,VENDOR,LABEL)
output=""
counter=0
for unmounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint == null) | .name'); do
for unmounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type ==
"part") | select(.rm == true) | select(.mountpoint == null) | .name'); do
unmounted=$(echo "$devices" | jq -r '.blockdevices[] | select(.name == "'"$unmounted"'") | .label')
unmounted=$(echo "$unmounted" | tr -d ' ')
@ -25,7 +29,8 @@ usb_print() {
output="$output$space$unmounted"
done
for mounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint != null) | .size'); do
for mounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type ==
"part") | select(.rm == true) | select(.mountpoint != null) | .size'); do
if [ $counter -eq 0 ]; then
space=""
else
@ -54,7 +59,8 @@ case "$1" in
--mount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for mount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint == null) | .name'); do
for mount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type ==
"part") | select(.rm == true) | select(.mountpoint == null) | .name'); do
mountpoint=$(udisksctl mount --no-user-interaction -b "$mount")
done
@ -63,7 +69,8 @@ case "$1" in
--unmount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for unmount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint != null) | .name'); do
for unmount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type ==
"part") | select(.rm == true) | select(.mountpoint != null) | .name'); do
udisksctl unmount --no-user-interaction -b "$unmount"
#power-off makes us unable to mount again...
#udisksctl power-off --no-user-interaction -b "$unmount"

View File

@ -2,11 +2,13 @@
borderless = True
custom_url_handler = firefox
enabled_plugins = TerminalShot, LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
suppress_multiple_term_dialog = True
title_font = DejaVu Sans Mono 11
title_use_system_font = False
use_custom_url_handler = True
[keybindings]
layout_launcher = <Shift><Alt>l
reset_clear = <Primary><Shift>l
switch_to_tab_1 = None
switch_to_tab_2 = None
[layouts]