Commits

Iñigo Serna  committed 6993333

Update code to use python v2.5+ "ternary operator" and "any".

* lfm/lfm.py (Lfm.run): update code to use python v2.5+ ternary operator
* lfm/lfm.py (PowerCLI.display):
* lfm/lfm.py (PowerCLI.__run):
* lfm/lfm.py (Vfs.init_dir):
* lfm/actions.py (toggle_manage_otherpane):
* lfm/messages.py (EntryLine.manage_keys.__prev_step):
* lfm/messages.py (EntryLine.manage_keys.__next_step):
* lfm/files.py (__get_filetype):
* lfm/utils.py (get_shell_output3_subprocess):
* lfm/config.py (Config.check_progs):
* lfm/pyview.py (InternalView.__validate_buf):

* lfm/lfm.py (PowerCLI.__check_loop): update code to use python v2.5+ "any"

  • Participants
  • Parent commits 945cc0a

Comments (0)

Files changed (9)

+Sat May 14 12:15:47 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/lfm.py (PowerCLI.__check_loop): update code to use python v2.5+ "any"
+
+Sat May 14 12:12:22 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/lfm.py (Lfm.run): update code to use python v2.5+ ternary operator
+	* lfm/lfm.py (PowerCLI.display):
+	* lfm/lfm.py (PowerCLI.__run):
+	* lfm/lfm.py (Vfs.init_dir):
+	* lfm/actions.py (toggle_manage_otherpane):
+	* lfm/messages.py (EntryLine.manage_keys.__prev_step):
+	* lfm/messages.py (EntryLine.manage_keys.__next_step):
+	* lfm/files.py (__get_filetype):
+	* lfm/utils.py (get_shell_output3_subprocess):
+	* lfm/config.py (Config.check_progs):
+	* lfm/pyview.py (InternalView.__validate_buf):
+
 Sun May  8 18:28:26 2011  Iñigo Serna  <inigoserna@gmail.com>
 
 	* lfm/compress.py (PackagerTAR): implemented tar un/compress
 ============================================================================
-Last update:	Time-stamp: <2011-05-08 18:31:29 inigo>
+Last update:	Time-stamp: <2011-05-14 12:17:47 inigo>
 ============================================================================
 
-- update sites: katxi, terra, googlecode, freshmeat, cheeseshop, bitbucket
-- release & announce: python-lists*, cheeseshop, freshmeat
 
-Bugs:
-=====
+- Ctrl-G: Open PowerCLI
+- F11: PowerCLI
+  . Stored commands
+  . History
+- messages.EntryLine
+  . ? accept $b[0-9]: bookmarks
+  . Ctrl-D?: open bookmarks selection list
+  . Ctrl-Y: open history selection list
+- history
+  . s/historic/history/g
+  . per edit type
+    . file/path: rename, copy, move, mkdir, create_link, edit_link
+    . find
+    . grep
+    . do_something_on_file, execute_file
+    . powercli
+  . store in ~/.lfm_history
+    . format:
+      [type]
+      entry_1
+      ...
+
 
 General:
 ========
-Medium Priority:
+High Priority:
   + enhancements:
-1   - catch exception in main
-1   - look to use key in sort/ed comp python v2.5+
-1   - test and improve PowerCLI
-1   - don't like much how recursive chmod/chown/chgrp currently works
+    - clean code
+      . look to use key in sort/ed cmp
+    - test and improve PowerCLI
+    - don't like much how recursive chmod/chown/chgrp currently works
       . split in 2 different features chmod and chown/chgrp ?
-2   - pyview: tail mode:
-      . option -f, document
-      . powercli: |: run as tail -f, substitute run sync by default, document
-2   - substitute curses.color_pair(X) for COL_XXX
-  + ui:
-1   - support for languages with wide chars
+    - support for languages with wide chars
       . check the real length on screen of the utf8-encoded strings.
         http://bugs.python.org/issue6755
         http://stackoverflow.com/questions/2476953/python-utf-8-howto-align-printout
-3   - speed up cursor movement => curses.panel
-3   - tab views:
+    - history
+      . make persistent between sessions => ~/.lfm_history
+      . specific per entry type
+  + documentation:
+    - document .lfmrc contents
+    - be sure version and release date is correct in all files
+    - update NEWS, clean TODO
+
+Medium Priority:
+  + enhancements:
+    - pyview: tail mode:
+      . option -f, document
+      . powercli: |: run as tail -f, substitute run sync by default, document
+    - substitute curses.color_pair(X) for COL_XXX
+  + ui:
+    - speed up cursor movement => curses.panel
+    - tab views:
       . 2 columns mode
       . customized: permissions instead of date
       . quick view
       . info view
   + new features:
