Beispiel #1
0
def setup(module, target='zip', output_path=None, data_dir=None):
    dist = os.path.abspath('dist')
    try:
        if target == 'zip':
            assert er(
                'setup.py', 'install', '--no-compile', '--install-lib',
                os.path.join(dist, 'lib'), '--install-scripts',
                os.path.join(dist),
                *(['--install-data',
                   os.path.join(dist, data_dir)]
                  if data_dir is not None else []))
            with shell.goto(dist) as ok:
                assert ok
                assert compress.mkzip('%s.zip' % module,
                                      glob.glob(os.path.join('lib', '*')))
                assert shell.remove('lib')
        elif target == 'exe':
            assert er(
                'setup.py', 'install', '--no-compile', '--install-lib',
                os.path.join(dist, 'lib', 'python'), '--install-scripts',
                os.path.join(dist, 'scripts'),
                *(['--install-data',
                   os.path.join(dist, data_dir)]
                  if data_dir is not None else []))
            with shell.goto(dist) as ok:
                assert ok

                modules = list(
                    filter(os.path.exists, ['lib', 'scripts'] +
                           ([data_dir] if data_dir is not None else [])))
                assert compress.seven_zip('%s.exe' % module,
                                          modules,
                                          self_extracting=True)
                # Cleanup
                for module in modules:
                    assert shell.remove(module)
        if output_path is not None:
            output_path = os.path.abspath(output_path)
            if output_path != dist:
                if not os.path.isdir(output_path):
                    assert shell.mkdir(output_path)
                for filename in shell.search(dist, '*'):
                    output = os.path.join(
                        output_path,
                        filename.replace(dist, '', 1).strip('\\/'))
                    assert shell.move(filename, output)
        return 0
    except AssertionError as e:
        print(e)
        return 1
    finally:
        # Cleanup
        if output_path != dist:
            shell.remove(dist)
        if os.path.isdir('build'):
            shell.remove('build')
