Beispiel #1
0
    def build(self):
        # setup build directory
        super(copy.CopyPlugin, self).build()

        files = self.options.files
        editables = self.options.edit
        globs = {f: files[f] for f in files if glob.has_magic(f)}
        filepaths = {
            os.path.join(self.builddir, f): files[f]
            for f in files if not glob.has_magic(f)
        }

        for edit in editables:
            fpath = os.path.join(self.builddir, edit)
            if os.path.exists(fpath):
                for regex in editables[edit]:
                    for line in fileinput.input([fpath], inplace=True):
                        r = re.compile(regex)
                        print(r.sub(editables[edit][regex], line.rstrip()))

        for src in globs:
            paths = glob.glob(os.path.join(self.builddir, src))
            if not paths:
                raise EnvironmentError('no matches for {!r}'.format(src))
            for path in paths:
                filepaths.update(
                    {os.path.join(self.builddir, path): globs[src]})

        for src in sorted(filepaths):
            dst = os.path.join(self.installdir, filepaths[src].lstrip('/'))
            os.makedirs(os.path.dirname(dst), exist_ok=True)
            _recursively_link(src, dst, self.installdir)
Beispiel #2
0
    def build(self):
        # setup build directory
        super(copy.CopyPlugin, self).build()

        files = self.options.files
        editables = self.options.edit
        globs = {f: files[f] for f in files if glob.has_magic(f)}
        filepaths = {os.path.join(self.builddir, f): files[f] for f in files
                     if not glob.has_magic(f)}

        for edit in editables:
            fpath = os.path.join(self.builddir, edit)
            if os.path.exists(fpath):
                for regex in editables[edit]:
                    for line in fileinput.input([fpath], inplace=True):
                        r = re.compile(regex)
                        print (r.sub(editables[edit][regex], line.rstrip()))

        for src in globs:
            paths = glob.glob(os.path.join(self.builddir, src))
            if not paths:
                raise EnvironmentError('no matches for {!r}'.format(src))
            for path in paths:
                filepaths.update(
                    {os.path.join(self.builddir, path): globs[src]})

        for src in sorted(filepaths):
            dst = os.path.join(self.installdir, filepaths[src].lstrip('/'))
            os.makedirs(os.path.dirname(dst), exist_ok=True)
            _recursively_link(src, dst, self.installdir)
Beispiel #3
0
 def test_recursively_link_directory_into_directory(self):
     os.mkdir('qux')
     _recursively_link('foo', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', 'foo', '2')))
     self.assertTrue(os.path.isfile(os.path.join('qux', 'foo', 'bar', '3')))
     self.assertTrue(
         os.path.isfile(os.path.join('qux', 'foo', 'bar', 'baz', '4')))
 def test_recursively_link_directory_into_directory(self):
     os.mkdir('qux')
     _recursively_link('foo', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', 'foo', '2')))
     self.assertTrue(os.path.isfile(os.path.join('qux', 'foo', 'bar', '3')))
     self.assertTrue(
         os.path.isfile(os.path.join('qux', 'foo', 'bar', 'baz', '4')))
Beispiel #5
0
    def test_recursively_link_file_into_dir_chown_permissions(self, chown_mock):
        chown_mock.side_effect = PermissionError("Nope")
        os.mkdir("qux")
        _recursively_link("1", "qux", os.getcwd())
        self.assertTrue(os.path.isfile(os.path.join("qux", "1")))

        self.assertTrue(chown_mock.called)
Beispiel #6
0
 def test_recursively_link_directory_into_directory(self):
     os.mkdir("qux")
     _recursively_link("foo", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "foo", "2")))
     self.assertTrue(os.path.isfile(os.path.join("qux", "foo", "bar", "3")))
     self.assertTrue(
         os.path.isfile(os.path.join("qux", "foo", "bar", "baz", "4")))
Beispiel #7
0
    def test_recursively_link_file_into_dir_chown_permissions(self,
                                                              chown_mock):
        chown_mock.side_effect = PermissionError('Nope')
        os.mkdir('qux')
        _recursively_link('1', 'qux', os.getcwd())
        self.assertTrue(os.path.isfile(os.path.join('qux', '1')))

        self.assertTrue(chown_mock.called)
