# -*- coding: utf-8 -*- from fabric2 import Connection from invoke import Result from pathlib_mate import PathCls as Path _ = Result HOST = "ec2-54-165-167-139.compute-1.amazonaws.com" USER = "******" PEM_PATH = Path.home().append_parts("ec2-pem", "eq-sanhe-dev.pem").abspath # open a ssh session and close automatically with Connection(host=HOST, user=USER, connect_kwargs={"key_filename": [ PEM_PATH, ]}) as conn: # example1: send command, create a html file index.html # conn.run('echo "<html>Hello World</html>" > /tmp/index.html') # type: Result # conn.run('cat /tmp/index.html') # type: Result # example2: process standard output afterwards result = conn.run('ls /', hide=True) # type: Result print( result.stdout ) # access the standard output, capture those strings and process it in Python # print(result.stderr) # print(result.encoding) # print(result.command) # print(result.shell) # the shell you use to execute this command
""" from __future__ import print_function import requests from pathlib_mate import PathCls as Path try: from .pkg.atomicwrites import atomic_write from .pkg.sqlalchemy_mate import engine_creator except: from uszipcode.pkg.atomicwrites import atomic_write from uszipcode.pkg.sqlalchemy_mate import engine_creator db_file_dir = Path.home().append_parts(".uszipcode") db_file_dir.mkdir(exist_ok=True) simple_db_file_path = db_file_dir.append_parts("simple_db.sqlite") db_file_path = db_file_dir.append_parts("db.sqlite") def is_simple_db_file_exists(): if simple_db_file_path.exists(): if simple_db_file_path.size >= 5 * 1000 * 1000: return True return False def is_db_file_exists(): if db_file_path.exists():
then put everything into ``dev.sh`` and use the "Example: run shell script remotely" to run the shell script on remote. """ from fabric2 import Connection from invoke import Result from paramiko import SFTPClient from patchwork.transfers import rsync from pathlib_mate import PathCls as Path # --- Config --- HOST = "ec2-111-222-333-444.compute-1.amazonaws.com" OS_USERNAME = "******" # for Amazon Linux and Redhat, its ec2-user, for Ubuntu, its ubuntu, for other system, read this: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html#connection-prereqs-get-info-about-instance # all path are absolute HOME = Path.home() # $HOME directory HERE = Path(__file__).parent # where this dev.py scripts locate REPO_ROOT = HERE.parent # the path of this repository on local laptop REPO_ROOT_REMOTE = "/tmp/{}".format(REPO_ROOT.basename) # the path of this repository on remote server, if using rsync. PEM_PATH = Path(HOME, "path-to-my-pem-file.pem").abspath _ = Result _ = SFTPClient _ = rsync # config connection with Connection( host=HOST, user=OS_USERNAME, connect_kwargs=dict(
# -*- coding: utf-8 -*- """ dir settings """ from __future__ import unicode_literals from pathlib_mate import PathCls as Path HOME = Path.home() """ User home directory: - Windows: C:\\Users\\<username> - MacOS: /Users/<username> - Ubuntu: /home/<username> """ ALFRED_FTS = Path(HOME, ".alfred-fts") """ Alfred Full Text Search Data Folder: ${HOME}/.alfred-fts """ if not ALFRED_FTS.exists(): ALFRED_FTS.mkdir()