def explain(section, program): s = store.store('explainshell', config.MONGO_URI) try: if 'args' in request.args: args = request.args['args'] command = '%s %s' % (program, args) matcher_ = matcher.matcher(command, s, section) mrs = matcher_.match() mr = mrs[0][1] l = [] it = util.peekable(iter(mr)) while it.hasnext(): m = it.next() spaces = 0 if it.hasnext(): spaces = it.peek().start - m.end spaces = ' ' * spaces text = m.text if text: text = text.decode('utf-8') d = { 'match': m.match, 'unknown': m.unknown, 'text': text, 'spaces': spaces } l.append(d) d = l[0] d['section'] = matcher_.manpage.section d['match'] = '%s(%s)' % (d['match'], d['section']) d['source'] = matcher_.manpage.source[:-5] others = helpers.others([x[0] for x in mrs[1:]]) return render_template('explain.html', program=l[0], matches=l, othersections=others, getargs=args) else: logger.info('/explain section=%r program=%r', section, program) mps = s.findmanpage(program, section) mp = mps.pop(0) program = mp.namesection mp = { 'source': mp.source[:-3], 'section': mp.section, 'program': program, 'synopsis': mp.synopsis, 'options': [o.text.decode('utf-8') for o in mp.options] } othersections = helpers.others(mps) logger.info('others: %s', othersections) return render_template('options.html', mp=mp, othersections=helpers.others(mps)) except errors.ProgramDoesNotExist, e: return render_template('error.html', prog=e.args[0])
def main(files, dbname, dbhost, overwrite, drop, verify): if verify: s = store.store(dbname, dbhost) ok = s.verify() return 0 if ok else 1 if drop: if input('really drop db (y/n)? ').strip().lower() != 'y': drop = False else: overwrite = True # if we drop, no need to take overwrite into account gzs = set() for path in files: if os.path.isdir(path): gzs.update([os.path.abspath(f) for f in glob.glob(os.path.join(path, '*.gz'))]) else: gzs.add(os.path.abspath(path)) m = manager(dbhost, dbname, gzs, overwrite, drop) added, exists = m.run() for mp in added: print('successfully added %s' % mp.source) if exists: print('these manpages already existed and werent overwritten: \n\n%s' % '\n'.join([m.path for m in exists]))
def main(files, dbname, dbhost, overwrite, drop, verify): if verify: s = store.store(dbname, dbhost) ok = s.verify() return 0 if ok else 1 if drop: if raw_input('really drop db (y/n)? ').strip().lower() != 'y': drop = False else: overwrite = True # if we drop, no need to take overwrite into account gzs = set() for path in files: if os.path.isdir(path): gzs.update([os.path.abspath(f) for f in glob.glob(os.path.join(path, '*.gz'))]) else: gzs.add(os.path.abspath(path)) m = manager(dbhost, dbname, gzs, overwrite, drop) added, exists = m.run() for mp in added: print 'successfully added %s' % mp.source if exists: print 'these manpages already existed and werent overwritten: \n\n%s' % '\n'.join([m.path for m in exists])
def explain(): if 'cmd' not in request.args or not request.args['cmd'].strip(): return {'status': 'nocommand'} command = request.args['cmd'].strip() command = command[:1000] # trim commands longer than 1000 characters if '\n' in command: return { 'status': 'error', 'title': 'parsing error!', 'message': 'no newlines please' } s = store.store('explainshell', config.MONGO_URI) try: matches, helptext = explaincommand(command, s) return { 'status': 'success', 'matches': matches, 'helptext': helptext, 'getargs': command } except errors.ProgramDoesNotExist, e: return { 'status': 'missingmanpage', 'e': e, 'title': 'missing man page' }
def main(progs, manpagedir, dbname, dbhost, limit, skip, overwrite, drop, verify): if verify: s = store.store(dbname, dbhost) ok = s.verify() return 0 if ok else 1 if drop: if raw_input('really drop db (y/n)? ').strip().lower() != 'y': drop = False else: overwrite = True # if we drop, no need to take overwrite into account gzs = sorted(glob.glob(os.path.join(manpagedir, '*', '*.gz'))) if limit <= 0: limit = len(gzs) else: limit += skip if progs: progs = set(progs) gzs = [gz for gz in gzs if manpage.extractname(gz) in progs][skip:limit] else: gzs = gzs[skip:limit] m = manager(dbhost, dbname, gzs, overwrite, drop) added, exists = m.run() for mp in added: print 'successfully added %s' % mp.name if exists: print 'these manpages already existed and werent overwritten: %s' % ', '.join( [m.name for m in exists])
def main(progs, manpagedir, dbname, dbhost, limit, skip, overwrite, drop, verify): if verify: s = store.store(dbname, dbhost) ok = s.verify() return 0 if ok else 1 if drop: if raw_input('really drop db (y/n)? ').strip().lower() != 'y': drop = False else: overwrite = True # if we drop, no need to take overwrite into account gzs = sorted(glob.glob(os.path.join(manpagedir, '*', '*.gz'))) if limit <= 0: limit = len(gzs) else: limit += skip if progs: progs = set(progs) gzs = [gz for gz in gzs if manpage.extractname(gz) in progs][skip:limit] else: gzs = gzs[skip:limit] m = manager(dbhost, dbname, gzs, overwrite, drop) added, exists = m.run() for mp in added: print 'successfully added %s' % mp.name if exists: print 'these manpages already existed and werent overwritten: %s' % ', '.join([m.name for m in exists])
def __init__(self, dbhost, dbname, paths, overwrite=False, drop=False): self.paths = paths self.overwrite = overwrite self.store = store.store(dbname, dbhost) self.classifier = classifier.classifier(self.store, 'bayes') self.classifier.train() if drop: self.store.drop(True)
def explain(): if 'cmd' not in request.args or not request.args['cmd'].strip(): return redirect('/') command = request.args['cmd'] command = command[:1000] # trim commands longer than 1000 characters s = store.store('explainshell', config.MONGO_URI) try: matches, helptext = explaincommand(command, s) return render_template('explain.html', matches=matches, helptext=helptext, getargs=command) except errors.ProgramDoesNotExist, e: return render_template('errors/missingmanpage.html', title='missing man page', e=e)
def explain(section, program): s = store.store('explainshell', config.MONGO_URI) try: if 'args' in request.args: args = request.args['args'] if program is None: program = args.split(' ')[0] args = ' '.join(args.split(' ')[1:]) command = '%s %s' % (program, args) matcher_ = matcher.matcher(command, s, section) mrs = matcher_.match() mr = mrs[0][1] l = [] it = util.peekable(iter(mr)) while it.hasnext(): m = it.next() spaces = 0 if it.hasnext(): spaces = it.peek().start - m.end spaces = ' ' * spaces text = m.text if text: text = text.decode('utf-8') d = {'match' : m.match, 'unknown' : m.unknown, 'text' : text, 'spaces' : spaces} l.append(d) d = l[0] d['section'] = matcher_.manpage.section d['match'] = '%s(%s)' % (d['match'], d['section']) d['source'] = matcher_.manpage.source[:-5] others = helpers.others([x[0] for x in mrs[1:]]) return render_template('explain.html', program=l[0], matches=l, othersections=others, getargs=args) else: logger.info('/explain section=%r program=%r', section, program) mps = s.findmanpage(program, section) mp = mps.pop(0) program = mp.namesection mp = {'source' : mp.source[:-3], 'section' : mp.section, 'program' : program, 'synopsis' : mp.synopsis, 'options' : [o.text.decode('utf-8') for o in mp.options]} othersections = helpers.others(mps) logger.info('others: %s', othersections) return render_template('options.html', mp=mp, othersections=helpers.others(mps)) except errors.ProgramDoesNotExist, e: return render_template('error.html', prog=e.args[0])
def debug(): s = store.store('explainshell', config.MONGO_URI) d = {'manpages' : []} for mp in s: synopsis = '' if mp.synopsis: synopsis = mp.synopsis[:20] dd = {'name' : mp.name, 'synopsis' : synopsis} l = [] for o in mp.options: l.append(str(o)) dd['options'] = ', '.join(l) d['manpages'].append(dd) d['manpages'].sort(key=lambda d: d['name'].lower()) return render_template('debug.html', d=d)
def debug(): s = store.store('explainshell', config.MONGO_URI) d = {'manpages': []} for mp in s: synopsis = '' if mp.synopsis: synopsis = mp.synopsis[:20] dd = {'name': mp.name, 'synopsis': synopsis} l = [] for o in mp.options: l.append(str(o)) dd['options'] = ', '.join(l) d['manpages'].append(dd) d['manpages'].sort(key=lambda d: d['name'].lower()) return render_template('debug.html', d=d)
def explain(): if 'cmd' not in request.args or not request.args['cmd'].strip(): return redirect('/') command = request.args['cmd'].strip() command = command[:1000] # trim commands longer than 1000 characters s = store.store('explainshell', config.MONGO_URI) try: matches, helptext = explaincommand(command, s) return render_template('explain.html', matches=matches, helptext=helptext, getargs=command) except errors.ProgramDoesNotExist, e: return render_template('errors/missingmanpage.html', title='missing man page', e=e)
def explain(): if 'cmd' not in request.args or not request.args['cmd'].strip(): return redirect('/') command = request.args['cmd'].strip() command = command[:1000] # trim commands longer than 1000 characters if '\n' in command: return render_template('errors/error.html', title='parsing error!', message='no newlines please') s = store.store('explainshell', config.MONGO_URI) try: matches, helptext = explaincommand(command, s) return render_template('explain.html', matches=matches, helptext=helptext, getargs=command) except errors.ProgramDoesNotExist as e: return render_template('errors/missingmanpage.html', title='missing man page', e=e) except bashlex.errors.ParsingError as e: logger.warn('%r parsing error: %s', command, e.message) return render_template('errors/parsingerror.html', title='parsing error!', e=e) except NotImplementedError as e: logger.warn('not implemented error trying to explain %r', command) msg = ( "the parser doesn't support %r constructs in the command you tried. you may " "<a href='https://github.com/idank/explainshell/issues'>report a " "bug</a> to have this added, if one doesn't already exist." ) % e.args[0] return render_template('errors/error.html', title='error!', message=msg) except: logger.error('uncaught exception trying to explain %r', command, exc_info=True) msg = 'something went wrong... this was logged and will be checked' return render_template('errors/error.html', title='error!', message=msg)
def explainold(section, program): logger.info('/explain section=%r program=%r', section, program) s = store.store('explainshell', config.MONGO_URI) if section is not None: program = '%s.%s' % (program, section) if 'args' in request.args: args = request.args['args'] command = '%s %s' % (program, args) return redirect('/explain?cmd=%s' % urllib.quote_plus(command), 301) else: try: mp, suggestions = explainprogram(program, s) return render_template('options.html', mp=mp, suggestions=suggestions) except errors.ProgramDoesNotExist, e: return render_template('errors/missingmanpage.html', title='missing man page', e=e)
def explainold(section, program): logger.info('/explain section=%r program=%r', section, program) s = store.store('explainshell', config.MONGO_URI) if section is not None: program = '%s.%s' % (program, section) # keep links to old urls alive if 'args' in request.args: args = request.args['args'] command = '%s %s' % (program, args) return redirect('/explain?cmd=%s' % urllib.quote_plus(command), 301) else: try: mp, suggestions = explainprogram(program, s) return render_template('options.html', mp=mp, suggestions=suggestions) except errors.ProgramDoesNotExist, e: return render_template('errors/missingmanpage.html', title='missing man page', e=e)
def setUp(self): store.store('explainshell_tests').drop(True)
<b>history</b> <b>-p</b> <u>arg</u> [<u>arg</u> <u>...</u>] <b>history</b> <b>-s</b> <u>arg</u> [<u>arg</u> <u>...</u>] With no options, display the command history list with line numbers. Lines listed with a <b>*</b> have been modified. An argument of <u>n</u> lists only the last <u>n</u> lines. If the shell variable <b>HISTTIMEFORMAT</b> is set and not null, it is used as a format string for <u>strftime</u>(3) to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. If <u>filename</u> is supplied, it is used as the name of the history file; if not, the value of <b>HISTFILE</b> is used.''', '', True), [], [], False, True, False), so(sp(1, '<b>-c</b> Clear the history list by deleting all the entries.', '', True), ['-c'], [], False, False, False), so(sp(2, textwrap.dedent(''' <b>-d</b> <u>offset</u> Delete the history entry at position <u>offset</u>.'''), '', True), ['-d'], [], 'offset', False, False), so(sp(3, textwrap.dedent(''' <b>-a</b> Append the ``new'' history lines (history lines entered since the beginning of the current <b>bash</b> session) to the history file.'''), '', True), ['-a'], [], False, False, False), so(sp(4, textwrap.dedent(''' <b>-n</b> Read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the beginning of the current <b>bash</b> session.'''), '', True), ['-n'], [], False, False, False), so(sp(5, textwrap.dedent(''' <b>-r</b> Read the contents of the history file and append them to the current history list.'''), '', True), ['-r'], [], False, False, False), so(sp(6, textwrap.dedent(''' <b>-w</b> Write the current history list to the history file, overwriting the history file's contents.'''), '', True), ['-w'], [], 'filename', False, False), so(sp(7, textwrap.dedent(''' <b>-p</b> Perform history substitution on the following <u>args</u> and display the result on the standard output. Does not store the results in the history list. Each <u>arg</u> must be quoted to disable normal history expansion.'''), '', True), ['-p'], [], 'arg', True, False), so(sp(8, textwrap.dedent(''' <b>-s</b> Store the <u>args</u> in the history list as a single entry. The last command in the history list is removed before the <u>args</u> are added.'''), '', True), ['-s'], [], 'arg', False, False)]) if __name__ == '__main__': import logging.config logging.config.dictConfig(config.LOGGING_DICT) s = store.store('explainshell', config.MONGO_URI) for m in BUILTINS.itervalues(): s.addmanpage(m)
), '', True), ['-r'], [], False, False, False), so( sp( 6, textwrap.dedent( ''' <b>-w</b> Write the current history list to the history file, overwriting the history file's contents.''' ), '', True), ['-w'], [], 'filename', False, False), so( sp( 7, textwrap.dedent( ''' <b>-p</b> Perform history substitution on the following <u>args</u> and display the result on the standard output. Does not store the results in the history list. Each <u>arg</u> must be quoted to disable normal history expansion.''' ), '', True), ['-p'], [], 'arg', True, False), so( sp( 8, textwrap.dedent( ''' <b>-s</b> Store the <u>args</u> in the history list as a single entry. The last command in the history list is removed before the <u>args</u> are added.'''), '', True), ['-s'], [], 'arg', False, False) ]) if __name__ == '__main__': import logging.config logging.config.dictConfig(config.LOGGING_DICT) s = store.store('explainshell', config.MONGO_URI) for m in BUILTINS.itervalues(): s.addmanpage(m)