diff options
author | hut <hut@lavabit.com> | 2010-04-27 03:34:01 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-27 03:34:01 +0200 |
commit | ebd4457e566ea00b68fbb5ab5552d68de12e3b2f (patch) | |
tree | 811c15ae650f72fd7eb70b96c8ccb4ecc814b443 | |
parent | e5112bfe57e7a8176e8d7d3fe27d442d3262cd88 (diff) | |
parent | 4db79381d4874318c76c605cf990c630c9d70115 (diff) | |
download | ranger-ebd4457e566ea00b68fbb5ab5552d68de12e3b2f.tar.gz |
Merge branch 'master' into cp
-rw-r--r-- | ranger/api/apps.py | 24 | ||||
-rw-r--r-- | ranger/defaults/apps.py | 81 |
2 files changed, 41 insertions, 64 deletions
diff --git a/ranger/api/apps.py b/ranger/api/apps.py index 90162e0b..d2e9ac4f 100644 --- a/ranger/api/apps.py +++ b/ranger/api/apps.py @@ -76,7 +76,7 @@ class Applications(FileManagerAware): application_handler = getattr(self, 'app_' + app) except AttributeError: if app in get_executables(): - return tup(app, *context) + return _generic_app(app, context) continue if self._meets_dependencies(application_handler): return application_handler(context) @@ -99,7 +99,7 @@ class Applications(FileManagerAware): handler = getattr(self, 'app_' + app) except AttributeError: if app in get_executables(): - return tup(app, *context) # generic app + return _generic_app(app, context) handler = self.app_default return handler(context) @@ -116,6 +116,13 @@ class Applications(FileManagerAware): result |= set(m[4:] for m in cls.__dict__ if m.startswith('app_')) return sorted(result) + @classmethod + def generic(cls, *args, **keywords): + flags = 'flags' in keywords and keywords['flags'] or "" + for name in args: + assert isinstance(name, str) + setattr(cls, "app_" + name, _generic_wrapper(name, flags=flags)) + def tup(*args): """ @@ -134,3 +141,16 @@ def depends_on(*args): fnc.dependencies = args return fnc return decorator + + +def _generic_app(name, context, flags=''): + """Use this function when no other information is given""" + context.flags += flags + return tup(name, *context) + + +def _generic_wrapper(name, flags=''): + """Wraps _generic_app into a method for Applications""" + assert isinstance(name, str) + return depends_on(name)(lambda self, context: + _generic_app(name, context, flags)) diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py index 6c09298a..4dd3bde5 100644 --- a/ranger/defaults/apps.py +++ b/ranger/defaults/apps.py @@ -92,13 +92,10 @@ class CustomApplications(Applications): # ----------------------------------------- application definitions + # Note: Trivial applications are defined at the bottom def app_pager(self, c): return tup('less', *c) - @depends_on('vim') - def app_vim(self, c): - return tup('vim', *c) - def app_editor(self, c): try: default_editor = os.environ['EDITOR'] @@ -135,16 +132,6 @@ class CustomApplications(Applications): else: return tup('mplayer', *c) - @depends_on("eog") - def app_eye_of_gnome(self, c): - c.flags += 'd' - return tup('eog', *c) - - @depends_on('mirage') - def app_mirage(self, c): - c.flags += 'd' - return tup('mirage', *c) - @depends_on('feh') def app_feh(self, c): arg = {1: '--bg-scale', 2: '--bg-tile', 3: '--bg-center'} @@ -171,10 +158,6 @@ class CustomApplications(Applications): except: return tup('feh', *c) - @depends_on("gimp") - def app_gimp(self, c): - return tup('gimp', *c) - @depends_on('aunpack') def app_aunpack(self, c): if c.mode is 0: @@ -182,15 +165,6 @@ class CustomApplications(Applications): return tup('aunpack', '-l', c.file.path) return tup('aunpack', c.file.path) - @depends_on('fceux') - def app_fceux(self, c): - return tup('fceux', *c) - - @depends_on('apvlv') - def app_apvlv(self, c): - c.flags += 'd' - return tup('apvlv', *c) - @depends_on('make') def app_make(self, c): if c.mode is 0: @@ -200,25 +174,6 @@ class CustomApplications(Applications): if c.mode is 2: return tup("make", "clear") - @depends_on('elinks') - def app_elinks(self, c): - c.flags += 'D' - return tup('elinks', *c) - - @depends_on('opera') - def app_opera(self, c): - c.flags += 'd' - return tup('opera', *c) - - @depends_on('firefox') - def app_firefox(self, c): - c.flags += 'd' - return tup("firefox", *c) - - @depends_on('javac') - def app_javac(self, c): - return tup("javac", *c) - @depends_on('java') def app_java(self, c): def strip_extensions(file): @@ -228,22 +183,6 @@ class CustomApplications(Applications): files_without_extensions = map(strip_extensions, c.files) return tup("java", files_without_extensions) - @depends_on('zsnes') - def app_zsnes(self, c): - return tup("zsnes", c.file.path) - - @depends_on('evince') - def app_evince(self, c): - return tup("evince", *c) - - @depends_on('zathura') - def app_zathura(self, c): - return tup("zathura", *c) - - @depends_on('wine') - def app_wine(self, c): - return tup("wine", c.file.path) - @depends_on('totem') def app_totem(self, c): if c.mode is 0: @@ -251,6 +190,24 @@ class CustomApplications(Applications): if c.mode is 1: return tup("totem", "--fullscreen", *c) + +# Often a programs invocation is trivial. For example: +# vim test.py readme.txt [...] +# This could be implemented like: +# @depends_on("vim") +# def app_vim(self, c): +# return tup("vim", *c.files) +# Instead of creating such a generic function for each program, just add +# its name here and it will be automatically done for you. +CustomApplications.generic('vim', 'fceux', 'elinks', 'wine', + 'zsnes', 'javac') + +# By setting flags='d', this programs will not block ranger's terminal: +CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince', + 'zathura', 'gimp', 'mirage', 'eog', flags='d') + +# What filetypes are recognized as scripts for interpreted languages? +# This regular expression is used in app_default() INTERPRETED_LANGUAGES = re.compile(r''' ^(text|application)/x-( haskell|perl|python|ruby|sh |