summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcleopatre/bundle_delivery.py28
-rwxr-xr-xcleopatre/devkit/tests/bundle_delivery/test_bundle_delivery.py15
2 files changed, 22 insertions, 21 deletions
diff --git a/cleopatre/bundle_delivery.py b/cleopatre/bundle_delivery.py
index c9ef774cfe..0631cbb098 100755
--- a/cleopatre/bundle_delivery.py
+++ b/cleopatre/bundle_delivery.py
@@ -8,6 +8,7 @@ files between bundle versions, or publishing a bundle and its associated files.
import datetime
import git
+import glob
import os
import re
import shutil
@@ -19,11 +20,11 @@ import tempfile
# The path to the bundle storage area.
BUNDLE_STORAGE_PATH = "//GEVREY/LIVRAISONS"
-# In the bundle storage, the directory where SPC300 bundles are stored.
-BUNDLE_STORAGE_SPC300_BUNDLES_DIR = "SPC300/SPiDBundle"
-# In the bundle storage, the format of the name of a each directory containing
+# In the bundle storage, the directory where bundles are stored.
+BUNDLE_STORAGE_BUNDLES_DIR = "SPiDBundle"
+# In the bundle storage, the format of the path to a directory containing
# a bundle.
-BUNDLE_STORAGE_BUNDLE_DIR_FMT = "{date}_SPiDBundle_{tagname}"
+BUNDLE_STORAGE_BUNDLE_DIR_FMT = "{project}/{date}_SPiDBundle_{tagname}"
# In the bundle storage, the format of the filename of a bundle.
BUNDLE_STORAGE_BUNDLE_FILE_FMT = "SPiDBundle-{tagname}.tar.bz2"
# The format of the filename of the resulting diff between two bundles.
@@ -39,13 +40,14 @@ class BundleStorage:
def __init__(self, dir_):
"""Instantiate.
- dir_: the directory where the SPC300 bundles are stored.
+ dir_: the directory where the bundles are stored.
"""
self._dir = dir_
def _create_bundle_dir(self, tag):
"""Create the bundle directory for a tag."""
bundle_dir = BUNDLE_STORAGE_BUNDLE_DIR_FMT.format(
+ project=tag.project,
date=datetime.date.today().strftime("%Y_%m_%d"),
tagname=tag.name)
bundle_dir = os.path.join(self._dir, bundle_dir)
@@ -72,14 +74,10 @@ class BundleStorage:
def _get_bundle_dir(self, tag):
"""Get the bundle directory for a tag."""
- b_re = re.compile(
- BUNDLE_STORAGE_BUNDLE_DIR_FMT.format(date=".*", tagname=tag.name))
- bundle_dirs = []
- for d in os.listdir(self._dir):
- if b_re.match(d):
- bundle_dirs.append(os.path.join(self._dir, d))
- # Don't break yet. Continue, to see if we find other
- # directories (which we shouldn't!)
+ bundle_path = os.path.join(self._dir,
+ BUNDLE_STORAGE_BUNDLE_DIR_FMT.format(
+ project=tag.project, date="*", tagname=tag.name))
+ bundle_dirs = glob.glob(bundle_path)
nb = len(bundle_dirs)
if nb > 1:
raise RuntimeError(
@@ -100,10 +98,10 @@ class BundleStorage:
dir_ = cls._find_in_mounted_filesystems()
if dir_ is None:
dir_ = raw_input("Path to bundle storage?\n--> ")
- dir_ = os.path.join(dir_, BUNDLE_STORAGE_SPC300_BUNDLES_DIR)
+ dir_ = os.path.join(dir_, BUNDLE_STORAGE_BUNDLES_DIR)
if not os.path.exists(dir_):
raise RuntimeError(
- "Cannot find SPC300 bundle storage: \"{0}\"".format(dir_))
+ "Cannot find bundle storage: \"{0}\"".format(dir_))
return cls(dir_)
def get_bundle(self, tag, dest_dir):
diff --git a/cleopatre/devkit/tests/bundle_delivery/test_bundle_delivery.py b/cleopatre/devkit/tests/bundle_delivery/test_bundle_delivery.py
index 7357fcf935..6ea7764684 100755
--- a/cleopatre/devkit/tests/bundle_delivery/test_bundle_delivery.py
+++ b/cleopatre/devkit/tests/bundle_delivery/test_bundle_delivery.py
@@ -66,6 +66,7 @@ class TestBundleStorage(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp(prefix='test-bundle-delivery-')
+ os.mkdir(os.path.join(self.temp_dir, "av"))
def test_get_bundle(self):
b = BundleStorage(self.temp_dir)
@@ -89,21 +90,23 @@ class TestBundleStorage(unittest.TestCase):
expected_dir = "{0}_SPiDBundle_av-1.2.1".format(
datetime.date.today().strftime("%Y_%m_%d"))
- self.assertEqual([expected_dir], os.listdir(self.temp_dir))
- self.assertEqual(3,
- len(os.listdir(os.path.join(self.temp_dir, expected_dir))))
+ self.assertEqual(["av"], os.listdir(self.temp_dir))
+ self.assertEqual([expected_dir],
+ os.listdir(os.path.join(self.temp_dir, "av")))
+ self.assertEqual(
+ 3, len(os.listdir(os.path.join(self.temp_dir, "av", expected_dir))))
self.assertTrue(
filecmp.cmp("testfiles/SPiDBundle-av-1.2.1.tar.bz2",
- os.path.join(self.temp_dir, expected_dir,
+ os.path.join(self.temp_dir, "av", expected_dir,
"SPiDBundle-av-1.2.1.tar.bz2")))
self.assertTrue(
filecmp.cmp("testfiles/plc-with-traces.rom",
- os.path.join(self.temp_dir, expected_dir,
+ os.path.join(self.temp_dir, "av", expected_dir,
"plc-with-traces.rom")))
self.assertTrue(
filecmp.cmp("testfiles/SPiDBundle-av-1.2.0-av-1.2.1.diff",
os.path.join(
- self.temp_dir, expected_dir,
+ self.temp_dir, "av", expected_dir,
"SPiDBundle-av-1.2.0-av-1.2.1.diff")))
def tearDown(self):