Skip to content

Commit

Permalink
Add config to do desktop notifications by running an abitrary command.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jan 13, 2017
1 parent dc93a72 commit 16d8c35
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
43 changes: 29 additions & 14 deletions python/servo/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,39 @@ def notify_darwin(title, text):
raise Exception("Optional Python module 'pyobjc' is not installed.")


def notify_build_done(elapsed, success=True):
def notify_with_command(command):
def notify(title, text):
if call([command, title, text]) != 0:
raise Exception("Could not run '%s'." % command)
return notify


def notify_build_done(config, elapsed, success=True):
"""Generate desktop notification when build is complete and the
elapsed build time was longer than 30 seconds."""
if elapsed > 30:
notify("Servo build", "%s in %s" % ("Completed" if success else "FAILED", format_duration(elapsed)))
notify(config, "Servo build",
"%s in %s" % ("Completed" if success else "FAILED", format_duration(elapsed)))


def notify(title, text):
def notify(config, title, text):
"""Generate a desktop notification using appropriate means on
supported platforms Linux, Windows, and Mac OS. On unsupported
platforms, this function acts as a no-op."""
platforms = {
"linux": notify_linux,
"linux2": notify_linux,
"win32": notify_win,
"darwin": notify_darwin
}
func = platforms.get(sys.platform)
platforms, this function acts as a no-op.
If notify-command is set in the [tools] section of the configuration,
that is used instead."""
notify_command = config["tools"].get("notify-command")
if notify_command:
func = notify_with_command(notify_command)
else:
platforms = {
"linux": notify_linux,
"linux2": notify_linux,
"win32": notify_win,
"darwin": notify_darwin
}
func = platforms.get(sys.platform)

if func is not None:
try:
Expand Down Expand Up @@ -324,7 +339,7 @@ def build(self, target=None, release=False, dev=False, jobs=None,
pass

# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed, status == 0)
notify_build_done(self.config, elapsed, status == 0)

print("Build %s in %s" % ("Completed" if status == 0 else "FAILED", format_duration(elapsed)))
return status
Expand Down Expand Up @@ -375,7 +390,7 @@ def build_cef(self, jobs=None, verbose=False, release=False,
elapsed = time() - build_start

# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed)
notify_build_done(self.config, elapsed)

print("CEF build completed in %s" % format_duration(elapsed))

Expand Down Expand Up @@ -430,7 +445,7 @@ def build_geckolib(self, with_gecko=None, jobs=None, verbose=False, release=Fals
elapsed = time() - build_start

# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed)
notify_build_done(self.config, elapsed)

print("GeckoLib build completed in %s" % format_duration(elapsed))

Expand Down
6 changes: 6 additions & 0 deletions servobuild.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ system-cargo = false
# Defaults to true
rustc-with-gold = true

# If uncommented, this command is used instead of the platform’s default
# to notify at the end of a compilation that took a long time.
# This is the name or path of an executable called with two arguments:
# the summary and content of the notification.
#notify-command = "notify-send"

[build]
# Set "mode = dev" or use `mach build --dev` to build the project with warning.
# or Set "mode = release" or use `mach build --release` for optimized build.
Expand Down

0 comments on commit 16d8c35

Please sign in to comment.