Esempio n. 1
0
def install_from_emzed_store(pkg_name, wanted_version=None):
    if wanted_version:
        if isinstance(wanted_version, str):
            wanted_version = tuple(map(int, wanted_version.split(".")))
        assert isinstance(wanted_version, tuple)
        assert len(wanted_version) == 3

    url = global_config.get_url("emzed_store_url")

    version_infos = list_packages_from_emzed_store().get(pkg_name, [])
    for version, target_path in version_infos:
        if version == wanted_version:
            path = target_path
            break

    if path is None:
        raise Exception("version %s of %s not found on package store" %
                        (wanted_version, pkg_name))

    is_venv = os.environ.get("VIRTUAL_ENV") is not None
    user_flag = "" if is_venv else "--user"

    # I first tried to download the file and run easy_install locally on it. But this
    # did not update pkg_resources, so reload(emzed.ext) in the same python interpeter process
    # did not find the new extension point.
    # pip does not show this problem.

    with changed_working_directory(tempfile.mkdtemp()):
        rc = subprocess.call("pip install %s %s" % (user_flag, url + path),
                             shell=True)
        if rc:
            raise Exception("download failed")
Esempio n. 2
0
def install_from_emzed_store(pkg_name, wanted_version=None):
    if wanted_version:
        if isinstance(wanted_version, str):
            wanted_version = tuple(map(int, wanted_version.split(".")))
        assert isinstance(wanted_version, tuple)
        assert len(wanted_version) == 3

    url = global_config.get_url("emzed_store_url")

    version_infos = list_packages_from_emzed_store().get(pkg_name, [])
    for version, target_path in version_infos:
        if version == wanted_version:
            path = target_path
            break

    if path is None:
        raise Exception("version %s of %s not found on package store" % (wanted_version, pkg_name))

    is_venv = os.environ.get("VIRTUAL_ENV") is not None
    user_flag = "" if is_venv else "--user"

    # I first tried to download the file and run easy_install locally on it. But this
    # did not update pkg_resources, so reload(emzed.ext) in the same python interpeter process
    # did not find the new extension point.
    # pip does not show this problem.

    with changed_working_directory(tempfile.mkdtemp()):
        rc = subprocess.call("pip install %s %s" % (user_flag, url + path), shell=True)
        if rc:
            raise Exception("download failed")
Esempio n. 3
0
def _create_package_folder(pkg_folder, pkg_name, version):
    package_folder = os.path.join(pkg_folder, pkg_name)
    os.makedirs(package_folder)
    with open(os.path.join(package_folder, "__init__.py"), "w") as fp:
        fp.write(
            """

# IMPORTS WHICH SHOULD APPEAR IN emzed.ext AFTER INSTALLING THE PACKAGE:
from minimal_module import hello # makes emzed.ext.%s.hello() visible

# DO NOT TOUCH THE FOLLOWING LINE:
import pkg_resources
__version__ = tuple(map(int, pkg_resources.require(__name__)[0].version.split(".")))
del pkg_resources"""
            % pkg_name
        )

    with open(os.path.join(package_folder, "app.py"), "w") as fp:
        fp.write(
            """
def run():
    return 42
    """
        )

    with open(os.path.join(package_folder, "minimal_module.py"), "w") as fp:
        fp.write(
            """
def hello():
    return "hello from %s"
    """
            % pkg_name
        )

    with open(os.path.join(pkg_folder, "setup.py"), "w") as fp:
        user = global_config.get("emzed_store_user")
        password = global_config.get("emzed_store_password")
        repository = global_config.get_url("emzed_store_url")
        author = global_config.get("user_name")
        author_email = global_config.get("user_email")
        author_url = global_config.get("user_url")
        fp.write(SETUP_PY_TEMPLATE % locals())

    with open(os.path.join(pkg_folder, "LICENSE"), "w") as fp:
        fp.write(licenses.GPL_3)

    with open(os.path.join(pkg_folder, "README"), "w") as fp:
        fp.write("please describe your emzed package here\n")
Esempio n. 4
0
def list_packages_from_emzed_store(secret=""):
    url = global_config.get_url("emzed_store_url")
    result = defaultdict(list)
    if not secret:
        packages = client.list_public_files(url)
    else:
        user = global_config.get("emzed_store_user")
        folder = "/" + secret
        try:
            packages = client.list_files(url, user, folder)
        except requests.HTTPError, e:
            print e.message
            print
            print "MAYBE USER %s IS UNKNOWN OR SECRET '%s' IS INVALID" % (user, secret)
            print
            return result
Esempio n. 5
0
def delete_from_emzed_store(pkg_name, version_string, secret=""):
    assert_valid_secret(secret)
    assert version_string, "empty version_string not allowed"
    user = global_config.get("emzed_store_user")
    password = global_config.get("emzed_store_password")
    url = global_config.get_url("emzed_store_url")  # + pkg_name + "/" + version_string

    folder = "/" + secret
    try:
        files = client.list_files(url, user, folder)
    except requests.HTTPError, e:
        print e.message
        print
        print "MAYBE USER %s IS NOT KNOWN OR SECRET %r IS NOT VALID" % (user, secret)
        print
        return False
Esempio n. 6
0
def list_packages_from_emzed_store(secret=""):
    url = global_config.get_url("emzed_store_url")
    result = defaultdict(list)
    if not secret:
        packages = client.list_public_files(url)
    else:
        user = global_config.get("emzed_store_user")
        folder = "/" + secret
        try:
            packages = client.list_files(url, user, folder)
        except requests.HTTPError, e:
            print str(e)
            print
            print "MAYBE USER %s IS UNKNOWN OR SECRET '%s' IS INVALID" % (
                user, secret)
            print
            return result
