示例#1
0
    def test_get_appet_with_asset(self):
        bundle_name = "test-bundle-depends.tar.gz"
        bundle_tmp_dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(bundle_tmp_dir, "a"))
        with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle:
            file_in_bundle.write('foo\n')
        subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name),
                               '-C', os.path.join(bundle_tmp_dir, 'a'), '.'])
        bundle_file = dxpy.upload_local_file(filename=os.path.join(bundle_tmp_dir, bundle_name),
                                             project=self.project,
                                             wait_on_close=True)

        asset_file = dxpy.upload_local_file(filename=os.path.join(bundle_tmp_dir, bundle_name),
                                            project=self.project,
                                            wait_on_close=True)

        dxrecord_details = {"archiveFileId": {"$dnanexus_link": asset_file.get_id()}}
        dxrecord = dxpy.new_dxrecord(project=self.project, types=["AssetBundle"], details=dxrecord_details,
                                     name='asset-lib-test', properties={"version": "0.0.1"})
        dxrecord.close()
        asset_bundle_id = dxrecord.get_id()

        asset_file.set_properties({"AssetBundle": asset_bundle_id})

        code_str = """#!/bin/bash
                    main(){
                        echo 'Hello World'
                    }
                    """
        app_spec = {
            "name": "asset_depends",
            "dxapi": "1.0.0",
            "runSpec": {
                "code": code_str,
                "interpreter": "bash",
                "assetDepends":  [{"id": asset_bundle_id}],
                "bundledDepends": [{"name": bundle_name, "id": {"$dnanexus_link": bundle_file.get_id()}}]
            },
            "inputSpec": [],
            "outputSpec": [],
            "version": "1.0.0"
        }
        app_dir = self.write_app_directory("asset_depends", json.dumps(app_spec))
        asset_applet_id = json.loads(run("dx build --json {app_dir}".format(app_dir=app_dir)))["id"]
        with chdir(tempfile.mkdtemp()):
            run("dx get --omit-resources " + asset_applet_id)
            self.assertTrue(os.path.exists("asset_depends"))
            self.assertFalse(os.path.exists(os.path.join("asset_depends", "resources")))
            self.assertTrue(os.path.exists(os.path.join("asset_depends", "dxapp.json")))

            applet_spec = json.load(open(os.path.join("asset_depends", "dxapp.json")))
            self.assertEqual([{"name": "asset-lib-test",
                               "project": self.project,
                               "folder": "/",
                               "version": "0.0.1"}
                              ],
                             applet_spec["runSpec"]["assetDepends"])
            self.assertEqual([{"name": bundle_name, "id": {"$dnanexus_link": bundle_file.get_id()}}],
                             applet_spec["runSpec"]["bundledDepends"])
