def token(self, CODE=''):
client, url = self.getCODE()
if not self.checked:
if CODE == '':
is_open = webbrowser.open_new(url)
if not is_open:
LOG.info(_("Please use the browser to open %(url)s"),
{'url': url})
try:
# for python2.x
CODE = raw_input(_("Please Input the Code: ")).strip()
except:
# for python3.x
CODE = input(_("Please Input the Code: ")).strip()
try:
client.set_code(CODE)
except:
LOG.error(_("Maybe wrong CODE"))
return
token = client.token
pkl.dump(token, open(str(self.token_file), 'wb'))
self.api = Client(self.app_key,
self.app_secret,
self.callback_url, token)
self.checked = True
python类open_new()的实例源码
def token(self, CODE=''):
client, url = self.getCODE()
if self.checked == False:
if CODE == '':
import pdb;pdb.set_trace()
is_open = webbrowser.open_new(url)
if not is_open:
print('Please open %s' % url)
try:
# for python2.x
CODE = raw_input("Please Input the Code: ").strip()
except:
# for python3.x
CODE = input("Please Input the Code: ").strip()
try:
client.set_code(CODE)
except:
print("Maybe wrong CODE")
return
token = client.token
pkl.dump(token, open(str(self.token_file), 'wb'))
self.api = Client(self.APP_KEY, self.APP_SECRET, self.CALLBACK_URL, token)
self.checked = True
def handle_unexpected_errors(f):
"""Decorator that catches unexpected errors."""
@wraps(f)
def call_f(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
errorf = StringIO()
print_exc(file=errorf)
error = errorf.getvalue()
click.echo(
"Looks like there's a bug in our code. Sorry about that!"
" Here's the traceback:\n" + error)
if click.confirm(
"Would you like to file an issue in our issue tracker?",
default=True, abort=True):
url = "https://github.com/datawire/pib/issues/new?body="
body = quote_plus(BUG_REPORT_TEMPLATE.format(
os.getcwd(), __version__, python_version,
run_result(["uname", "-a"]), error))
webbrowser.open_new(url + body)
return call_f
def _request_refresh_token(self):
# create configuration file dir
config_dir = os.path.dirname(self._config_path)
if not os.path.isdir(config_dir):
os.makedirs(config_dir)
# open browser and ask for authorization
auth_request_url = gdal.GOA2GetAuthorizationURL(self._scope)
print('Authorize access to your Fusion Tables, and paste the resulting code below: ' + auth_request_url)
# webbrowser.open_new(auth_request_url)
auth_code = raw_input('Please enter authorization code: ').strip()
refresh_token = gdal.GOA2GetRefreshToken(auth_code, self._scope)
# save it
json.dump({'refresh_token': refresh_token}, open(self._config_path, 'w'))
return refresh_token
def click(self, link):
path = gitPath(self.view.window())
command = ("cd '{0}';git show {1}").format(path, link)
stdout, _ = run_bash_for_output(command)
window = self.view.window()
results_view = window.new_file()
results_view.set_scratch(True)
results_view.set_syntax_file('Packages/Diff/Diff.tmLanguage')
results_view.set_name('GitBlame')
# deps: this is from utilities.py
results_view.run_command('replace_content', {"new_content": stdout})
results_view.sel().clear()
results_view.sel().add(sublime.Region(0, 0))
window.focus_view(results_view)
"""for line in lines:
matches = re.search(r'Differential Revision: (http.*/D[0-9]+)', line)
if matches is not None:
actual_link = matches.group(1)
webbrowser.open_new(actual_link)"""
def run(self, unused_args, unused_config):
"""Generates and opens a URL to get auth code, then retrieve a token."""
auth_url = ee.oauth.get_authorization_url()
webbrowser.open_new(auth_url)
print("""
Opening web browser to address %s
Please authorize access to your Earth Engine account, and paste
the resulting code below.
If the web browser does not start, please manually browse the URL above.
""" % auth_url)
auth_code = input('Please enter authorization code: ').strip()
token = ee.oauth.request_token(auth_code)
ee.oauth.write_token(token)
print('\nSuccessfully saved authorization token.')
def plot(self, dataset, path, show=False):
with PdfPages(path) as pdf:
x_vals = dataset.data['T'].tolist()
y_vals = dataset.data[self.symbol].tolist()
plt.plot(x_vals, y_vals, 'ro', alpha=0.4, markersize=4)
x_vals2 = np.linspace(min(x_vals), max(x_vals), 80)
fx = np.polyval(self._coeffs, x_vals2)
plt.plot(x_vals2, fx, linewidth=0.3, label='')
plt.ticklabel_format(axis='y', style='sci', scilimits=(0, 4))
plt.legend(loc=3, bbox_to_anchor=(0, 0.8))
plt.title('$%s$ vs $T$' % self.display_symbol)
plt.xlabel('$T$ (K)')
plt.ylabel('$%s$ (%s)' % (self.display_symbol, self.units))
fig = plt.gcf()
pdf.savefig(fig)
plt.close()
if show:
webbrowser.open_new(path)
def run(self, unused_args, unused_config):
"""Generates and opens a URL to get auth code, then retrieve a token."""
auth_url = ee.oauth.get_authorization_url()
webbrowser.open_new(auth_url)
print """
Opening web browser to address %s
Please authorize access to your Earth Engine account, and paste
the resulting code below.
If the web browser does not start, please manually browse the URL above.
""" % auth_url
auth_code = raw_input('Please enter authorization code: ').strip()
token = ee.oauth.request_token(auth_code)
ee.oauth.write_token(token)
print '\nSuccessfully saved authorization token.'
def __menu (self) :
menubar = Tkinter.Menu(self.master)
fileMenu = Tkinter.Menu(menubar, tearoff = 0)
fileMenu.add_command(label = "Config", command = self.__configPanel)
fileMenu.add_command(label = "Close", command = self.master.quit)
menubar.add_cascade(label = "File", menu = fileMenu)
aboutMenu = Tkinter.Menu(menubar, tearoff = 0)
aboutMenu.add_command(label = "Info", command = self.__showInfo)
aboutMenu.add_command(label = "Check Update", command = self.__chkUpdate)
menubar.add_cascade(label = "About", menu = aboutMenu)
helpMenu = Tkinter.Menu(menubar, tearoff = 0)
helpMenu.add_command(label = "GitHub", command = lambda target = self.gitUrl : webbrowser.open_new(target))
helpMenu.add_command(label = "Release Notes", command = lambda target = self.appUrl : webbrowser.open_new(target))
helpMenu.add_command(label = "Send Feedback", command = lambda target = self.feedUrl : webbrowser.open_new(target))
menubar.add_cascade(label = "Help", menu = helpMenu)
self.master.config(menu = menubar)
def run(self, unused_args, unused_config):
"""Generates and opens a URL to get auth code, then retrieve a token."""
auth_url = ee.oauth.get_authorization_url()
webbrowser.open_new(auth_url)
print("""
Opening web browser to address %s
Please authorize access to your Earth Engine account, and paste
the resulting code below.
If the web browser does not start, please manually browse the URL above.
""" % auth_url)
auth_code = input('Please enter authorization code: ').strip()
token = ee.oauth.request_token(auth_code)
ee.oauth.write_token(token)
print('\nSuccessfully saved authorization token.')
def run(self, unused_args, unused_config):
"""Generates and opens a URL to get auth code, then retrieve a token."""
auth_url = ee.oauth.get_authorization_url()
webbrowser.open_new(auth_url)
print """
Opening web browser to address %s
Please authorize access to your Earth Engine account, and paste
the resulting code below.
If the web browser does not start, please manually browse the URL above.
""" % auth_url
auth_code = raw_input('Please enter authorization code: ').strip()
token = ee.oauth.request_token(auth_code)
ee.oauth.write_token(token)
print '\nSuccessfully saved authorization token.'
create_eb_vpc_with_ec2_api.py 文件源码
项目:eb-deployment-boto-scripts
作者: coaic
项目源码
文件源码
阅读 82
收藏 0
点赞 0
评论 0
def create_elastic_filesystem(region, vpc_id, private_subnets, security_group_id):
print("""
As Elastic File System is a relatively new service, API support is far from complete. You will need to create the file system
in the AWS EFS Console. A browser window will open for you to create the file system. Several prompts from this script will
guide you through the process.
You will need to be already logged into the AWS Console on your browser.
Ensure you select all listed availability zones.
""")
input("Ready to proceed? ")
input(" Please note the VPC Id: %s, you will need to select this from wizard when it opens in the browser - ok? " %(vpc_id))
input(" Please ensure you place this file system in the following subnets: %s - ok?" % (private_subnets))
input(" Please also ensure the following security group is selected, in addition to the default security group: %s - ok?" % (security_group_id))
webbrowser.open_new("https://%s.console.aws.amazon.com/efs/home?region=%s#/wizard/1" % (region, region))
mount_point = input("Once you have completed the wizard please paste the mount point from the browser at the prompt: ")
return mount_point
#
# Do VPC creation
#
def get_code(client_id):
"""
Opens a browser so the user can give us the auth code
Args:
client_id (str): client id for the app we want to use
Returns:
str: auth code user provided
"""
url = FITBIT_PERMISSION_SCREEN.format(
client_id=client_id,
scope='nutrition'
)
webbrowser.open_new(url)
print(
"I am attempting to get permission to run. "
"A browser should have just opened. If it has not please go to {}".format(
url
)
)
return input(
"A browser should have just opened: please provide the the text after 'code=' so I can continue: "
)
def open_url_in_help_browser(self, url):
print url
if self.settings.get_value('use_external_browser', False):
import webbrowser
webbrowser.open_new(url)
else:
browser = [x for x in hou.ui.paneTabs() if x.type() == hou.paneTabType.HelpBrowser]
if browser:
browser = browser[0]
else:
desktop = hou.ui.curDesktop()
browser = desktop.paneTabOfType(hou.paneTabType.HelpBrowser)
if browser is None:
browser = desktop.createFloatingPane(hou.paneTabType.HelpBrowser)
browser.setUrl(url)
browser.setIsCurrentTab()
QTimer.singleShot(200, self.focus_me)
def OnHelpEvent(self, event):
webbrowser.open_new(C_APP_SITE)
def callback():
webbrowser.open_new(r"http://www.google.com")
def display_help():
import webbrowser
webbrowser.open_new("http://www.flyninja.net/book/?p=30")
def callback_GitHub(event):
webbrowser.open_new(r"https://github.com/andb0t/Fuxenpruefung")
def callback_AGV(event):
webbrowser.open_new(r"http://agv-muenchen.de/")
def on_enter(self, *args):
super(ScreenWebView, self).on_enter(*args)
if platform == 'android':
''' on android create webview for webpage '''
self.ids["info_label"].text = "Please wait\nAttaching WebView"
self.webview_lock = True
Clock.schedule_once(self.create_webview, 0)
else:
''' on desktop just launch web browser '''
self.ids["info_label"].text = "Please wait\nLaunching browser"
import webbrowser
webbrowser.open_new(self.url)
def showItem(self):
current_row = self.listWidget.currentRow()
for i in range(current_row + 1):
if i == current_row:
url = self.staff_list[i].split(',')[1]
webbrowser.open_new(url)
#?????????
def token(self, CODE=''):
client, url = self.getCODE()
if self.checked == False:
if CODE == '':
webbrowser.open_new(url)
CODE = raw_input("Please Input the Code: ").strip()
try:
client.set_code(CODE)
except:
print "Maybe wrong CODE"
return
token = client.token
pkl.dump(token, file(self.token_file, 'w'))
self.api = Client(self.APP_KEY, self.APP_SECRET, self.CALLBACK_URL, token)
self.checked = True
def go_to_help(self, word):
"""
open browser and go to wiki page for control with type *word
"""
webbrowser.open_new(self.CONTROLS[word])
def authFunc(fd,q): # Opens the desired bookmark.
if q>=1 and q<=len(fd):
webbrowser.open_new(fd[q-1]["url"])
else:
print("Invalid input.")
q = int(input("Enter a valid result no. to be opened: "))
authFunc(fd,q)
def show_control_web(self, widget=None, data=None):
host_port = config.get(["modules", "launcher", "control_port"], 8085)
webbrowser.open_new("http://127.0.0.1:%s/" % host_port)
def config_(self, notification):
host_port = config.get(["modules", "launcher", "control_port"], 8085)
webbrowser.open_new("http://127.0.0.1:%s/" % host_port)
def run(self):
while self.notResponding():
print('Did not respond')
print('Responded')
webbrowser.open_new('http://127.0.0.1:8888/')
def showHelp(self):
webbrowser.open_new(self.help)
def showHelp(self):
if self.leave_help_open:
webbrowser.open_new(self.helpfile)
else:
dialog = displayobject.AnObject(QtGui.QDialog(), self.helpfile, title='Help')
dialog.exec_()
def show_control_web(self, widget=None, data=None):
host_port = config.get(["modules", "launcher", "control_port"], 8085)
webbrowser.open_new("http://127.0.0.1:%s/" % host_port)