def upload(request, data=None, phome=None, con_len=None): try: err = {} tmp_fname = get_random_name() if not os.path.exists(config.tmp_dir): os.makedirs(config.tmp_dir) tmp_fpath = os.path.join(config.tmp_dir, tmp_fname) tmp_dirpath = tmp_fpath + '_dir' package_data = StringIO(data) if data \ else StringIO(request.raw_post_data) username = request.user.username package_home = phome or package_data.readline().strip() package_home = '.'.join([username, package_home]).strip('.') content_length = con_len or int(package_data.readline().strip()) store_file(tmp_fpath, package_data, content_length, config.chunk_size) callback_fn = make_parse_fn(request, err) num_package_dirs = add_packages_from_zip(tmp_fpath, tmp_dirpath, package_home, config.repo_dir, callback_fn) except RepositoryException, e: return apiresponse(e.message, 'err')
def extract_zip(zip_fpath, dir_path=None): if not dir_path: dirname = get_random_name() dir_path = os.path.join(get_tmp_dir(), dirname) unzip_file_into_dir(open(zip_fpath, 'rb'), dir_path) return dir_path
def _upload_package_dir(self, package_dir_path, package_home): tmp_fname = get_random_name() tmp_fpath = os.path.join(get_tmp_dir(), tmp_fname) try: zip_dir(package_dir_path, tmp_fpath) response = self._upload_package_zip(tmp_fpath, package_home) return response finally: if os.path.exists(tmp_fpath): os.remove(tmp_fpath)
def _download_package(self, class_id, package_version): zip_fpath = os.path.join(get_tmp_dir(), get_random_name()) try: CLIENT.repo_uri = self.uri CLIENT.download(zip_fpath, class_id, package_version) repo_dirpath = self._get_repo_dir() package_id = self._get_package_id(class_id, package_version) package_home = '.'.join(package_id.split('.')[:-1]) add_package(zip_fpath, package_home, repo_dirpath) finally: if os.path.exists(zip_fpath): os.remove(zip_fpath)