def _get_action_log_file(): global _ACTION_LOG_FILE if _ACTION_LOG_FILE is None: fp = os.path.join(get_otol_build_env('OPEN_TREE_DEPENDENCY_DIR'), 'log-bootstrap.txt') _LOG.debug('Opening "%s" as action log' % fp) fo = open(fp, 'a') _ACTION_LOG_FILE = fo return _ACTION_LOG_FILE
def do_download(self): parent_var = RESOURCE_CATEGORIES[self.category] parent_dir = get_otol_build_env(parent_var) assert parent_dir _my_makedirs(parent_dir) cwd = os.path.abspath(os.getcwd()) try: parent_dir = os.path.abspath(parent_dir) expected_path = os.path.join(parent_dir, self.compressed_name) _my_chdir(parent_dir) if self.protocol == 'http': if os.path.exists(expected_path): _LOG.warn('Path "%s" already exists. It will not be downloaded again...\n' % expected_path) fp = expected_path else: p = download_http(self.url) fp = os.path.join(parent_dir, p) self.compressed_path = fp expected_path = os.path.join(parent_dir, self.name) if os.path.exists(expected_path): if expected_path != fp: _LOG.warn('Path "%s" already exists. It will not be unpacked again...\n' % expected_path) fp = expected_path else: if self.compression == 'zip': _LOG.info('Unzipping "%s"...\n"' % fp) unzip_file(fp, parent_dir) fp = os.path.join(parent_dir, self.name) elif self.compression == 'tar.gz': _LOG.info('Unpacking "%s"...\n"' % fp) untar_gz(fp, parent_dir) fp = os.path.join(parent_dir, self.name) _LOG.info('Obtained "%s"...\n"' % fp) self.path = fp return fp elif self.protocol == 'svn': if os.path.exists(expected_path): _LOG.warn('Path "%s" already exists. It will not be downloaded again...\n' % fp) else: system_call(['svn', 'checkout', self.url, self.name]) self.path = expected_path self.compressed_path = self.path else: assert False self.status = RESOURCE_STATUS_CODE.DOWNLOADED finally: _my_chdir(cwd)
usage = '%%prog [options] <command> [resource]\nWhere <command> can be:\n%s\n\n' % command_list parser = OptionParser(usage=usage, add_help_option=True, version=_program_version, description=description) parser.add_option('--config', dest='config', default=None, metavar='FILEPATH', help='if specified, this path will be used to local filesystem paths. If not specified, the fallbacks will be $OPEN_TREE_DOWNLOAD_DEV_RESOURCE_CFG or ${OPEN_TREE_USER_SETTINGS_DIR}/download-dev-resource.cfg where ~/.open_tree is the default for ${OPEN_TREE_USER_SETTINGS_DIR}') (opts, args) = parser.parse_args() if len(args) < 1: sys.exit('Expecting at least one argument. Use -h for help') cfg_path = opts.config if not cfg_path: cfg_path = get_otol_build_env('OPEN_TREE_DOWNLOAD_DEV_RESOURCE_CFG') _LOG.debug('Config path is %s\n' % cfg_path) put_otol_build_env_into_env() command = args[0].lower() try: if command == 'list': list_command(opts) else: if len(args) < 2: if command == 'status': res_list = [i.name for i in get_flattened_resource_list()] else: sys.exit('Expecting a resource identifier after the "%s" command.' % command) else: