Commits

Friedrich Kastner-Masilko  committed d212229

Added "all" feature to makewritable extension

  • Participants
  • Parent commits abe92fc

Comments (0)

Files changed (1)

File makewritable.py

             s = os.stat(f)
             if (s.st_mode & stat.S_IWRITE) == 0:
                 frame=sys._getframe(1)
-                this=ui.ui(frame.f_globals['ui'])
-
-                query = _('make \'%s\' writable?') % f                                
-                invalid = True
-                while invalid:
-                    r = (this.prompt(query + _(' [Yna?] '), '(?i)[Yna?]?$') or 'y').lower()
-                    if r == '?':
-                        c = opener.__doc__.find('y - make the file writable')
-                        for l in opener.__doc__[c:].splitlines():
-                            if l: this.write(_(l.strip()), '\n')
-                        continue
-                    elif r == 'y':
-                        os.chmod(f, s.st_mode | stat.S_IWRITE)
-                        invalid = False
-                    elif r == 'n':
-                        invalid = False
-                    elif r == 'a':
-                        os.chmod(f, s.st_mode | stat.S_IWRITE)
-                        invalid = False
-                    else:
-                        this.write('%s not supported.\n' % r[0])
-                    
-                
+                currentUi=ui.ui(frame.f_globals['ui'])
+                if self.makewritable:
+                    os.chmod(f, s.st_mode | stat.S_IWRITE)
+                    currentUi.status(_('made \'%s\' writable\n') % f)
+                else:
+                    while True:
+                        r = (currentUi.prompt(_('make \'%s\' writable?') % f + _(' [Yna?] '), '(?i)[Yna?]?$') or 'y').lower()
+                        if r == '?':
+                            c = opener.__doc__.find('y - make the file writable')
+                            for l in opener.__doc__[c:].splitlines():
+                                if l: currentUi.write(_(l.strip()), '\n')
+                            continue
+                        elif r == 'y':
+                            os.chmod(f, s.st_mode | stat.S_IWRITE)
+                            break
+                        elif r == 'n':
+                            break
+                        elif r == 'a':
+                            os.chmod(f, s.st_mode | stat.S_IWRITE)
+                            self.makewritable = True;
+                            break
     return util.opener.makewritable_origopener(self, path, mode, text, atomictemp)
 
 util.opener.makewritable_origopener = util.opener.__call__
 util.opener.__call__ = opener
+util.opener.makewritable = False