Example #1
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     if len(self.project.dependencies) > 0:
         post_event('app_build_with_npm_deps')
         try:
             npm.invoke_npm(["install"])
             npm.invoke_npm(["dedupe"])
         except subprocess.CalledProcessError:
             post_event("app_build_failed_npm")
             raise BuildError("npm failed.")
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         extra_env = {}
         if args.debug:
             extra_env = {'CFLAGS': os.environ.get('CFLAGS', '') + ' -O0'}
         self._waf("configure", extra_env=extra_env, args=waf)
         self._waf("build", args=waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded", has_js=has_js, line_counts=self._get_line_counts(), build_time=duration)
Example #2
0
 def do_install(cls, args):
     try:
         npm.invoke_npm(["install", "--save", "--ignore-scripts", args.package])
         npm.invoke_npm(["dedupe"])
         npm.sanity_check()
     except subprocess.CalledProcessError:
         raise ToolError()
Example #3
0
    def _install_from_handle(self, f):
        path = None
        try:
            print("Extracting...")
            with tarfile.open(fileobj=f, mode="r:*") as t:
                with closing(
                        t.extractfile('sdk-core/manifest.json')) as f_manifest:
                    sdk_info = json.load(f_manifest)
                path = os.path.normpath(
                    os.path.join(self.sdk_dir, sdk_info['version']))
                if os.path.exists(path):
                    raise SDKInstallError(
                        "SDK {} is already installed.".format(
                            sdk_info['version']))
                contents = t.getnames()
                for filename in contents:
                    if filename.startswith('/') or '..' in filename:
                        raise SDKInstallError(
                            "SDK contained a questionable file: {}".format(
                                filename))
                if not path.startswith(self.sdk_dir):
                    raise SDKInstallError(
                        "Suspicious version number: {}".format(
                            sdk_info['version']))
                Requirements(sdk_info['requirements']).ensure_satisfied()
                os.mkdir(os.path.join(self.sdk_dir, sdk_info['version']))
                t.extractall(path)
            virtualenv_path = os.path.join(path, ".env")
            print("Preparing virtualenv... (this may take a while)")
            subprocess.check_call([
                sys.executable, "-m", "virtualenv", virtualenv_path,
                "--no-site-packages"
            ])
            print("Installing dependencies...")
            subprocess.check_call([
                os.path.join(virtualenv_path, "bin", "python"), "-m", "pip",
                "install", "-r",
                os.path.join(path, "sdk-core", "requirements.txt")
            ],
                                  env={'PYTHONHOME': virtualenv_path})
            package_json = os.path.join(path, "sdk-core", "package.json")
            if os.path.exists(package_json):
                print("Installing JS dependencies... (this may take a while)")
                node_modules_folder = os.path.join(path, "node_modules")
                os.mkdir(node_modules_folder)
                shutil.copy2(package_json, os.path.join(path, "package.json"))
                invoke_npm(["install", "--silent"], cwd=path)

            self.set_current_sdk(sdk_info['version'])
            print("Done.")
        except Exception:
            print("Failed.")
            try:
                if path is not None and os.path.exists(path):
                    print("Cleaning up failed install...")
                    shutil.rmtree(path)
                    print("Done.")
            except OSError:
                print("Cleanup failed.")
            raise
Example #4
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     if len(self.project.dependencies) > 0:
         post_event('app_build_with_npm_deps')
         try:
             npm.invoke_npm(["install"])
             npm.invoke_npm(["dedupe"])
         except subprocess.CalledProcessError:
             post_event("app_build_failed_npm")
             raise BuildError("npm failed.")
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         extra_env = {}
         if args.debug:
             extra_env = {'CFLAGS': os.environ.get('CFLAGS', '') + ' -O0'}
         self._waf("configure", extra_env=extra_env, args=waf)
         self._waf("build", args=waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded",
                    has_js=has_js,
                    line_counts=self._get_line_counts(),
                    build_time=duration)
Example #5
0
 def do_install(cls, args):
     try:
         npm.invoke_npm(
             ["install", "--save", "--ignore-scripts", args.package])
         npm.invoke_npm(["dedupe"])
         npm.sanity_check()
     except subprocess.CalledProcessError:
         raise ToolError()
Example #6
0
    def _install_from_handle(self, f):
        path = None
        try:
            print("Extracting...")
            with tarfile.open(fileobj=f, mode="r:*") as t:
                with closing(t.extractfile('sdk-core/manifest.json')) as f_manifest:
                    sdk_info = json.load(f_manifest)
                path = os.path.normpath(os.path.join(self.sdk_dir, sdk_info['version']))
                if os.path.exists(path):
                    raise SDKInstallError("SDK {} is already installed.".format(sdk_info['version']))
                contents = t.getnames()
                for filename in contents:
                    if filename.startswith('/') or '..' in filename:
                        raise SDKInstallError("SDK contained a questionable file: {}".format(filename))
                if not path.startswith(self.sdk_dir):
                    raise SDKInstallError("Suspicious version number: {}".format(sdk_info['version']))
                Requirements(sdk_info['requirements']).ensure_satisfied()
                os.mkdir(os.path.join(self.sdk_dir, sdk_info['version']))
                t.extractall(path)
            virtualenv_path = os.path.join(path, ".env")
            print("Preparing virtualenv... (this may take a while)")
            subprocess.check_call([sys.executable, "-m", "virtualenv", virtualenv_path, "--no-site-packages"])
            print("Installing dependencies...")
            subprocess.check_call([os.path.join(virtualenv_path, "bin", "python"), "-m", "pip", "install", "-r",
                                   os.path.join(path, "sdk-core", "requirements.txt")],
                                  env={'PYTHONHOME': virtualenv_path})
            package_json = os.path.join(path, "sdk-core", "package.json")
            if os.path.exists(package_json):
                print("Installing JS dependencies... (this may take a while)")
                node_modules_folder = os.path.join(path, "node_modules")
                os.mkdir(node_modules_folder)
                shutil.copy2(package_json, os.path.join(path, "package.json"))
                invoke_npm(["install", "--silent"], cwd=path)

            self.set_current_sdk(sdk_info['version'])
            print("Done.")
        except Exception:
            print("Failed.")
            try:
                if path is not None and os.path.exists(path):
                    print("Cleaning up failed install...")
                    shutil.rmtree(path)
                    print("Done.")
            except OSError:
                print("Cleanup failed.")
            raise
Example #7
0
 def do_publish(cls, args):
     try:
         npm.invoke_npm(["publish"])
     except subprocess.CalledProcessError:
         pass
Example #8
0
 def do_login(cls, args):
     print("You can either log in to or create an npm account here.")
     try:
         npm.invoke_npm(["login"])
     except subprocess.CalledProcessError:
         pass
Example #9
0
 def do_uninstall(cls, args):
     npm.invoke_npm(["uninstall", "--save", "--ignore-scripts", args.package])
Example #10
0
    def make_tintin_sdk(self, path):
        path = os.path.realpath(os.path.expanduser(path))
        dest_path = os.path.join(self.sdk_dir, 'tintin')
        if not os.path.exists(os.path.join(path, 'wscript')):
            raise SDKInstallError("No tintin found at {}".format(path))
        if os.path.exists(dest_path):
            raise SDKInstallError(
                "tintin SDK already set up. uninstall before making changes.")
        build_path = os.path.join(path, 'build')
        sdk_path = os.path.join(build_path, 'sdk')
        os.mkdir(dest_path)
        env_path = os.path.join(dest_path, '.env')
        if os.path.exists(os.path.join(sdk_path, 'package.json')):
            shutil.copy2(os.path.join(sdk_path, 'package.json'),
                         os.path.join(dest_path, 'package.json'))
            node_modules_path = os.path.join(dest_path, 'node_modules')
            os.mkdir(node_modules_path)
        dest_path = os.path.join(dest_path, 'sdk-core')
        os.mkdir(os.path.join(dest_path))
        pebble_path = os.path.join(dest_path, 'pebble')
        os.mkdir(pebble_path)

        # A symlink doesn't work for some reason; instead write a python script that invokes waf using whatever
        # interpreter we used to invoke it.
        with open(os.path.join(pebble_path, 'waf'), 'w') as f:
            f.write("""#!/usr/bin/env python
import subprocess
import sys
subprocess.call([sys.executable, {}] + sys.argv[1:])
""".format(repr(os.path.join(sdk_path, 'waf'))))
            os.chmod(os.path.join(pebble_path, 'waf'), 0o755)
        for platform in pebble_platforms:
            os.mkdir(os.path.join(pebble_path, platform))
            os.symlink(os.path.join(sdk_path, platform, 'include'),
                       os.path.join(pebble_path, platform, 'include'))
            os.symlink(os.path.join(sdk_path, platform, 'lib'),
                       os.path.join(pebble_path, platform, 'lib'))
            os.mkdir(os.path.join(pebble_path, platform, 'qemu'))
            os.symlink(
                os.path.join(build_path, 'qemu_micro_flash.bin'),
                os.path.join(pebble_path, platform, 'qemu',
                             'qemu_micro_flash.bin'))
            os.symlink(
                os.path.join(build_path, 'qemu_spi_flash.bin'),
                os.path.join(pebble_path, platform, 'qemu',
                             'qemu_spi_flash.bin'))

        os.symlink(os.path.join(sdk_path, 'common/'),
                   os.path.join(pebble_path, 'common'))

        with open(os.path.join(dest_path, 'manifest.json'), 'w') as f:
            json.dump(
                {
                    'requirements': [],
                    'version': 'tintin',
                    'type': 'sdk-core',
                    'channel': '',
                }, f)

        print("Preparing virtualenv... (this may take a while)")
        subprocess.check_call([
            sys.executable, "-m", "virtualenv", env_path, "--no-site-packages"
        ])
        print("Installing dependencies...")
        print(
            "This may fail installing Pillow==2.0.0. In that case, question why we still force 2.0.0 anyway."
        )
        if sys.platform.startswith('darwin'):
            platform = 'osx'
        elif sys.platform.startswith('linux'):
            platform = 'linux'
        else:
            raise SDKInstallError(
                "Couldn't figure out what requirements to install.")
        subprocess.check_call([
            os.path.join(env_path, "bin", "python"), "-m", "pip", "install",
            "-r",
            os.path.join(path, "requirements-{}.txt".format(platform))
        ],
                              env={
                                  'PYTHONHOME': env_path,
                                  'PATH': os.environ['PATH']
                              })
        if os.path.exists(os.path.join(dest_path, '..', 'node_modules')):
            print("Installing JS dependencies... (this may take a while)")
            invoke_npm(["install", "--silent"],
                       cwd=os.path.join(dest_path, '..'))

        self.set_current_sdk('tintin')
        print("Generated an SDK linked to {}.".format(path))
Example #11
0
    def make_tintin_sdk(self, path):
        path = os.path.realpath(os.path.expanduser(path))
        dest_path = os.path.join(self.sdk_dir, 'tintin')
        if not os.path.exists(os.path.join(path, 'wscript')):
            raise SDKInstallError("No tintin found at {}".format(path))
        if os.path.exists(dest_path):
            raise SDKInstallError("tintin SDK already set up. uninstall before making changes.")
        build_path = os.path.join(path, 'build')
        sdk_path = os.path.join(build_path, 'sdk')
        os.mkdir(dest_path)
        env_path = os.path.join(dest_path, '.env')
        if os.path.exists(os.path.join(sdk_path, 'package.json')):
            shutil.copy2(os.path.join(sdk_path, 'package.json'), os.path.join(dest_path, 'package.json'))
            node_modules_path = os.path.join(dest_path, 'node_modules')
            os.mkdir(node_modules_path)
        dest_path = os.path.join(dest_path, 'sdk-core')
        os.mkdir(os.path.join(dest_path))
        pebble_path = os.path.join(dest_path, 'pebble')
        os.mkdir(pebble_path)

        # A symlink doesn't work for some reason; instead write a python script that invokes waf using whatever
        # interpreter we used to invoke it.
        with open(os.path.join(pebble_path, 'waf'), 'w') as f:
            f.write("""#!/usr/bin/env python
import subprocess
import sys
subprocess.call([sys.executable, {}] + sys.argv[1:])
""".format(repr(os.path.join(sdk_path, 'waf'))))
            os.chmod(os.path.join(pebble_path, 'waf'), 0o755)
        for platform in pebble_platforms:
            os.mkdir(os.path.join(pebble_path, platform))
            os.symlink(os.path.join(sdk_path, platform, 'include'), os.path.join(pebble_path, platform, 'include'))
            os.symlink(os.path.join(sdk_path, platform, 'lib'), os.path.join(pebble_path, platform, 'lib'))
            os.mkdir(os.path.join(pebble_path, platform, 'qemu'))
            os.symlink(os.path.join(build_path, 'qemu_micro_flash.bin'),
                       os.path.join(pebble_path, platform, 'qemu', 'qemu_micro_flash.bin'))
            os.symlink(os.path.join(build_path, 'qemu_spi_flash.bin'),
                       os.path.join(pebble_path, platform, 'qemu', 'qemu_spi_flash.bin'))

        os.symlink(os.path.join(sdk_path, 'common/'), 
                   os.path.join(pebble_path, 'common'))

        with open(os.path.join(dest_path, 'manifest.json'), 'w') as f:
            json.dump({
                'requirements': [],
                'version': 'tintin',
                'type': 'sdk-core',
                'channel': '',
            }, f)

        print("Preparing virtualenv... (this may take a while)")
        subprocess.check_call([sys.executable, "-m", "virtualenv", env_path, "--no-site-packages"])
        print("Installing dependencies...")
        print("This may fail installing Pillow==2.0.0. In that case, question why we still force 2.0.0 anyway.")
        if sys.platform.startswith('darwin'):
            platform = 'osx'
        elif sys.platform.startswith('linux'):
            platform = 'linux'
        else:
            raise SDKInstallError("Couldn't figure out what requirements to install.")
        subprocess.check_call([os.path.join(env_path, "bin", "python"), "-m", "pip", "install", "-r",
                               os.path.join(path, "requirements-{}.txt".format(platform))],
                              env={'PYTHONHOME': env_path, 'PATH': os.environ['PATH']})
        if os.path.exists(os.path.join(dest_path, '..', 'node_modules')):
            print("Installing JS dependencies... (this may take a while)")
            invoke_npm(["install", "--silent"], cwd=os.path.join(dest_path, '..'))

        self.set_current_sdk('tintin')
        print("Generated an SDK linked to {}.".format(path))
Example #12
0
 def do_publish(cls, args):
     try:
         npm.invoke_npm(["publish"])
     except subprocess.CalledProcessError:
         pass
Example #13
0
 def do_login(cls, args):
     print("You can either log in to or create an npm account here.")
     try:
         npm.invoke_npm(["login"])
     except subprocess.CalledProcessError:
         pass
Example #14
0
 def do_uninstall(cls, args):
     npm.invoke_npm(
         ["uninstall", "--save", "--ignore-scripts", args.package])