-1   - history
-      . make persistent between sessions
-      . specific per entry type
-2   - copy or move to: allow bookmarks: $b1
-2   - diff and sync dirs: use filecmp.dircmp or rsync
-1 + documentation:
-    - document .lfmrc contents
-    - be sure version and release date is correct in all files
-    - update NEWS, clean TODO
+    - copy or move to: allow bookmarks: $b1
+    - diff and sync dirs: use filecmp.dircmp or rsync
 
 Low Priority (maybe some day):
   + enhancements:
     . new vfs: .rpm, .cpio, .deb, .jar, .xpi, .egg
     . show directory under cursor in the other panel: mc: Alt+O
     . keybindings customization
-    . background processes: copy/move
+    . background processes: copy/move/delete
   + other:
     . use mimetypes module
     . use pyinotify module
   + remote vfs: ssh, ftp, smb, webdav => read FAQ entry about fuse integration
   + advanced file rename tool => use PowerCLI
   + i18n => curses ui programming is very hard when dealing with different languages
-            because strings length could change so it's imposible to design a nice
+            because strings have different lengths so it's imposible to design a nice
             and working interface for every language
-  + sessions
   + mouse support
   + UI to configure preferences
   + "save delete" option => move to ~/.Trash
 
 
-Upgrading python version, interesting features in new versions
-  + python 2.4
-    - sorted
-    - sort, sorted: cmp -> key
-    - subprocess
-    - property
-    - unicodetata.east_asian_width
-  + python 2.5
-    - ternary operator
-    - any, all
-    - ctypes
-  + python 2.6
-    - with
-    - multiprocessing
-    - subprocess.Popen.{send_signal,kill,terminate}
-    - format
-    - collections.namedtuple
-    - os.closerange()
-    - try: except Exception as
-  + python 2.7
-    - subprocess.check_output
-    - collections.OrderedDict
-  + python 3.x
-    - has_key => in
-    - no module cPickle
-    - print()
-
-
 Known Bugs:
 ===========
 + general:
     files are not deleted / moved in real path
 
 
+Python versions:
+================
+Upgrading python version, interesting new features by version
++ python 2.4
+  - sorted
+  - sort, sorted: cmp -> key
+   - subprocess
+   - property
+  - unicodetata.east_asian_width
++ python 2.5
+  - ternary operator
+  - any, all
+  - ctypes
++ python 2.6
+  - with
+  - multiprocessing
+  - subprocess.Popen.{send_signal,kill,terminate}
+  - format
+  - collections.namedtuple
+  - os.closerange()
+  - try: except Exception as
++ python 2.7
+  - subprocess.check_output
+  - collections.OrderedDict
++ python 3.x
+  - print()
+  - has_key => in
+  - collections.OrderedDict
+  - no module cPickle
+
+
 ============================================================================
 
 DONE:
 - config: sort entries when saving
 - PowerCLI
 - implemented tar un/compress
-- fix bugs:
+- fixed bugs:
   . pyview:
     . last char is not shown if file size is small
     . last line and wrap: cursor_down or page_next
 - Daniel Echeverry: debian mantainer
 - Martin Steigerwald: bug report
 - Xin Wang: bug report
+- Jesper Vestergaard: asked about background file operations

File lfm/actions.py

     app.regenerate()
 
 def toggle_manage_otherpane(tab):
-#     app.prefs.options['manage_otherpane'] = 1 if app.prefs.options['manage_otherpane'] == 0 else 0 # python v2.5+
-    if app.prefs.options['manage_otherpane'] == 0:
-        app.prefs.options['manage_otherpane'] = 1
-    else:
-        app.prefs.options['manage_otherpane'] = 0
+    app.prefs.options['manage_otherpane'] = 1 if app.prefs.options['manage_otherpane'] == 0 else 0
     return RET_HALF_UPDATE_OTHER
 
 def show_size(tab):

File lfm/config.py

     def check_progs(self):
         for k, v in defaultprogs.items():
             r = get_shell_output('%s \"%s\"' % (sysprogs['which'], v))
-            # self.progs[k] = v if r else '' # python v2.5+
-            if r:
-                self.progs[k] = v
-            else:
-                self.progs[k] = ''
+            self.progs[k] = v if r else ''
 
 
     def load(self):

File lfm/files.py

         except OSError:
             return FTYPE_NLNK
         else:
-            if stat.S_ISDIR(mode):
-                return FTYPE_LNK2DIR
-            else:
-                return FTYPE_LNK
-            # return FTYPE_LNK2DIR if stat.S_ISDIR(mode) else FTYPE_LNK # python v2.5+
+            return FTYPE_LNK2DIR if stat.S_ISDIR(mode) else FTYPE_LNK
     if stat.S_ISCHR(lmode):
         return FTYPE_CDEV
     if stat.S_ISBLK(lmode):
 # -*- coding: utf-8 -*-
 
 # Copyright (C) 2001-11  Iñigo Serna
