本文整理汇总了Python中console.Console.run方法的典型用法代码示例。如果您正苦于以下问题:Python Console.run方法的具体用法?Python Console.run怎么用?Python Console.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类console.Console
的用法示例。
在下文中一共展示了Console.run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: explore
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
def explore(fpath):
_, ext = splitext(fpath)
ftype = 'data' if ext in ('.h5', '.hdf5') else 'simulation'
print("Using {} file: '{}'".format(ftype, fpath))
if ftype == 'data':
globals_def, entities = entities_from_h5(fpath)
simulation = Simulation(globals_def, None, None, None, None,
entities.values(), 'h5', fpath, None)
period, entity_name = None, None
else:
simulation = Simulation.from_yaml(fpath)
# use output as input
simulation.data_source = H5Source(simulation.data_sink.output_path)
period = simulation.start_period + simulation.periods - 1
entity_name = simulation.default_entity
dataset = simulation.load()
data_source = simulation.data_source
data_source.as_fake_output(dataset, simulation.entities_map)
data_sink = simulation.data_sink
entities = simulation.entities_map
if entity_name is None and len(entities) == 1:
entity_name = entities.keys()[0]
if period is None and entity_name is not None:
entity = entities[entity_name]
period = max(entity.output_index.keys())
eval_ctx = EvaluationContext(simulation, entities, dataset['globals'],
period, entity_name)
try:
c = Console(eval_ctx)
c.run()
finally:
data_source.close()
if data_sink is not None:
data_sink.close()
示例2: explore
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
def explore(fpath):
_, ext = splitext(fpath)
ftype = 'data' if ext in ('.h5', '.hdf5') else 'simulation'
print("Using %s file: '%s'" % (ftype, fpath))
if ftype == 'data':
globals_def, entities = entities_from_h5(fpath)
data_source = H5Data(None, fpath)
h5in, _, globals_data = data_source.load(globals_def, entities)
h5out = None
simulation = Simulation(globals_def, None, None, None, None,
entities.values(), None)
period, entity_name = None, None
else:
simulation = Simulation.from_yaml(fpath)
h5in, h5out, globals_data = simulation.load()
period = simulation.start_period + simulation.periods - 1
entity_name = simulation.default_entity
entities = simulation.entities_map
if entity_name is None and len(entities) == 1:
entity_name = entities.keys()[0]
if period is None and entity_name is not None:
entity = entities[entity_name]
period = max(entity.output_index.keys())
eval_ctx = EvaluationContext(simulation, entities, globals_data, period,
entity_name)
try:
c = Console(eval_ctx)
c.run()
finally:
h5in.close()
if h5out is not None:
h5out.close()
示例3: __init__
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
class Sandy:
_settings = {}
def __init__(self):
self.console = Console()
def start_console(self):
self.console.run()
示例4: explore
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
def explore(fpath):
_, ext = splitext(fpath)
ftype = 'data' if ext in ('.h5', '.hdf5') else 'simulation'
print "Using %s file: '%s'" % (ftype, fpath)
if ftype == 'data':
h5in = populate_registry(fpath)
h5out = None
entity, period = None, None
else:
simulation = Simulation.from_yaml(fpath)
h5in, h5out, periodic_globals = simulation.load()
ent_name = simulation.default_entity
entity = entity_registry[ent_name] if ent_name is not None else None
period = simulation.start_period + simulation.periods - 1
try:
c = Console(entity, period)
c.run()
finally:
h5in.close()
if h5out is not None:
h5out.close()
示例5: explore
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
def explore(fpath):
_, ext = splitext(fpath)
ftype = 'data' if ext in ('.h5', '.hdf5') else 'simulation'
print("Using %s file: '%s'" % (ftype, fpath))
if ftype == 'data':
globals_def = populate_registry(fpath)
data_source = H5Data(None, fpath)
h5in, _, globals_data = data_source.load(globals_def,
registry.entity_registry)
h5out = None
entity, period = None, None
else:
simulation = Simulation.from_yaml(fpath)
h5in, h5out, globals_data = simulation.load()
entity = simulation.console_entity
period = simulation.start_period + simulation.periods - 1
globals_def = simulation.globals_def
try:
c = Console(entity, period, globals_def, globals_data)
c.run()
finally:
h5in.close()
if h5out is not None:
h5out.close()
示例6: __init__
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
class Deploy:
def __init__(self):
self.config = Conf()
self.console = Console()
def path(self, option):
path = self.config.get(option)
return os.path.abspath(path);
def chown(self, path):
user = self.config.get('deploy_user')
self.console.run(['chown', '-R', user, path])
def linkdir(self, src, dst):
self.console.run(['ln', '-sfn', src, dst])
def version(self, deploy_path):
hash = self.console.run(['git', 'rev-parse', 'HEAD'], cwd=deploy_path);
return hash[0:8]
def hostname(self):
hostname = self.console.run(['hostname', '-f'], output=False);
return hostname
def sync(self, src, dst):
if os.path.exists(src) == False:
os.makedirs(src, 0755)
self.console.run([
'rsync',
'--links',
'--checksum',
'--whole-file',
'--recursive',
src.rstrip('/') + '/',
dst
])
def checkout(self):
deploy_path = self.path('release_path') + '/' + time.strftime('%Y%m%d%H%M%S')
if os.path.exists(deploy_path) == False:
os.makedirs(deploy_path, 0755)
gitclone = ' '.join([
'git',
'clone',
'--quiet',
'--recursive',
'--depth', '1',
'--branch', self.config.get('repo_branch'),
self.config.get('repo_url'),
deploy_path
])
sshadd = ' '.join([
'ssh-add',
self.config.get('deploy_key')
])
self.console.success('Fetching files')
self.console.execute('ssh-agent sh -c \'' + sshadd + '; ' + gitclone + '\'')
return deploy_path
def composer(self, deploy_path):
if os.path.exists(deploy_path + '/composer.json') == False:
return None
self.console.success('Installing composer dependencies')
self.console.run([
'composer',
'--quiet',
'--no-interaction',
'install',
'--prefer-dist',
'--no-dev',
'--optimize-autoloader'
], cwd=deploy_path);
def scripts(self, scripts_to_run, deploy_path):
if self.config.has(scripts_to_run) == False:
return
scripts = self.config.get(scripts_to_run)
for line in scripts:
command = line.replace('$deploy_path', deploy_path)
command = command.replace('$repo_branch', self.config.get('repo_branch'))
command = command.replace('$repo_url', self.config.get('repo_url'))
command = command.replace('$hostname', self.hostname())
self.console.run(shlex.split(command), cwd=deploy_path)
def clean(self):
release_path = self.path('release_path')
deployments = self.console.run(['ls', '-1tA', release_path])
deploys_to_keep = int(self.config.get('deploys_to_keep'))
for folder in deployments.splitlines()[deploys_to_keep:]:
#.........这里部分代码省略.........
示例7: AndroidPlugin
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import run [as 别名]
class AndroidPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "GeditAndroidPlugin"
window = GObject.property(type=Gedit.Window)
def __init__(self):
GObject.Object.__init__(self)
self._ui_merge_id = None
self._console = None
self._project = None
def _add_console(self):
""" Adds a widget to the bottom pane for command output. """
self._console = Console()
self._console.set_font(self._settings.get_string("console-font"))
panel = self.window.get_bottom_panel()
panel.add_item_with_stock_icon(self._console, "AndroidConsole",
"Console", STOCK_CONSOLE)
def _add_ui(self):
""" Merge the 'Android' menu into the gedit menubar. """
ui_file = os.path.join(DATA_DIR, 'menu.ui')
manager = self.window.get_ui_manager()
# global actions are always sensitive
self._global_actions = Gtk.ActionGroup("AndroidGlobal")
self._global_actions.add_actions([
('Android', None, "_Android", None, None, None),
('AndroidNewProject', Gtk.STOCK_NEW, "_New Project...",
"<Shift><Control>N", "Start a new Android project.",
self.on_new_project_activate),
('AndroidOpenProject', Gtk.STOCK_OPEN, "_Open Project",
"<Shift><Control>O", "Open an existing Android project.",
self.on_open_project_activate),
('AndroidSdk', STOCK_SDK, "Android _SDK Manager",
None, "Launch the Android SDK manager.",
self.on_android_sdk_activate),
('AndroidAvdManager', STOCK_AVD, "_AVD Manager",
None, "Launch the Android AVD manager.",
self.on_android_avd_manager_activate),
])
manager.insert_action_group(self._global_actions)
# project actions are sensitive when a project is open
self._project_actions = Gtk.ActionGroup("AndroidProject")
self._project_actions.add_actions([
('AndroidCloseProject', Gtk.STOCK_CLOSE, "_Close Project...",
"", "Close the current Android project.",
self.on_close_project_activate),
('AndroidRun', None, "_Run...",
"", "Run the current project in debug mode.",
self.on_run_activate),
])
self._project_actions.set_sensitive(False)
manager.insert_action_group(self._project_actions)
self._ui_merge_id = manager.add_ui_from_file(ui_file)
manager.ensure_update()
def build_project(self, mode="debug"):
try:
self._console.run("%s %s" %
(self._settings.get_string("ant-command"), mode),
self._project.get_path())
except Exception as e:
self.error_dialog(str(e))
def close_project(self):
self._project = None
self._project_actions.set_sensitive(False)
def do_activate(self):
""" Plugin activates at startup and/or gedit preferences. """
# make sure we can use settings
schemas = Gio.Settings.list_schemas()
if not SETTINGS_SCHEMA in schemas:
self.error_dialog("Could not find settings schema:\n %s" % SETTINGS_SCHEMA)
return
self._settings = Gio.Settings.new(SETTINGS_SCHEMA)
self._install_stock_icons()
self._add_ui()
self._add_console()
def do_deactivate(self):
""" Plugin deactivates at startup and/or gedit preferences. """
self._settings = None
self._remove_ui()
self._remove_console()
def do_update_state(self):
pass
def error_dialog(self, message):
""" Display a very basic error dialog. """
logger.warn(message)
dialog = Gtk.MessageDialog(self.window,
Gtk.DialogFlags.MODAL |
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
#.........这里部分代码省略.........