mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-13 03:10:03 -05:00
Make GlobCopier support nested paths.
This commit is contained in:
+12
-5
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import argparse, glob, shutil, os.path
|
||||
import argparse, glob, shutil, os, os.path
|
||||
|
||||
def Main(projectName, stagingFunction):
|
||||
"""Main should be called by all staging scripts when executed.
|
||||
@@ -35,10 +35,17 @@ def Main(projectName, stagingFunction):
|
||||
def GlobCopier(*globs):
|
||||
exclude = ('webpack.config.js',)
|
||||
def stage(stagingDir):
|
||||
for g in globs:
|
||||
for f in glob.glob(g):
|
||||
if os.path.split(f)[1] not in exclude:
|
||||
shutil.copy2(f, stagingDir)
|
||||
for pattern in globs:
|
||||
for f in glob.glob(pattern):
|
||||
if os.path.isdir(f):
|
||||
continue
|
||||
fromDir, name = os.path.split(f)
|
||||
if name in exclude:
|
||||
continue
|
||||
toDir = os.path.join(stagingDir, fromDir)
|
||||
if not os.path.exists(toDir):
|
||||
os.makedirs(toDir)
|
||||
shutil.copy2(f, toDir)
|
||||
return stage
|
||||
|
||||
|
||||
|
||||
@@ -42,16 +42,55 @@ class TestStaging(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_GlobCopier(self):
|
||||
for name in ('a.js', 'b.js', 'c.html', 'd.css', 'webpack.config.js'):
|
||||
files = (
|
||||
'a.js',
|
||||
'b.js',
|
||||
'c.html',
|
||||
'd.css',
|
||||
'webpack.config.js',
|
||||
|
||||
'x/aa.js',
|
||||
'x/bb.js',
|
||||
'x/dd.css',
|
||||
'x/webpack.config.js',
|
||||
|
||||
'x/xx/aaa.js',
|
||||
'x/xx/bbb.js',
|
||||
'x/xx/webpack.config.js',
|
||||
|
||||
'x/yy/aaa.js',
|
||||
'x/yy/bbb.js',
|
||||
'x/yy/webpack.config.js',
|
||||
|
||||
'y/aaaa.js',
|
||||
'y/bbbb.js',
|
||||
'y/webpack.config.js',
|
||||
|
||||
'y/xxx/a5.js',
|
||||
'y/xxx/b5.js',
|
||||
'y/xxx/webpack.config.js',
|
||||
|
||||
'z/a6.js',
|
||||
'z/b6.js',
|
||||
'z/webpack.config.js',
|
||||
)
|
||||
for d in ('x/xx', 'x/yy', 'y/xxx', 'z'):
|
||||
os.makedirs(os.path.join(self.tempdir, d))
|
||||
for name in files:
|
||||
with open(os.path.join(self.tempdir, name), 'w') as f:
|
||||
f.write('hi')
|
||||
|
||||
cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(self.tempdir)
|
||||
staging.GlobCopier('*.js', 'c.html')(self.nested)
|
||||
staging.GlobCopier('*.js', 'c.html', 'x/*.js', 'x/xx/*', 'y/*', 'y/*')(self.nested)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
self.assertEqual(['a.js', 'b.js', 'c.html'], os.listdir(self.nested))
|
||||
|
||||
self.assertEqual(['a.js', 'b.js', 'c.html', 'x', 'y'], os.listdir(self.nested))
|
||||
self.assertEqual(['aa.js', 'bb.js', 'xx'], os.listdir(os.path.join(self.nested, 'x')))
|
||||
self.assertEqual(['aaa.js', 'bbb.js'], os.listdir(os.path.join(self.nested, 'x/xx')))
|
||||
self.assertEqual(['aaaa.js', 'bbbb.js'], os.listdir(os.path.join(self.nested, 'y')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user