本文整理匯總了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()}