Beispiel #8
0
    def test_recursively_link_directory_overwrite_file_raises(self):
        open('qux', 'w').close()
        with self.assertRaises(NotADirectoryError) as raised:
            _recursively_link('foo', 'qux', os.getcwd())

        self.assertEqual(
            str(raised.exception),
            "Cannot overwrite non-directory 'qux' with directory 'foo'")
Beispiel #9
0
    def test_recursively_link_file_into_dir_chown_permissions(
            self, chown_mock):
        chown_mock.side_effect = PermissionError('Nope')
        os.mkdir('qux')
        _recursively_link('1', 'qux', os.getcwd())
        self.assertTrue(os.path.isfile(os.path.join('qux', '1')))

        self.assertTrue(chown_mock.called)
    def test_recursively_link_directory_overwrite_file_raises(self):
        open('qux', 'w').close()
        with self.assertRaises(NotADirectoryError) as raised:
            _recursively_link('foo', 'qux', os.getcwd())

        self.assertEqual(
            str(raised.exception),
            "Cannot overwrite non-directory 'qux' with directory 'foo'")
Beispiel #11
0
    def test_recursively_link_file_into_dir_chown_permissions(
            self, chown_mock):
        chown_mock.side_effect = PermissionError("Nope")
        os.mkdir("qux")
        _recursively_link("1", "qux", os.getcwd())
        self.assertTrue(os.path.isfile(os.path.join("qux", "1")))

        self.assertTrue(chown_mock.called)
Beispiel #12
0
 def test_recursively_link_file_into_directory(self):
     os.mkdir('qux')
     _recursively_link('1', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', '1')))
Beispiel #13
0
 def test_recursively_link_file_to_file(self):
     _recursively_link('1', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile('qux'))
 def test_recursively_link_subtree(self):
     _recursively_link('foo/bar', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', '3')))
     self.assertTrue(os.path.isfile(os.path.join('qux', 'baz', '4')))
Beispiel #15
0
 def test_recursively_link_directory_into_directory(self):
     os.mkdir("qux")
     _recursively_link("foo", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "foo", "2")))
     self.assertTrue(os.path.isfile(os.path.join("qux", "foo", "bar", "3")))
     self.assertTrue(os.path.isfile(os.path.join("qux", "foo", "bar", "baz", "4")))
 def test_recursively_link_file_to_file(self):
     _recursively_link('1', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile('qux'))
 def test_recursively_link_file_into_directory(self):
     os.mkdir('qux')
     _recursively_link('1', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', '1')))
Beispiel #18
0
 def test_recursively_link_subtree(self):
     _recursively_link("foo/bar", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "3")))
     self.assertTrue(os.path.isfile(os.path.join("qux", "baz", "4")))
Beispiel #19
0
 def test_recursively_link_file_into_directory(self):
     os.mkdir("qux")
     _recursively_link("1", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "1")))
Beispiel #20
0
 def test_recursively_link_subtree(self):
     _recursively_link("foo/bar", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "3")))
     self.assertTrue(os.path.isfile(os.path.join("qux", "baz", "4")))
Beispiel #21
0
 def test_recursively_link_file_into_directory(self):
     os.mkdir("qux")
     _recursively_link("1", "qux", os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join("qux", "1")))
Beispiel #22
0
 def test_recursively_link_file_to_file(self):
     _recursively_link("1", "qux", os.getcwd())
     self.assertTrue(os.path.isfile("qux"))
Beispiel #23
0
 def test_recursively_link_subtree(self):
     _recursively_link('foo/bar', 'qux', os.getcwd())
     self.assertTrue(os.path.isfile(os.path.join('qux', '3')))
     self.assertTrue(os.path.isfile(os.path.join('qux', 'baz', '4')))
Beispiel #24
0
 def test_recursively_link_file_to_file(self):
     _recursively_link("1", "qux", os.getcwd())
     self.assertTrue(os.path.isfile("qux"))