Beispiel #2
0
 def test_non_existing_no_create(self, os):
     os.getcwd.return_value = 'foo'
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = False
     with shell.goto('some_directory') as ok:
         self.assertFalse(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with('some_directory')
         os.path.isdir.assert_called_with('some_directory')
         assert not os.chdir.called
     assert not os.chdir.called
Beispiel #3
0
 def test_existing(self, os):
     os.getcwd.return_value = 'foo'
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = True
     with shell.goto('some_directory') as ok:
         self.assertTrue(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with('some_directory')
         os.path.isdir.assert_called_with('some_directory')
         os.chdir.assert_called_with('some_directory')
     os.chdir.assert_called_with('foo')
Beispiel #4
0
 def test_non_existing_no_create(self, os):
     os.getcwd.return_value = "foo"
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = False
     with shell.goto("some_directory") as ok:
         self.assertFalse(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with("some_directory")
         os.path.isdir.assert_called_with("some_directory")
         assert not os.chdir.called
     assert not os.chdir.called
Beispiel #5
0
 def test_existing(self, os):
     os.getcwd.return_value = "foo"
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = True
     with shell.goto("some_directory") as ok:
         self.assertTrue(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with("some_directory")
         os.path.isdir.assert_called_with("some_directory")
         os.chdir.assert_called_with("some_directory")
     os.chdir.assert_called_with("foo")
Beispiel #6
0
 def test_with_throws_an_exception(self, os):
     os.getcwd.return_value = 'foo'
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = True
     with self.assertRaises(Exception):
         with shell.goto('some_directory') as ok:
             self.assertTrue(ok)
             os.getcwd.assert_called_with()
             os.path.abspath.assert_called_with('some_directory')
             os.path.isdir.assert_called_with('some_directory')
             os.chdir.assert_called_with('some_directory')
             raise Exception('Failed')
     os.chdir.assert_called_with('foo')
Beispiel #7
0
 def test_non_existing_create_failed(self, os):
     os.getcwd.return_value = 'foo'
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = False
     os.makedirs.side_effect = Exception('Failed to create')
     with shell.goto('some_directory', True) as ok:
         self.assertFalse(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with('some_directory')
         os.path.isdir.assert_called_with('some_directory')
         os.makedirs.assert_called_with('some_directory', 0o755)
         assert not os.chdir.called
     assert not os.chdir.called
Beispiel #8
0
 def test_with_throws_an_exception(self, os):
     os.getcwd.return_value = "foo"
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = True
     with self.assertRaises(Exception):
         with shell.goto("some_directory") as ok:
             self.assertTrue(ok)
             os.getcwd.assert_called_with()
             os.path.abspath.assert_called_with("some_directory")
             os.path.isdir.assert_called_with("some_directory")
             os.chdir.assert_called_with("some_directory")
             raise Exception("Failed")
     os.chdir.assert_called_with("foo")
Beispiel #9
0
 def test_non_existing_create_failed(self, os):
     os.getcwd.return_value = "foo"
     os.path.abspath.side_effect = lambda path: path
     os.path.isdir.return_value = False
     os.makedirs.side_effect = Exception("Failed to create")
     with shell.goto("some_directory", True) as ok:
         self.assertFalse(ok)
         os.getcwd.assert_called_with()
         os.path.abspath.assert_called_with("some_directory")
         os.path.isdir.assert_called_with("some_directory")
         os.makedirs.assert_called_with("some_directory", 0o755)
         assert not os.chdir.called
     assert not os.chdir.called
Beispiel #10
0
 def run(self, config):
     # Calculate the working dir
     working_dir = self.project.path if self.working_dir is None else os.path.join(self.project.path, self.working_dir)
     with shell.goto(working_dir) as ok:
         if not ok:
             error = 'Could not change directory to "%s"!' % working_dir
             logger.error(error)
             return 1, error, ''
         if self.type == Step.MSBUILD:
             return self._msbuild(config)
         elif self.type == Step.SHELL:
             return self._command(config)
         else:
             error = 'Don\'t know how to build %s projects!' % self.type
             logger.error(error)
             return 1, error, ''
Beispiel #11
0
def setup(module, target="zip", output_path=None, data_dir=None):
    dist = os.path.abspath("dist")
    try:
        if target == "zip":
            assert er(
                "setup.py",
                "install",
                "--no-compile",
                "--install-lib",
                os.path.join(dist, "lib"),
                "--install-scripts",
                os.path.join(dist),
                *(
                    ["--install-data", os.path.join(dist, data_dir)]
                    if data_dir is not None
                    else []
                ),
            )
            with shell.goto(dist) as ok:
                assert ok
                assert compress.mkzip(
                    "%s.zip" % module, glob.glob(os.path.join("lib", "*"))
                )
                assert shell.remove("lib")
        elif target == "exe":
            assert er(
                "setup.py",
                "install",
                "--no-compile",
                "--install-lib",
                os.path.join(dist, "lib", "python"),
                "--install-scripts",
                os.path.join(dist, "scripts"),
                *(
                    ["--install-data", os.path.join(dist, data_dir)]
                    if data_dir is not None
                    else []
                ),
            )
            with shell.goto(dist) as ok:
                assert ok

                modules = list(
                    filter(
                        os.path.exists,
                        ["lib", "scripts"]
                        + ([data_dir] if data_dir is not None else []),
                    )
                )
                assert compress.seven_zip(
                    "%s.exe" % module, modules, self_extracting=True
                )
                # Cleanup
                for module in modules:
                    assert shell.remove(module)
        if output_path is not None:
            output_path = os.path.abspath(output_path)
            if output_path != dist:
                if not os.path.isdir(output_path):
                    assert shell.mkdir(output_path)
                for filename in shell.search(dist, "*"):
                    output = os.path.join(
                        output_path, filename.replace(dist, "", 1).strip("\\/")
                    )
                    assert shell.move(filename, output)
        return 0
    except AssertionError as e:
        print(e)
        return 1
    finally:
        # Cleanup
        if output_path != dist:
            shell.remove(dist)
        if os.path.isdir("build"):
            shell.remove("build")