Esempio n. 7
0
def delete_from_emzed_store(pkg_name, version_string, secret=""):
    assert_valid_secret(secret)
    assert version_string, "empty version_string not allowed"
    user = global_config.get("emzed_store_user")
    password = global_config.get("emzed_store_password")
    url = global_config.get_url(
        "emzed_store_url")  # + pkg_name + "/" + version_string

    folder = "/" + secret
    try:
        files = client.list_files(url, user, folder)
    except requests.HTTPError, e:
        print str(e)
        print
        print "MAYBE USER %s IS NOT KNOWN OR SECRET %r IS NOT VALID" % (user,
                                                                        secret)
        print
        return False
Esempio n. 8
0
def upload_to_emzed_store(pkg_folder, secret=""):
    assert_valid_secret(secret)
    with changed_working_directory(pkg_folder):
        # make sure we load the right setup.py
        sys.path.insert(0, os.path.abspath(pkg_folder))
        import setup
        reload(setup)
        sys.path.pop(0)

        existing_versions = list_packages_from_emzed_store()[setup.PKG_NAME]
        if existing_versions:
            if any(setup.VERSION == v for (v, __) in existing_versions):

                raise Exception("package %s with version %s already exists" %
                                (setup.PKG_NAME, setup.VERSION))
        if os.path.exists("dist"):
            shutil.rmtree("dist")

        rc = subprocess.call("python setup.py sdist",
                             shell=True,
                             stdout=sys.__stdout__,
                             stderr=sys.__stdout__)
        if rc:
            raise Exception("upload failed")

        user = global_config.get("emzed_store_user")
        password = global_config.get("emzed_store_password")
        url = global_config.get_url("emzed_store_url")

        for p in glob.glob("dist/*"):
            if os.path.isfile(p):
                path = "/%s/%s" % (secret, os.path.basename(p))
                with open(p, "rb") as fp:
                    try:
                        client.upload_file(url, user, password, path, fp)
                    except requests.HTTPError, e:
                        print str(e)
                        print
                        print "MAYBE USER %s IS UNKNOWN OR PASSWORD DOES NOT MATCH" % user
                        print
                        print "USE emzed.config.edit() TO CHANGE THEM."
                        print
                        break
Esempio n. 9
0
def upload_to_emzed_store(pkg_folder, secret=""):
    assert_valid_secret(secret)
    with changed_working_directory(pkg_folder):
        # make sure we load the right setup.py
        sys.path.insert(0, os.path.abspath(pkg_folder))
        import setup
        reload(setup)
        sys.path.pop(0)

        existing_versions = list_packages_from_emzed_store()[setup.PKG_NAME]
        if existing_versions:
            if any(setup.VERSION == v for (v, __) in existing_versions):

                raise Exception("package %s with version %s already exists" % (setup.PKG_NAME,
                                                                               setup.VERSION))
        if os.path.exists("dist"):
            shutil.rmtree("dist")

        rc = subprocess.call("python setup.py sdist", shell=True,
                stdout=sys.__stdout__,
                stderr= sys.__stdout__)
        if rc:
            raise Exception("upload failed")

        user = global_config.get("emzed_store_user")
        password = global_config.get("emzed_store_password")
        url = global_config.get_url("emzed_store_url")

        for p in glob.glob("dist/*"):
            if os.path.isfile(p):
                path = "/%s/%s" % (secret, os.path.basename(p))
                with open(p, "rb") as fp:
                    try:
                        client.upload_file(url, user, password, path, fp)
                    except requests.HTTPError, e:
                        print e.message
                        print
                        print "MAYBE USER %s IS UNKNOWN OR PASSWORD DOES NOT MATCH" % user
                        print
                        print "USE emzed.config.edit() TO CHANGE THEM."
                        print
                        break
Esempio n. 10
0
def _create_package_folder(pkg_folder, pkg_name, version):
    package_folder = os.path.join(pkg_folder, pkg_name)
    os.makedirs(package_folder)
    with open(os.path.join(package_folder, "__init__.py"), "w") as fp:
        fp.write("""

# IMPORTS WHICH SHOULD APPEAR IN emzed.ext AFTER INSTALLING THE PACKAGE:
from minimal_module import hello # makes emzed.ext.%s.hello() visible

# DO NOT TOUCH THE FOLLOWING LINE:
import pkg_resources
__version__ = tuple(map(int, pkg_resources.require(__name__)[0].version.split(".")))
del pkg_resources""" % pkg_name)

    with open(os.path.join(package_folder, "app.py"), "w") as fp:
        fp.write("""
def run():
    return 42
    """)

    with open(os.path.join(package_folder, "minimal_module.py"), "w") as fp:
        fp.write("""
def hello():
    return "hello from %s"
    """ % pkg_name)

    with open(os.path.join(pkg_folder, "setup.py"), "w") as fp:
        user = global_config.get("emzed_store_user")
        password = global_config.get("emzed_store_password")
        repository = global_config.get_url("emzed_store_url")
        author = global_config.get("user_name")
        author_email = global_config.get("user_email")
        author_url = global_config.get("user_url")
        fp.write(SETUP_PY_TEMPLATE % locals())

    with open(os.path.join(pkg_folder, "LICENSE"), "w") as fp:
        fp.write(licenses.GPL_3)

    with open(os.path.join(pkg_folder, "README"), "w") as fp:
        fp.write("please describe your emzed package here\n")