Skip to main content
Code Review

Return to Question

edited tags; edited title
Link
200_success
  • 145.5k
  • 22
  • 190
  • 479

Script File presence check for an automated workflow

edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

How can I make this function more practical and efficient? Script for an automated workflow

Source Link
dongle
  • 111
  • 2

How can I make this function more practical and efficient?

I am working on a script for an automated workflow. It expects a CSV and a disk image to be present in the directory that is supplied as args.input.

I want to check for and handle every possible scenario: no CSV, no disk image, too many CSVs, too many disk images, and any possible combination thereto.

I've written the below, which works, and seems to be human readable, but it just seems incredibly excessive and verbose – is there any way I can make this more compact, yet still retain its legibility?

# CONFORMANCE CHECKS
def check_conformance():
 csv = glob.glob(args.input+'*.csv')
 disk_image = glob.glob(args.input+'*.E01')
 if len(csv) == 1:
 does_csv_exist = os.path.isfile(csv[0])
 elif len(csv) < 1:
 does_csv_exist = False
 elif len(csv) > 1:
 does_csv_exist = "too many CSVs!"
 if len(disk_image) == 1:
 does_E01_exist = os.path.isfile(disk_image[0])
 elif len(disk_image) < 1:
 does_E01_exist = False
 elif len(disk_image) > 1:
 does_E01_exist = "too many Disk Images!"
 if len(disk_image) > 1 and len(csv) > 1:
 does_csv_exist = "too many CSVs!"
 does_E01_exist = "too many disk images!"
 return (False, does_csv_exist, does_E01_exist,)
 if does_E01_exist is True and does_csv_exist is True:
 return True
 elif does_E01_exist is True and does_csv_exist is False:
 return (False, "CSV is missing")
 elif does_E01_exist is False and does_csv_exist is True:
 return (False, "E01 disk image is missing")
 elif does_E01_exist is False and does_csv_exist is False:
 return (False, "E01 disk image AND csv are missing")
 elif does_csv_exist is not True and does_csv_exist is not False:
 return (False, does_csv_exist)
 elif does_E01_exist is not True and does_E01_exist is not False:
 return (False, does_E01_exist)
lang-py

AltStyle によって変換されたページ (->オリジナル) /