Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pages on linux available for macos #12545

Open
46 tasks
vitorhcl opened this issue Mar 23, 2024 · 2 comments
Open
46 tasks

pages on linux available for macos #12545

vitorhcl opened this issue Mar 23, 2024 · 2 comments

Comments

@vitorhcl
Copy link
Member

vitorhcl commented Mar 23, 2024

I made a simple script that hits https://keith.github.io/xcode-man-pages for checking if the linux pages are available on macOS, printing the ones that return 200 and are not already present on common.

However, we can't simply move them to common, because we have to check if there are any difference between platforms.

Missing pages on section 1:

  • brctl →
  • chfn →
  • colrm →
  • compress →
  • csplit →
  • diff3 →
  • expect →
  • fuser →
  • getconf →
  • getopt →
  • gzexe →
  • ipcrm →
  • lastcomm →
  • libtool →
  • locale →
  • login →
  • manpath →
  • ncal →
  • newgrp →
  • postconf →
  • postfix →
  • reset →
  • size →
  • snmpwalk →
  • strip →
  • talk →
  • tftp →
  • ul →
  • uncompress →
  • unset →
  • unzipsfx →
  • wall →
  • zforce →
  • zipcloak → zipcloak: move to common and replace "zipfile" #12543
  • zipsplit → zipsplit: improve page #12544

Missing pages on section 5: This section is for file formats

Missing pages on section 8:

  • edquota →
  • fdisk →
  • halt →
  • iostat →
  • mknod →
  • nologin →
  • quotacheck →
  • repquota →
  • rpcinfo →
  • sa →
  • vipw →
The script
import argparse
import asyncio
from aiopath import AsyncPath
import aiohttp
from random import shuffle
from aioconsole import aprint


async def list_files(directory):
  files = [file async for file in AsyncPath(directory).iterdir() if file.is_file()]
  return files


async def fetch_data(file, url):
  async with aiohttp.ClientSession() as session:
      async with session.get(url) as response:
          return file, response.status


async def print_response(file, status_code, url):
  color = "\033[32m" if status_code == 200 else "\033[31m"
  reset_color = "\033[0m"
  formatted_code = f"{color}{status_code}{reset_color}"
  await aprint(
      f"File: {file.name[:-3]}; Response code: {formatted_code}; Link: {url}"
  )


async def process_file(file, url):
  file, status_code = await fetch_data(file, url)
  if status_code == 200:
      await print_response(file, status_code, url)
      return file.stem  # Return the file stem if status code is 200


async def fetch_and_print_file_data(
  linux_directory, common_directory, macos_directory, manual_section
):
  files = await list_files(linux_directory)
  present_files = [file.stem for file in await list_files(common_directory)]
  present_files.extend(file.stem for file in await list_files(macos_directory))

  await aprint(files)
  url_template = (
      "https://keith.github.io/xcode-man-pages/{}." + manual_section + ".html"
  )
  links = [
      (file, url_template.format(file.stem))
      for file in files
      if file.stem not in present_files
  ]
  shuffle(links)

  tasks = []
  for file, url in links:
      task = process_file(file, url)
      tasks.append(task)

  file_stems = await asyncio.gather(*tasks)
  todo_list = sorted(set(filter(None, file_stems)))

  await aprint(f"\nMissing pages on section {manual_section}:")
  for stem in todo_list:
      await aprint(f"- [ ] {stem} →")


async def main():
  parser = argparse.ArgumentParser()
  parser.add_argument(
      "tldr_root", type=AsyncPath, help="Root directory of TLDR pages"
  )
  parser.add_argument(
      "manual_section",
      help="Hit manual section 1, 5 or 8",
      choices=["1", "5", "8"],
  )
  args = parser.parse_args()

  pages_directory = AsyncPath(args.tldr_root) / "pages"

  await fetch_and_print_file_data(
      pages_directory / "linux",
      pages_directory / "common",
      pages_directory / "osx",
      args.manual_section,
  )


if __name__ == "__main__":
  asyncio.run(main())
@TcPirate1
Copy link
Contributor

This is a good script!
Only change that I'd like to point out to future users of it is that in the first function, an await keyword after the if is needed.

So instead of:

async def list_files(directory):
  files = [file async for file in AsyncPath(directory).iterdir() if file.is_file()]
  return files

It should be:

async def list_files(directory):
  files = [file async for file in AsyncPath(directory).iterdir() if await file.is_file()]
  return files

Hopefully this saves some minor headaches :)

@vitorhcl
Copy link
Member Author

This is a good script!
Only change that I'd like to point out to future users of it is that in the first function, an await keyword after the if is needed.

So instead of:

async def list_files(directory):
  files = [file async for file in AsyncPath(directory).iterdir() if file.is_file()]
  return files

It should be:

async def list_files(directory):
  files = [file async for file in AsyncPath(directory).iterdir() if await file.is_file()]
  return files

Hopefully this saves some minor headaches :)

Thank you for the fix! Feel free to edit my comment and modify the script :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants