def buildArchive(self, archive_dir, remote_path=None, archive_root=None, archive_name=None, analyze=True): """Create a tar gz archive in archive_dir.""" if analyze: self.analyze(force=True) products = self.products products_ready = True for product in products: if product.status != 'use_tag': logger.error('Product %s not ready to be archived.' % product.path) product.showAction() products_ready = False if not products_ready: return -1 if archive_name is None: archive_name = '%s.tgz' % self.release_tag archive_path = os.path.join(archive_dir, archive_name) logger.info('Creating archive: %s' % archive_path) if not archive_root: # archive root is the root folder inside the archive archive_root = self.release_tag # extract tag tmpdir = mkdtemp() bundle_name = self.release_tag bundle_path = os.path.join(tmpdir, archive_root) bundle_tag_url = computeTagUrl(self.bundle_url, bundle_name) command('svn -q export %s %s' % (bundle_tag_url, bundle_path)) if not os.path.exists(bundle_path): # svn export don't complain on invalid url logger.error('Tag %s not found, use --release first.' % bundle_tag_url) return -1 # prepare bundle and products self.prepareBundleArchive(bundle_path, bundle_name) # add MD5SUMS command('cd %s; find . -type f -not -name MD5SUMS -print0 ' '| xargs -0 md5sum > MD5SUMS' % bundle_path) # tarball command('cd %s; tar czf %s %s' % (tmpdir, archive_path, archive_root)) command('rm -rf %s' % tmpdir) command('chmod 644 %s' % archive_path) logger.info('Archive: %s ready.' % archive_path) if remote_path: logger.info("scp archive to %s" % remote_path) command("scp %s %s" % (archive_path, remote_path)) return 0
def branch(self): """Create a branch for all products from a bundle tag.""" release_tag = self.release_tag hash_tag = getHashTag(release_tag) bundle_tag_url = computeTagUrl(self.bundle_url, release_tag) if not bundle_tag_url: logger.error('Invalid source url: %s' % self.bundle_url) return -1 bundle_branch_url = bundle_tag_url.replace('/tags/', '/branches/') logger.info('Branching %s -> %s hash_tag: %s.' % (bundle_tag_url, bundle_branch_url, hash_tag)) ret, output = command('svn ls %s' % bundle_tag_url, do_raise=False) if ret: logger.error('Tag not found. You need to release %s first.' % release_tag) return -1 ret, output = command('svn ls %s' % bundle_branch_url, do_raise=False) if not ret: logger.error('Branch %s already exists.' % bundle_branch_url) return -1 products = self.listProducts(bundle_tag_url) branch_products = [] # create a branch for each product for product in products: product_url = product['url'] parent = os.path.dirname(product_url) ret = -1 if os.path.basename(parent) == 'tags': ret, output = command('svn ls %s/CHANGES' % product_url, do_raise=False) if ret: # not a versionned product keep it asis branch_products.append(product) continue branch_url = os.path.dirname(parent) + '/branches/' + hash_tag ret, output = command('svn ls %s' % branch_url, do_raise=False) if not ret: logger.warning('Branch %s already exists.' % branch_url) else: command('svn copy -m"bundleman branch product %s release %s"' '-r%s %s %s' % (product['path'], hash_tag, product['revision'], product_url, branch_url)) branch_products.append({'path': product['path'], 'url': branch_url}) # create a bundle branch logger.info('Creating bundle %s' % bundle_branch_url) createBundle(bundle_branch_url, branch_products, release_tag) return bundle_branch_url
def computeTagUrl(self): """Using version file guess the tag url of the product.""" co_url = self.url if self.version_new and self.version_new[1]: tag = self.version_new[1] else: tag = self.version[1] if not tag: return co_url if not self.bm_versioned: return co_url package_url = computeTagUrl(co_url, tag) if not package_url: return co_url return package_url
def tag(self): """Create a bundle tags/release_tag.""" release_tag = self.release_tag logger.info('Create a bundle tag %s' % release_tag) # check bundle url bundle_url = self.bundle_url tag_url = computeTagUrl(bundle_url, release_tag) if tag_url is None: logger.error('Invalid bundle url: %s' % bundle_url) return -1 ret, output = command('svn ls %s' % tag_url, do_raise=False) if not ret: logger.error('Bundle tag %s already exists.' % tag_url) return -1 # analyze products self.analyze(force=True) bad_products = [] products = [] for product in self.products: if product.status != 'use_tag': bad_products.append(product) products.append({'path': product.rpath, 'revision': product.revision, 'url': product.tag_url}) if bad_products: logger.warning('Sorry found product(s) not ready:') for product in bad_products: print str(product) return -1 # create bundle logger.info('Creating bundle %s' % tag_url) createBundle(tag_url, products, release_tag, bundle_url) return 0