Skip to content

Commit

Permalink
Check default profile paths, added option for custom path (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
noam09 committed Apr 16, 2019
1 parent 41fd08e commit b65e0f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
43 changes: 26 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Usage tracking
script_directory = os.path.dirname(os.path.realpath(__file__))
usage_db = os.path.join(script_directory, 'usage.json')
usage_db = os.path.join(script_directory, "usage.json")
if os.path.exists(usage_db):
with open(usage_db, 'r') as db:
# Read JSON string
Expand All @@ -28,18 +28,23 @@
usage_cache = json.loads(raw)

# Initialize items cache and Remmina profiles path
remmina_bin = ''
remmina_bin = ""
# Locate Remmina profiles and binary
remmina_profiles_path = "{}/.local/share/remmina".format(os.environ.get('HOME'))
default_paths = ["{}/.local/share/remmina".format(os.environ.get('HOME')),
"{}/.remmina".format(os.environ.get('HOME'))]
# remmina_profiles_path = "{}/.local/share/remmina".format(os.environ.get('HOME'))
# remmina_profiles_path_alt = "{}/.remmina".format(os.environ.get('HOME'))
remmina_bin = distutils.spawn.find_executable('remmina')
# This extension is useless without remmina
if remmina_bin is None or remmina_bin == '':
logger.error('Remmina executable path could not be determined')
if remmina_bin is None or remmina_bin == "":
logger.error("Remmina executable path could not be determined")
exit()
# Check if Remmina profiles directory exists
if not os.path.isdir(remmina_profiles_path):
logger.error("Remmina profiles directory doesn't exist ({})".format(remmina_profiles_path))
exit()
remmina_profiles_path = None
# Check default paths first
for p in default_paths:
if os.path.isdir(p):
remmina_profiles_path = p


class RemminaExtension(Extension):
Expand All @@ -61,8 +66,7 @@ def list_profiles(self, query):
temp = profiles
profiles = sorted(temp)
except Exception as e:
print('Failed getting profile files')

logger.error("Failed getting Remmina profile files")
for p in profiles:
base = os.path.basename(p)
title, desc, proto = profile_details(p)
Expand All @@ -82,11 +86,17 @@ def list_profiles(self, query):

class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
global remmina_profiles_path
if extension.preferences["profiles"] is not "" \
or not remmina_profiles_path:
# Tilde (~) won't work alone, need expanduser()
remmina_profiles_path = os.path.expanduser(extension.preferences["profiles"])
# pref_profiles_path = extension.preferences['profiles']
logger.debug("Remmina profiles path: {}".format(remmina_profiles_path))
# Get query
term = (event.get_argument() or '').lower()
term = (event.get_argument() or "").lower()
# Display all items when query empty
profiles_list = extension.list_profiles(term)

return RenderResultListAction(profiles_list[:8])


Expand All @@ -95,7 +105,7 @@ def on_event(self, event, extension):
global usage_cache
# Get query
data = event.get_data()
on_enter = data['id']
on_enter = data["id"]
# The profilefile name is the ID
base = os.path.basename(on_enter)
b = os.path.splitext(base)[0]
Expand All @@ -107,17 +117,16 @@ def on_event(self, event, extension):
# Update usage JSON
with open(usage_db, 'w') as db:
db.write(json.dumps(usage_cache, indent=2))

return RunScriptAction('#!/usr/bin/env bash\n{} -c {}\n'.format(remmina_bin, on_enter), None).run()


def create_item(name, icon, keyword, description, on_enter):
return ExtensionResultItem(
name=name,
description=description,
icon='images/{}.svg'.format(icon),
icon="images/{}.svg".format(icon),
on_enter=ExtensionCustomAction(
{'id': on_enter})
{"id": on_enter})
)


Expand Down Expand Up @@ -188,5 +197,5 @@ def profile_details(profile_path):
return "", "", "rdp"


if __name__ == '__main__':
if __name__ == "__main__":
RemminaExtension().run()
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"name": "Remmina",
"description": "Quick access to Remmina profiles",
"default_value": "r"
},
{
"id": "profiles",
"type": "input",
"name": "Remmina Profiles Directory",
"description": "Where Remmina stores profile configuration files <br /><code>~/.local/share/remmina</code> and <code>~/.remmina</code> are checked by default",
"default_value": ""
}
]
}

0 comments on commit b65e0f7

Please sign in to comment.