Edgewall Software

Ticket #3532: trac-admin-wiki-import-stdin-4297-trunk.diff

File trac-admin-wiki-import-stdin-4297-trunk.diff, 1.3 KB (added by sid, 2 years ago)

Patch that adds ability to import wiki page from stdin

  • trac/admin/console.py

     
    673673            self._do_wiki_remove(name) 
    674674        elif arg[0] == 'import' and len(arg) == 3: 
    675675            title = arg[1] 
    676             file = arg[2] 
     676            file = (len(arg) == 3 and arg[2]) or None 
    677677            self._do_wiki_import(file, title) 
    678678        elif arg[0] == 'export'  and len(arg) in [2,3]: 
    679679            page = arg[1] 
     
    705705 
    706706    def _do_wiki_import(self, filename, title, cursor=None, 
    707707                        create_only=[]): 
    708         if not os.path.isfile(filename): 
    709             raise Exception, '%s is not a file' % filename 
     708        if not filename: 
     709            data = to_unicode(sys.stdin.readlines(), 'utf-8') 
     710        else: 
     711            if not os.path.isfile(filename): 
     712                raise Exception, '%s is not a file' % filename 
     713            f = open(filename,'r') 
     714            data = to_unicode(f.read(), 'utf-8') 
    710715 
    711         f = open(filename,'r') 
    712         data = to_unicode(f.read(), 'utf-8') 
    713  
    714716        # Make sure we don't insert the exact same page twice 
    715717        rows = self.db_query("SELECT text FROM wiki WHERE name=%s " 
    716718                             "ORDER BY version DESC LIMIT 1", cursor,