cmdsorting.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. #
  5. # Copyright 2022 Stephen Stengel <stephen.stengel@cwu.edu> and friends
  6. #
  7. #
  8. import os
  9. import sys
  10. from AnimalSorter import sortAnimalsIntoFolders
  11. HELPFILE_PATH = "cmd-helpfile.txt"
  12. def main(args):
  13. print("Hello!")
  14. inStr, outStr = checkArgs(args)
  15. print("Running program...")
  16. sortAnimalsIntoFolders(inStr, outStr)
  17. print("Done!")
  18. return 0
  19. def checkArgs(args):
  20. helpArgs = ["--help", "-help", "help", "h", "-h", "--h"]
  21. if not set(helpArgs).isdisjoint(args):
  22. printHelpFile()
  23. sys.exit(-4)
  24. argslen = len(args)
  25. firstStr, secondStr = "", ""
  26. if argslen == 1:
  27. print("No input. Using manual mode. (Press control + C to exit...")
  28. firstStr, secondStr = askForInput()
  29. elif argslen == 2 and args[1] == "tux":
  30. printTextFile("tux.ascii")
  31. sys.exit(99)
  32. elif argslen == 3:
  33. firstStr, secondStr = args[1], args[2]
  34. elif argslen > 3:
  35. print("Bad input")
  36. printHelpFile()
  37. sys.exit(2)
  38. if firstStr == "" or secondStr == "":
  39. print("a folder is still not specified!")
  40. sys.exit(1)
  41. firstStr = os.path.abspath(firstStr)
  42. secondStr = os.path.abspath(secondStr)
  43. if firstStr != "" and secondStr != "":
  44. print("Input folder: " + str(firstStr) + "\n" \
  45. + "Output folder: " + str(secondStr) )
  46. return firstStr, secondStr
  47. def askForInput():
  48. print("Enter the path of the input pictures folder...")
  49. inStr = input()
  50. print("Enter the path of where you would like the sorted pictures to be saved...")
  51. outStr = input()
  52. return inStr, outStr
  53. def printTextFile(fileName):
  54. with open(fileName, "r") as tuxFile:
  55. for line in tuxFile:
  56. print(line, end = "")
  57. print()
  58. def printHelpFile():
  59. printTextFile(HELPFILE_PATH)
  60. if __name__ == '__main__':
  61. import sys
  62. sys.exit(main(sys.argv))