-# Time-stamp: <2011-05-08 01:30:34 inigo>
+# Time-stamp: <2011-05-14 12:16:46 inigo>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
                     self.act_pane, self.noact_pane = self.lpane, self.rpane
             elif ret == RET_TAB_NEW:
                 tab = self.act_pane.act_tab
-#                 path = os.path.dirname(tab.vbase) if tab.vfs else tab.path # python v2.5+
-                path = tab.vfs=='' and tab.path or os.path.dirname(tab.vbase)
+                path = tab.path if tab.vfs=='' else os.path.dirname(tab.vbase)
                 idx = self.act_pane.tabs.index(tab)
                 newtab = TabVfs(self.act_pane)
                 newtab.init(path)
     def display(self):
         self.visible = True
         tab = self.app.act_pane.act_tab
-        # path = vfs.join(tab) if tab.vfs else tab.path # python v2.5+
-        path = tab.vfs and vfs.join(tab) or tab.path
+        path = vfs.join(tab) if tab.vfs else tab.path
         l = self.app.maxw/6 - 4
         if len(path) > l:
             path = '~'+ path[-l-1:]
-        # userchar = '#' if os.getuid()==0 else '$' # python v2.5+
-        useridchar = os.getuid()==0 and '#' or '$'
+        useridchar = '#' if os.getuid()==0 else '$'
         self.win.erase()
         self.win.addstr('[%s]%s ' % (utils.encode(path), useridchar),
                         curses.color_pair(24) | curses.A_BOLD)
     def __check_loop(self, cmd, selected):
         if not selected:
             return False
-        # return any((var in cmd) for var in \
-        #                ('$f', '$v', '$F', '$E', '$i', '$tm', '$ta', '$tc')) # Python v2.5+
-        for var in ('$f', '$v', '$F', '$E', '$i', '$tm', '$ta', '$tc'):
-            if var in cmd:
-                return True
-        else:
-            return False
+        return any((var in cmd) for var in \
+                       ('$f', '$v', '$F', '$E', '$i', '$tm', '$ta', '$tc'))
 
 
     def __replace_python(self, cmd, lcls):
             except KeyboardInterrupt:
                 os.system('reset')
                 msg = 'Stopped by user'
-            # st = -1 if msg else 0 # pyhon v2.5+
-            st = msg and -1 or 0
+            st = -1 if msg else 0
         elif mode == PowerCLI.RUN_BACKGROUND:
             utils.run_in_background(cmd, path)
             st, msg = 0, ''
 
 
     def init_dir(self, path):
-        # old_path = self.path if self.path and not self.vfs else None # python v2.5+
-        if self.path and not self.vfs:
-            old_path = self.path
-        else:
-            old_path = ''
+        old_path = self.path if self.path and not self.vfs else ''
         try:
             app = self.pane.app
             self.nfiles, self.files = files.get_dir(path, app.prefs.options['show_dotfiles'])

File lfm/messages.py

             pos -= 1
             while pos > 0 and self.text[pos] not in stepchars:
                 pos -=1
-            # return pos if pos > 0 else 0 # python v2.5+
-            return (pos > 0) and pos or 0
+            return pos if pos > 0 else 0
 
         def __next_step(pos):
             pos += 1
             l = len(self.text)
             while pos < l and self.text[pos] not in stepchars:
                 pos +=1
-            # return pos if pos < l  else l # python v2.5+
-            return (pos < l) and pos or l
+            return pos if pos < l  else l
 
         while True:
             self.show()

File lfm/pyview.py

 # -*- coding: utf-8 -*-
 
 # Copyright (C) 2001-11  Iñigo Serna
-# Time-stamp: <2011-05-08 01:31:17 inigo>
+# Time-stamp: <2011-05-14 12:12:24 inigo>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
             self.x0 = int((app.maxw-col_max)/2)
         else:
             self.x0 = 1
-            # self.y0 = 0 if self.large else 1 # python v2.5+
-            if self.large:
-                self.y0 = 0
-            else:
-                self.y0 = 1
+            self.y0 = 0 if self.large else 1
         self.buf = buf
 
     def init_curses(self):

File lfm/utils.py

         time.sleep(0.1)
     buf = p.stderr.read()
     p.stderr.close()
-    # return buf.strip() if buf else None # Python v2.5+
-    if buf:
-        return buf.strip()
-    else:
-        return None
+    return buf.strip() if buf else None
 
 
 ######################################################################