def demo(): import envoy import heroku user = request.values['user'].encode("utf-8") repo = request.values['repo'].encode("utf-8") username = os.environ['HEROKU_USER'] password = os.environ['HEROKU_PASS'] cloud = heroku.from_pass(username, password) app = cloud.apps.add() r = envoy.run("git clone %s %s" % (repo, app.name.encode("utf-8")), timeout=15) try: os.chdir(app.name.encode("utf-8")) print 1 r = envoy.run("git remote add heroku [email protected]:%s.git" % app.name.encode("utf-8")) print 2 r = envoy.run('git push heroku master') print 3 app = cloud.apps[app.name] print 4 app.collaborators.add(user) print 5 app.transfer(user) print 6 result = Response(response = json.dumps({'result': "success", 'name': app.name}), mimetype="application/json") print 7 except Exception, e: print e app.destroy() result = Response(response = json.dumps({'result': "failed"}), mimetype="application/json")
def log_ping(): if TASKS.get('log_ping'): heroku_user = os.environ['HEROKU_USERNAME'] heroku_pass = os.environ['HEROKU_PASSWORD'] cloud = heroku.from_pass(heroku_user, heroku_pass) for app in (h_app.name for h_app in cloud.apps): url = "http://{app}.herokuapp.com/".format(app=app) result = requests.get(url).status_code log_this(sys._getframe().f_code.co_name, url, result)
def add_domain(name): heroku_email = settings.HEROKU_EMAIL heroku_pass = settings.HEROKU_PASSWORD cloud = heroku.from_pass(heroku_email, heroku_pass) app = cloud.apps[settings.HEROKU_APP_NAME] domain = app.domains try: domain.add(name) except HTTPError: pass # NOTICE: silencing error
def get_projects(): heroku_user = os.environ['HEROKU_USERNAME'] heroku_pass = os.environ['HEROKU_PASSWORD'] cloud = heroku.from_pass(heroku_user, heroku_pass) return [ { "name": h_app.name, "url": "http://{app}.herokuapp.com/".format(app=h_app.name), } for h_app in cloud.apps ]
def scaleUpDynos(): heroku_username = SECRETS_DICT["HEROKU_USERNAME"] heroku_password = SECRETS_DICT["HEROKU_PASSWORD"] cloud = heroku.from_pass(heroku_username, heroku_password) apps = cloud.apps app = apps['twitter-politics'] dyno = app.processes['tw'] for i in range(1,TOTAL_THREADS): print "++ starting dyno: " + str(i+1) dyno.scale(i+1) time.sleep(120) displayScriptProgress(to_email=LAUNCH_EMAIL_RECIPIENTS)
def scaleUpDynos(): heroku_username = SECRETS_DICT["HEROKU_USERNAME"] heroku_password = SECRETS_DICT["HEROKU_PASSWORD"] cloud = heroku.from_pass(heroku_username, heroku_password) apps = cloud.apps app = apps['twitter-politics'] dyno = app.processes['tw'] for i in range(1, TOTAL_THREADS): print "++ starting dyno: " + str(i + 1) dyno.scale(i + 1) time.sleep(120) displayScriptProgress(to_email=LAUNCH_EMAIL_RECIPIENTS)
def apply(self): try: self.cloud = heroku.from_key(self.params.key.as_string()) except errors.NoMatching: try: username = self.params.username.as_string() password = self.params.password.as_string() except errors.NoMatching: raise errors.TypeError( "Must specify key or username and password", anchor=self.params.anchor) self.cloud = heroku.from_pass(username, password) if self.root.readonly: return changed = False app_id = self.params.application_id.as_string() if not app_id in self.cloud.apps: self.action("Creating new app named '%s'" % app_id) if not self.root.simulate: self.app = self.cloud.apps.add(app_id) else: self.app = None changed = True else: self.app = self.cloud.apps[app_id] self.action("Entering maintenance mode") if not self.root.simulate and self.app: self.app.maintenance(on=True) self.apply_configuration() self.apply_scaling() self.apply_addons() self.action("Leaving maintenance mode") if not self.root.simulate and self.app: self.app.maintenance(on=False) self.apply_domains() # May generate e-mail so do it last - we don't want someone looking # half way through set up self.apply_collaborators() self.root.changed(changed)
def demo(): import envoy import heroku user = request.values['user'].encode("utf-8") repo = request.values['repo'].encode("utf-8") username = os.environ['HEROKU_USER'] password = os.environ['HEROKU_PASS'] cloud = heroku.from_pass(username, password) app = cloud.apps.add() r = envoy.run("git clone %s %s" % (repo, app.name.encode("utf-8")), timeout=15) try: os.chdir(app.name.encode("utf-8")) print 1 r = envoy.run("git remote add heroku [email protected]:%s.git" % app.name.encode("utf-8")) print 2 r = envoy.run('git push heroku master') print 3 app = cloud.apps[app.name] print 4 app.collaborators.add(user) print 5 app.transfer(user) print 6 result = Response(response=json.dumps({ 'result': "success", 'name': app.name }), mimetype="application/json") print 7 except Exception, e: print e app.destroy() result = Response(response=json.dumps({'result': "failed"}), mimetype="application/json")
from __future__ import print_function import heroku, sys, os print(sys.argv) username, password = sys.argv[1:] client = heroku.from_pass(username, password) api_key = client._api_key netrc = '''machine %s.heroku.com login %s password %s ''' netrc_path = os.path.expanduser('~vagrant/.netrc') netrc_file = os.fdopen(os.open(netrc_path, os.O_WRONLY | os.O_CREAT, 0600), 'w') try: for machine in ['api', 'git']: print(netrc % (machine, username, api_key), file=netrc_file) except Exception, e: netrc_file.close() os.remove(netrc_path)
except IndexError: print "\nUsage: ~$ python add_domains.py app_name domains_to_add.txt\n" sys.exit(1) heroku_email = raw_input("Heroku email: ") heroku_pass = getpass.getpass() domains_error = [] d_success = 0 d_failure = 0 # read the supplied domains file with open(domains_file, 'r') as f: domains = [line.strip() for line in f] print "Attempting to add %d domains to '%s' from supplied '%s'..." % (len(domains), my_app, domains_file) # log in to Heroku cloud = heroku.from_pass(heroku_email, heroku_pass) app = cloud.apps[my_app] domain = app.domains # try adding domains for d in domains: try: domain.add(d) except HTTPError: domains_error.append(d) d_failure += 1 print "ERROR adding: %s" % d else: d_success += 1 print "added: %s" % d
from __future__ import print_function import heroku, sys, os print(sys.argv) username, password = sys.argv[1:] client = heroku.from_pass(username, password) api_key = client._api_key netrc = """machine %s.heroku.com login %s password %s """ netrc_path = os.path.expanduser("~vagrant/.netrc") netrc_file = os.fdopen(os.open(netrc_path, os.O_WRONLY | os.O_CREAT, 0600), "w") try: for machine in ["api", "git"]: print(netrc % (machine, username, api_key), file=netrc_file) except Exception, e: netrc_file.close() os.remove(netrc_path)
app = Flask(__name__) redis_url = os.environ.get('REDISTOGO_URL', 'redis://*****:*****@celery.task(name='yoshi.install') def install(package, connect=False): # Create temp git directory. git_path = os.path.join(tempfile.mkdtemp(), 'repo') os.makedirs(git_path) os.chdir(git_path) # Initialize the repo. envoy.run('git init') with open('requirements.txt', 'w') as f: