def _importlayers(t=None, local=None, drop=None, user=None, overwrite=None, category=None, keywords=None, private=None): t = _request_input("Type (vanilla/geoshape)", t, True, options=GEONODE_TYPES) local = _request_input("Local File Path", local, True) drop = _request_input("Remote Drop Folder", drop, True) user = _request_input("User", user, False) overwrite = _request_input("Overwrite", overwrite, False) category = _request_input("Category", category, False, options=ISO_CATEGORIES) keywords = _request_input("Keywords (Comma-separated)", keywords, False) private = _request_input("Private", private, True) path_managepy = PATH_MANAGEPY_GS if t.lower()=="geoshape" else PATH_MANAGEPY_VN if _request_continue(): sudo("[ -d {d} ] || mkdir {d}".format(d=drop)) remote_files = put(local, drop, mode='0444', use_sudo=True) if remote_files: with cd(path_managepy): template = "source {a}; python manage.py importlayers {paths}" if user: template += " -u {u}".format(u=user) if overwrite: template += " -o" if category: template += " -c {c}".format(c=category) if keywords: template += " -k {kw}".format(kw=keywords) if private: template += " -p" c = template.format(a=PATH_ACTIVATE, paths=(" ".join(remote_files))) sudo(c) else: print "Not files uploaded"
def _add_analytics_ga(t=None, c=None): data = _load_template('settings_ga.py') if data: t = _request_input("Type (vanilla/geoshape)", t, True, options=GEONODE_TYPES) c = _request_input("Code", c, True) ls = PATH_LS_GS if t.lower()=="geoshape" else PATH_LS_VN data = data.replace("{{code}}", c) print "Local Settings: "+ls print "Data..." print data if _request_continue(): _append_to_file(data.split("\n"), ls)
def _add_analytics_dap(t=None, a=None, sa=None): data = _load_template('settings_dap.py') if data: t = _request_input("Type (vanilla/geoshape)", t, True, options=GEONODE_TYPES) a = _request_input("Agency", a, True) sa = _request_input("Sub-agency", sa, True) ls = PATH_LS_GS if t.lower()=="geoshape" else PATH_LS_VN data = data.replace("{{agency}}", a) data = data.replace("{{subagency}}", sa) print "Local Settings: "+ls print "Data..." print data if _request_continue(): _append_to_file(data.split("\n"), ls)
def _add_email(t=None, a=None, p=None, h=None): data = _load_template('settings_email.py') if data: t = _request_input("Type (vanilla/geoshape)", t, True, options=GEONODE_TYPES) a = _request_input("Address (e.g., [email protected])", a, True) p = _request_input("Password", p, True) h = _request_input("Host (e.g., smtp.gmail.com)", h, True) ls = PATH_LS_GS if t.lower()=="geoshape" else PATH_LS_VN data = data.replace("{{address}}", a) data = data.replace("{{password}}", p) data = data.replace("{{host}}", h) print "Local Settings: "+ls print "Data..." print data if _request_continue(): _append_to_file(data.split("\n"), ls)
def add_gmail(t=None, u=None, p=None): """ Adds server GMail to instance Adds GMail settings to vim /var/lib/geonode/rogue_geonode/geoshape/local_settings.py """ address = _request_input("User", u, True)+'@gmail.com' host = 'smtp.gmail.com' return _run_task(_add_email, args=None, kwargs={'t':t, 'a':address, 'p':p, 'h':host})
def _add_cache(n=None, d=None, ip=None, l=None, u=None, p=None): data = _load_template("tilecache.cfg") if data: n = _request_input("Name", n, True) d = _request_input("Description", d, True) ip = _request_input("IP Address", ip, True) l = _request_input("Layers", l, True) u = _request_input("User", u, True) p = _request_input("Password", p, True) data = data.replace("{{name}}", n) data = data.replace("{{description}}", d) data = data.replace("{{ip}}", ip) data = data.replace("{{layers}}", l) data = data.replace("{{user}}", u) data = data.replace("{{password}}", p) print "Data..." print data if _request_continue(): _append_to_file(data.split("\n"), "/etc/tilecache.cfg") _restart_apache()
def _backup_geonode(t=None, remote=None, local=None): t = _request_input("Type (vanilla/geoshape)", t, True, options=GEONODE_TYPES) remote = _request_input("Remote Destination Folder", remote, True) local = _request_input("Local File Path", local, False) if _request_continue(): print "Backing up data..." sudo("[ -d {d} ] || mkdir {d}".format(d=remote)) sudo("[ -d {d}/db ] || mkdir {d}/db".format(d=remote)) sudo('chown -R {u}:{g} {d}/db'.format(u="postgres", g="postgres", d=remote)) with settings(sudo_user='******'): sudo('pg_dump geonode | gzip > {d}/db/geonode.gz'.format(d=remote)) sudo('pg_dump geonode_imports | gzip > {d}/db/geonode_imports.gz'.format(d=remote)) sudo('cp -R {gsd} {d}/geoserver'.format(gsd=PATH_GEOSERVER_DATA, d=remote)) if local: local_files = get(remote, local_path=local) for local_file in local_files: print "Downloaded Local File: "+local_file print "Backup complete."
def _upload_files( target, local=None, manifest=None, drop=None, tries=None, user=None, group=None, iam=None, notify_level=None, topic=None, use_sudo=None, ): while True: if (not local) and (not manifest): local = _request_input("Local File Path", local, False) if (not local) and (not manifest): manifest = _request_input("Manifest Path", manifest, False) if local or manifest: break print "Either local or manifest required. Please try again. Ctrl+C to cancel." drop = _request_input("Remote Drop Folder", drop, True) tries = _request_input("Tries for each file", tries, True) user = _request_input("User", user, True) group = _request_input("Group", group, True) use_sudo = _request_input("Use Sudo", use_sudo, True, options={"yes": "yes", "no": "no"}) == "yes" notify_level = int(_request_input("Notification Level", notify_level, True, options=["0", "1", "2"])) iam_users = None try: iam_users = AWS_SETTINGS["iam"] except: pass topics = None try: topics = AWS_SETTINGS["topics"] except: pass while True: if not iam: iam = _request_input("IAM User", iam, False, options=iam_users) if not topic: topic = _request_input("Notify Topic", topic, False, options=topics) if (bool(iam) or bool(topic)) == (bool(iam) and bool(topic)): break print "If sending a notification, both iam and topic are required. Please try again. Ctrl+C to cancel." if _request_continue(): sudo("[ -d {d} ] || ( mkdir {d} ; chown -R {u}:{g} {d} ) ".format(d=drop, u=user, g=group)) local_files = glob(local) if local else _parse_manifest(manifest) print manifest print local_files md5_list = [] for f in local_files: md5_list.append(_calc_md5sum(f)) print "Local Files" for i in range(len(local_files)): print local_files[i] + ": " + md5_list[i] files_list = [] count_success = 0 count_failed = 0 for i in range(len(local_files)): print "Uploading " + local_files[i] + "..." rf = _upload_file(local_files[i], drop, md5_list[i], int(tries), user, group, use_sudo) files_list.append({"lf": local_files[i], "rf": (rf if rf else "XXX"), "status": (rf is not None)}) if rf: count_success += 1 if iam and topic and notify_level == 2: _notify_file_uploaded(iam, topic, local_files[i], rf, target["name"], target["host"], True) else: count_failed += 1 print "Aborted. Could not upload " + local_files[i] + "." if iam and topic and notify_level == 2: _notify_file_uploaded(iam, topic, local_files[i], rf, target["name"], target["host"], False) if iam and topic and (notify_level == 1 or notify_level == 2): _notify_file_uploads(iam, topic, count_success, count_failed, target["name"], target["host"], files_list)