def add(self, package, *filenames, **kwargs): """Add a new package to the project. package is the name of the directory which will be added. A ValueError is raised if package is already tracked or if package is already an osc working copy. Also if prj/package does not exist or is no directory a ValueError is raised. If filenames are specified they are added to package. If no filenames are specified all files will be added to the package. A ValueError is raised if filenames and no_files=True is specified. Keyword arguments: no_files -- add no files (default: False) """ super(Project, self).add(package) no_files = kwargs.get('no_files', False) if filenames and no_files: raise ValueError("filenames and no_files are mutually exclusive") with wc_lock(self.path): if self._status(package) != '?': raise ValueError("package \"%s\" is already tracked" % package) pkg_path = os.path.join(self.path, package) if not os.path.isdir(pkg_path): raise ValueError("path \"%s\" is no dir" % pkg_path) elif wc_is_project(pkg_path) or wc_is_package(pkg_path): msg = ("path \"%s\" is already an initialized" "working copy" % pkg_path) raise ValueError(msg) storedir = wc_pkg_data_mkdir(self.path, package) pkg = Package.init(pkg_path, self.name, package, self.apiurl, ext_storedir=storedir) self._packages.add(package, state='A') self._packages.write() if no_files: filenames = [] elif not filenames: filenames = [f for f in os.listdir(pkg.path) if os.path.isfile(os.path.join(pkg.path, f))] for filename in filenames: pkg.add(filename)
def _perform_adds(self, ustate, **kwargs): uinfo = ustate.info tl = self.notifier.listener for package in uinfo.added: tmp_dir = os.path.join(ustate.location, package) storedir = wc_pkg_data_filename(self.path, package) if ustate.state == UpdateStateMixin.STATE_PREPARE: os.mkdir(storedir) pkg = Package.init(tmp_dir, self.name, package, self.apiurl, storedir, transaction_listener=tl) pkg.update(**kwargs) ustate.state = UpdateStateMixin.STATE_UPDATING # fixup symlink new_dir = os.path.join(self.path, package) path = os.path.relpath(storedir, new_dir) old_storelink = _storedir(tmp_dir) if os.path.isdir(tmp_dir): if os.path.exists(old_storelink): os.unlink(old_storelink) os.symlink(path, old_storelink) os.rename(tmp_dir, new_dir) ustate.processed(package, ' ') self.notifier.processed(package, ' ', None)