Skip to content

Commit 62b13f7

Browse files
committed
tooling update
1 parent 4636fc5 commit 62b13f7

8 files changed

Lines changed: 303 additions & 259 deletions

File tree

Pipfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 195 deletions
This file was deleted.

grive_indicator/__init__.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import re
2323
import signal
2424
import subprocess
25+
import sys
2526

2627
gi.require_version("AppIndicator3", "0.1")
2728
gi.require_version("Gtk", "3.0")
@@ -40,6 +41,8 @@
4041
runConfigure,
4142
show_notify,
4243
get_version,
44+
openLocal,
45+
openRemote,
4346
)
4447

4548
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
@@ -56,7 +59,7 @@ def __init__(self, cliArgs, *args, **kwargs):
5659
)
5760
if cliArgs.version:
5861
print(get_version())
59-
exit()
62+
sys.exit()
6063
self.folder = cliArgs.folder
6164
self.debug = cliArgs.debug
6265

@@ -94,11 +97,11 @@ def menu_setup(self):
9497
self.syncNow_item.show()
9598

9699
self.Remote_item = Gtk.MenuItem("Remote Google Drive")
97-
self.Remote_item.connect("activate", self.openRemote)
100+
self.Remote_item.connect("activate", openRemote)
98101
self.Remote_item.show()
99102

100103
self.Local_item = Gtk.MenuItem("Local Folder")
101-
self.Local_item.connect("activate", self.openLocal)
104+
self.Local_item.connect("activate", openLocal)
102105
self.Local_item.show()
103106

104107
self.Settings_item = Gtk.MenuItem("Preferences")
@@ -169,27 +172,14 @@ def syncNow(self, widget):
169172
if grive_out_line.startswith("sync"):
170173
show_notify(grive_out_line)
171174
logger.debug("Finished sync")
172-
self.lastSync = re.split("T|\.", datetime.now().isoformat())[1]
175+
self.lastSync = re.split(r"T|\.", datetime.now().isoformat())[1]
173176
self.lastSync_item.set_label("Last sync at " + self.lastSync)
174-
except OSError:
175-
logger.error("Missing grive in PATH")
176-
pass
177+
except OSError as e:
178+
logger.error(f"Missing grive in PATH: {e}")
179+
sys.exit(1)
177180
except Exception as e:
178-
logger.error("Error occurred running grive. Skipping sync: %s" % e)
179-
pass
180-
181-
def openRemote(self, widget):
182-
Gtk.show_uri_on_window(None, "https://drive.google.com", Gdk.CURRENT_TIME)
183-
184-
def openLocal(self, widget):
185-
localFolder = "file://{}".format(Config().getValue("folder"))
186-
if os.getenv("SNAP") is not None:
187-
logger.debug("Opening {} in snap: xdg-open".format(localFolder))
188-
subprocess.call(["xdg-open", localFolder])
189-
else:
190-
logger.debug("Opening {}: show_uri_on_window".format(localFolder))
191-
Gtk.show_uri_on_window(None, localFolder, Gdk.CURRENT_TIME)
192-
# subprocess.call(["xdg-open", "file://{}".format(Config().getValue('folder'))])
181+
logger.error(f"Error occurred running grive. Skipping sync: {e}")
182+
# pass
193183

194184
def settings(self, widget):
195185
settings.main(self.debug)
@@ -214,7 +204,7 @@ def main():
214204
parser.add_argument(
215205
"--version", action="store_true", help="Print the version and quit"
216206
)
217-
# TODO: Add auth parameter
207+
218208
args = parser.parse_args()
219209

220210
app = GriveIndicator(args)

grive_indicator/tools.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import requests
2424
import shutil
2525
import subprocess
26+
import sys
2627

2728
gi.require_version("AppIndicator3", "0.1")
2829
gi.require_version("Gio", "2.0")
@@ -31,7 +32,7 @@
3132

3233
from contextlib import suppress
3334
from gi.repository import AppIndicator3
34-
from gi.repository import Gtk, Notify, GdkPixbuf
35+
from gi.repository import Gtk, Notify, GdkPixbuf, Gdk
3536
from pathlib import Path
3637
from xdg.BaseDirectory import xdg_config_home
3738

@@ -121,7 +122,7 @@ def runConfigure(folder, selective=None):
121122
def _runConfigure(folder, selective=None):
122123
logger.debug("Saving configurations: folder:%s selective:%s" % (folder, selective))
123124
shutil.copy(Path(root_data / "grive_indicator.conf"), config_file)
124-
with open(Path(folder / ".griveignore"), "w") as griveignore:
125+
with open((folder / ".griveignore"), "w") as griveignore:
125126
griveignore.write(selective)
126127
conf = Config()
127128
conf.setValue("folder", folder)
@@ -193,14 +194,25 @@ def show_notify(line):
193194
notification.show()
194195

195196

197+
def openRemote(widget):
198+
Gtk.show_uri_on_window(None, "https://drive.google.com", Gdk.CURRENT_TIME)
199+
200+
201+
def openLocal(widget):
202+
localFolder = "file://{}".format(Config().getValue("folder"))
203+
if os.getenv("SNAP") is not None:
204+
logger.debug("Opening {} in snap: xdg-open".format(localFolder))
205+
subprocess.call(["xdg-open", localFolder])
206+
else:
207+
logger.debug("Opening {}: show_uri_on_window".format(localFolder))
208+
Gtk.show_uri_on_window(None, localFolder, Gdk.CURRENT_TIME)
209+
# subprocess.call(["xdg-open", "file://{}".format(Config().getValue('folder'))])
210+
211+
196212
def get_version():
197213
"""Get version depending if on dev or released version"""
198214
version_file = Path(Path(__file__).resolve().parent / "version")
199-
version = (
200-
open(version_file, "r", encoding="utf-8")
201-
.read()
202-
.strip()
203-
)
215+
version = open(version_file, "r", encoding="utf-8").read().strip()
204216
if os.getenv("SNAP_REVISION"):
205217
snap_appendix = ""
206218
snap_rev = os.getenv("SNAP_REVISION")
@@ -222,7 +234,9 @@ def get_version():
222234

223235

224236
ind = AppIndicator3.Indicator.new(
225-
"Grive Indicator", str(getIcon()), AppIndicator3.IndicatorCategory.APPLICATION_STATUS
237+
"Grive Indicator",
238+
str(getIcon()),
239+
AppIndicator3.IndicatorCategory.APPLICATION_STATUS,
226240
)
227241
ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
228242
ind.set_attention_icon_full("indicator-messages-new", "Message attention icon")

0 commit comments

Comments
 (0)