本文整理汇总了Python中Formatter.get_width方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.get_width方法的具体用法?Python Formatter.get_width怎么用?Python Formatter.get_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter.get_width方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: man
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import get_width [as 别名]
def man(self, pattern):
"""Call viewer.sh to view man page"""
try:
os.makedirs(Environ.man_dir)
except:
pass
avail = os.listdir(Environ.man_dir)
if not os.path.exists(Environ.index_db):
raise RuntimeError("can't find index.db")
conn = sqlite3.connect(Environ.index_db)
cursor = conn.cursor()
# Try direct match
try:
page_name, url = cursor.execute(
"SELECT name,url FROM CPPMAN WHERE" ' name="%s" ORDER BY LENGTH(name)' % pattern
).fetchone()
except TypeError:
# Try standard library
try:
page_name, url = cursor.execute(
"SELECT name,url FROM CPPMAN" ' WHERE name="std::%s" ORDER BY LENGTH(name)' % pattern
).fetchone()
except TypeError:
try:
page_name, url = cursor.execute(
"SELECT name,url FROM " 'CPPMAN WHERE name LIKE "%%%s%%" ORDER BY LENGTH(name)' % pattern
).fetchone()
except TypeError:
raise RuntimeError("No manual entry for " + pattern)
finally:
conn.close()
page_name = page_name.replace("/", "_")
if page_name + ".3.gz" not in avail or self.forced:
self.cache_man_page(url, page_name)
self.update_mandb()
pager = Environ.pager if sys.stdout.isatty() else Environ.renderer
# Call viewer
pid = os.fork()
if pid == 0:
os.execl(
"/bin/sh",
"/bin/sh",
pager,
Environ.man_dir + page_name + ".3.gz",
str(Formatter.get_width()),
Environ.pager_config,
page_name,
)
return pid
示例2: man
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import get_width [as 别名]
def man(self, pattern):
"""Call viewer.sh to view man page"""
try:
os.makedirs(Environ.man_dir)
except: pass
avail = os.listdir(Environ.man_dir)
if not os.path.exists(Environ.index_db):
raise RuntimeError("can't find index.db")
conn = sqlite3.connect(Environ.index_db)
cursor = conn.cursor()
# Try direct match
try:
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN WHERE'
' name="%s" ORDER BY LENGTH(name)' % pattern).fetchone()
except TypeError:
# Try standard library
try:
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN'
' WHERE name="std::%s" ORDER BY LENGTH(name)'
% pattern).fetchone()
except TypeError:
try:
page_name, url = cursor.execute('SELECT name,url FROM '
'CPPMAN WHERE name LIKE "%%%s%%" ORDER BY LENGTH(name)'
% pattern).fetchone()
except TypeError:
raise RuntimeError('No manual entry for ' + pattern)
finally:
conn.close()
page_name = page_name.replace('/', '_')
#if page_name + '.3.gz' not in avail or self.forced:
#self.cache_man_page(url, page_name)
#self.update_mandb()
pager = Environ.pager if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() else Environ.renderer
# Call viewer
#pid = os.fork()
#if pid == 0:
#out = os.execl('/bin/sh', '/bin/sh', pager,
#page_name + '.3.gz',
#str(Formatter.get_width()), Environ.pager_config,
#page_name)
p = subprocess.Popen([pager, page_name + '.3.gz', str(Formatter.get_width()), Environ.pager_config, page_name], stdout=subprocess.PIPE)
return {'page':page_name, 'out':p.stdout.read()}