示例#2
0
 def test_file_name_with_special_chars_locally(self):
     # create a tar.gz file with spaces, quotes and escape chars in its name
     bundle_name = "test 'bundle' \"with\" \"@#^&%()[]{}\" spaces.tar.gz"
     bundle_tmp_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(bundle_tmp_dir, "a"))
     with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle:
         file_in_bundle.write('foo\n')
     subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name),
                            '-C', os.path.join(bundle_tmp_dir, 'a'), '.'])
     extract_tmp_dir = tempfile.mkdtemp()
     with chdir(extract_tmp_dir):
         subprocess.check_call(["dx-unpack", os.path.join(bundle_tmp_dir, bundle_name)])
         self.assertTrue(os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt')))
示例#3
0
 def test_remove_file_after_unpack(self):
     # dx-unpack removes the file after unpacking
     bundle_name = "tarball.tar.gz"
     bundle_tmp_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(bundle_tmp_dir, "a"))
     with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle:
         file_in_bundle.write('foo\n')
     subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name),
                            '-C', os.path.join(bundle_tmp_dir, 'a'), '.'])
     extract_tmp_dir = tempfile.mkdtemp()
     with chdir(extract_tmp_dir):
         subprocess.check_call(["dx-unpack", os.path.join(bundle_tmp_dir, bundle_name)])
         self.assertTrue(os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt')))
         shutil.rmtree(os.path.join(bundle_tmp_dir, "a"))
         self.assertFalse(os.path.exists(os.path.join(bundle_tmp_dir, bundle_name)))
示例#4
0
 def test_file_name_with_special_chars_locally(self):
     # create a tar.gz file with spaces, quotes and escape chars in its name
     bundle_name = "test 'bundle' \"with\" \"@#^&%()[]{}\" spaces.tar.gz"
     bundle_tmp_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(bundle_tmp_dir, "a"))
     with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'),
               'w') as file_in_bundle:
         file_in_bundle.write('foo\n')
     subprocess.check_call([
         'tar', '-czf',
         os.path.join(bundle_tmp_dir, bundle_name), '-C',
         os.path.join(bundle_tmp_dir, 'a'), '.'
     ])
     extract_tmp_dir = tempfile.mkdtemp()
     with chdir(extract_tmp_dir):
         subprocess.check_call(
             ["dx-unpack",
              os.path.join(bundle_tmp_dir, bundle_name)])
         self.assertTrue(
             os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt')))
示例#5
0
 def test_remove_file_after_unpack(self):
     # dx-unpack removes the file after unpacking
     bundle_name = "tarball.tar.gz"
     bundle_tmp_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(bundle_tmp_dir, "a"))
     with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'),
               'w') as file_in_bundle:
         file_in_bundle.write('foo\n')
     subprocess.check_call([
         'tar', '-czf',
         os.path.join(bundle_tmp_dir, bundle_name), '-C',
         os.path.join(bundle_tmp_dir, 'a'), '.'
     ])
     extract_tmp_dir = tempfile.mkdtemp()
     with chdir(extract_tmp_dir):
         subprocess.check_call(
             ["dx-unpack",
              os.path.join(bundle_tmp_dir, bundle_name)])
         self.assertTrue(
             os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt')))
         shutil.rmtree(os.path.join(bundle_tmp_dir, "a"))
         self.assertFalse(
             os.path.exists(os.path.join(bundle_tmp_dir, bundle_name)))
示例#6
0
    def test_get_appet_with_asset(self):
        bundle_name = "test-bundle-depends.tar.gz"
        bundle_tmp_dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(bundle_tmp_dir, "a"))
        with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'),
                  'w') as file_in_bundle:
            file_in_bundle.write('foo\n')
        subprocess.check_call([
            'tar', '-czf',
            os.path.join(bundle_tmp_dir, bundle_name), '-C',
            os.path.join(bundle_tmp_dir, 'a'), '.'
        ])
        bundle_file = dxpy.upload_local_file(filename=os.path.join(
            bundle_tmp_dir, bundle_name),
                                             project=self.project,
                                             wait_on_close=True)

        asset_file = dxpy.upload_local_file(filename=os.path.join(
            bundle_tmp_dir, bundle_name),
                                            project=self.project,
                                            wait_on_close=True)

        dxrecord_details = {
            "archiveFileId": {
                "$dnanexus_link": asset_file.get_id()
            }
        }
        dxrecord = dxpy.new_dxrecord(project=self.project,
                                     types=["AssetBundle"],
                                     details=dxrecord_details,
                                     name='asset-lib-test',
                                     properties={"version": "0.0.1"})
        dxrecord.close()
        asset_bundle_id = dxrecord.get_id()

        asset_file.set_properties({"AssetBundle": asset_bundle_id})

        code_str = """#!/bin/bash
                    main(){
                        echo 'Hello World'
                    }
                    """
        app_spec = {
            "name": "asset_depends",
            "dxapi": "1.0.0",
            "runSpec": {
                "code":
                code_str,
                "interpreter":
                "bash",
                "distribution":
                "Ubuntu",
                "release":
                "14.04",
                "assetDepends": [{
                    "id": asset_bundle_id
                }],
                "bundledDepends": [{
                    "name": bundle_name,
                    "id": {
                        "$dnanexus_link": bundle_file.get_id()
                    }
                }]
            },
            "inputSpec": [],
            "outputSpec": [],
            "version": "1.0.0"
        }
        app_dir = self.write_app_directory("asset_depends",
                                           json.dumps(app_spec))
        asset_applet_id = json.loads(
            run("dx build --json {app_dir}".format(app_dir=app_dir)))["id"]
        with chdir(tempfile.mkdtemp()):
            run("dx get --omit-resources " + asset_applet_id)
            self.assertTrue(os.path.exists("asset_depends"))
            self.assertFalse(
                os.path.exists(os.path.join("asset_depends", "resources")))
            self.assertTrue(
                os.path.exists(os.path.join("asset_depends", "dxapp.json")))
            with open(os.path.join("asset_depends", "dxapp.json")) as fh:
                applet_spec = json.load(fh)
            self.assertEqual([{
                "name": "asset-lib-test",
                "project": self.project,
                "folder": "/",
                "version": "0.0.1"
            }], applet_spec["runSpec"]["assetDepends"])
            self.assertEqual([{
                "name": bundle_name,
                "id": {
                    "$dnanexus_link": bundle_file.get_id()
                }
            }], applet_spec["runSpec"]["bundledDepends"])
示例#7
0
 def setUp(self):
     self.wd = tempfile.mkdtemp()
     chdir(self.wd)
     setUpTempProject(self)