def handle_template(template_file, output, template_dirs): log.info("handling %s" % template_file) template_file_on_disk = find_file_in_template_dirs(template_file, template_dirs) if template_file_on_disk is None: if template_file.endswith("**"): source_dir = template_file[:-3] src_path = find_file_in_template_dirs(source_dir, template_dirs) if src_path: for a_triple in _listing_directory_files_recusively( source_dir, src_path, output): yield a_triple else: reporter.report_error_message( "{0} cannot be found".format(template_file)) else: reporter.report_error_message( "{0} cannot be found".format(template_file)) elif os.path.isdir(template_file_on_disk): for a_triple in _list_dir_files(template_file, template_file_on_disk, output): yield a_triple else: template_type = _get_template_type(template_file) yield (template_file, output, template_type)
def main(): """ program entry point """ parser = create_parser() options = vars(parser.parse_args()) HASH_STORE.IGNORE_CACHE_FILE = options[constants.LABEL_FORCE] moban_file = options[constants.LABEL_MOBANFILE] if moban_file is None: moban_file = mobanfile.find_default_moban_file() if moban_file: try: count = handle_moban_file(moban_file, options) if count: sys.exit(count) except ( exceptions.DirectoryNotFound, exceptions.NoThirdPartyEngine, exceptions.MobanfileGrammarException, ) as e: reporter.report_error_message(str(e)) sys.exit(constants.ERROR) else: try: count = handle_command_line(options) if count: sys.exit(count) except exceptions.NoTemplate as e: reporter.report_error_message(str(e)) sys.exit(constants.ERROR)
def _copy(self, src_path, dest): dest_folder = os.path.dirname(dest) if dest_folder: utils.mkdir_p(dest_folder) reporter.report_copying(src_path, dest) try: shutil.copy(src_path, dest) self._count = self._count + 1 except PermissionError: reporter.report_error_message("No permission to write %s" % dest)
def get_repo_name(repo_url): import giturlparse from giturlparse.parser import ParserError try: repo = giturlparse.parse(repo_url) return repo.name except ParserError: reporter.report_error_message(constants.MESSAGE_INVALID_GIT_URL % repo_url) raise
def get_repo_name(repo_url): import giturlparse try: repo = giturlparse.parse(repo_url) name = repo.repo if name.endswith("/"): name = name[:-1] return name except AttributeError: reporter.report_error_message(constants.MESSAGE_INVALID_GIT_URL % repo_url) raise
def copy_files(self, file_list): for dest, src in _iterate_list_of_dicts(file_list): src_path = self._get_src_file(src) if src_path is None: if src.endswith("**"): source_dir = src[:-3] src_path = self._get_src_file(source_dir) if src_path: self._copy_dir_recursively(src[:-3], src_path, dest) else: reporter.report_error_message( "{0} cannot be found".format(source_dir)) else: reporter.report_error_message( "{0} cannot be found".format(src)) elif os.path.isdir(src_path): self._copy_dir(src, src_path, dest) elif HASH_STORE.are_two_file_different(src_path, dest): self._increment_file_count() self._copy(src_path, dest)
def test_error_message(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() reporter.report_error_message("something wrong") patcher.stop() eq_(fake_stdout.getvalue(), "Error: something wrong\n")