Projects STRLCPY dummy Commits 27a62d9f
🤬
  • No option is used to specify the file path

  • Loading...
  • tkmru committed 7 months ago
    27a62d9f
    1 parent 7529ea3b
  • ■ ■ ■ ■ ■ ■
    dummy/cli.py
    skipped 5 lines
    6 6  import colorama
    7 7  import io
    8 8   
    9  -from colorama import Fore, Back, Style
     9 +from colorama import Fore
    10 10  from PIL import Image, ImageDraw, ImageFont
    11 11  from reportlab.pdfgen import canvas
    12 12  from reportlab.lib.pagesizes import B5
    skipped 63 lines
    76 76   elif byte_str.endswith(('GB', 'Gb', 'gB', 'gb')):
    77 77   return int(byte_str[:-2]) * 1024 * 1024 * 1024
    78 78   else:
    79  - return int(byte_str)
     79 + try:
     80 + return int(byte_str)
     81 + except ValueError:
     82 + print(Fore.RED + 'Error: Invalid byte size.')
     83 + return None
    80 84   
    81 85  def parse_args():
    82 86   colorama.init(autoreset=True)
    83 87   parser = argparse.ArgumentParser(description='Create a dummy file for testing.')
    84  - parser.add_argument('-n', '--name', help='File name(.jpeg, .png, .pdf)', required=True)
     88 + parser.add_argument('file_path', help='Path to the generated file(.jpeg, .png, .pdf)')
    85 89   parser.add_argument('-t', '--text', help='Text to be written in the file', default='dummy file')
    86 90   parser.add_argument('-b', '--bytes', help='Bytes of file(.png only)')
    87 91   
    88 92   args = parser.parse_args()
    89  - if args.name.endswith('.jpeg'):
    90  - make_jpeg(args.name, args.text)
    91  - elif args.name.endswith('.png'):
    92  - make_png(args.name, args.text, parse_bytes(args.bytes))
    93  - elif args.name.endswith('.pdf'):
    94  - make_pdf(args.name, args.text)
     93 + if args.file_path.endswith('.jpeg') or args.file_path.endswith('.jpg'):
     94 + make_jpeg(args.file_path, args.text)
     95 + elif args.file_path.endswith('.png'):
     96 + make_png(args.file_path, args.text, parse_bytes(args.bytes))
     97 + elif args.file_path.endswith('.pdf'):
     98 + make_pdf(args.file_path, args.text)
    95 99   else:
    96 100   print(Fore.RED + 'Error: Invalid file extension.')
    97  - return
     101 + 
    98 102   
Please wait...
Page is in error, reload to recover