Change names to query creation/modification time.

Down the road, the application's action on folders will be checked
as well.  Thus, it is appropriate to alter the functions' names to
querry the time of creation/modifications into a more flexible, yet
correct form.
This commit is contained in:
Norwid Behrnd 2021-09-28 14:41:00 +00:00
parent 7504aead86
commit 20fbfe2504
2 changed files with 40 additions and 40 deletions

View file

@ -43,16 +43,16 @@ def prepare_testfile():
os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0)) os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0))
def query_file_creation(): def query_creation_time(name=TFILE):
"""Determine the time of creation of the file.""" """Determine the time of creation of the file/folder."""
created = os.stat(TFILE).st_ctime created = os.stat(name).st_ctime
created = str(datetime.fromtimestamp(created)) created = str(datetime.fromtimestamp(created))
return created return created
def query_file_modification(): def query_modification_time(name=TFILE):
"""Determine the time when the file was modified.""" """Determine the time when the file/folder was modified."""
modified = os.stat(TFILE).st_mtime modified = os.stat(name).st_mtime
modified = str(datetime.fromtimestamp(modified)) modified = str(datetime.fromtimestamp(modified))
return modified return modified
@ -84,10 +84,10 @@ def test_default_pattern_YYYY_MM_DD(arg1):
new = str("") new = str("")
if arg1 in [" ", "-f", "--files", "-m", "--mtime"]: if arg1 in [" ", "-f", "--files", "-m", "--mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-c", "--ctime"]: elif arg1 in ["-c", "--ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
new = "_".join([day, TFILE]) new = "_".join([day, TFILE])
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}") test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
@ -112,11 +112,11 @@ def test_compact_pattern_YYYYMMDD(arg1):
"-C --files", "--compact --files", "-C --files", "--compact --files",
"-C -m", "--compact -m", "-C -m", "--compact -m",
"-C --mtime", "--compact --mtime"]: "-C --mtime", "--compact --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-C -c", "--compact -c", elif arg1 in ["-C -c", "--compact -c",
"-C --ctime", "--compact --ctime"]: "-C --ctime", "--compact --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# drop the hyphens in the datestamp: # drop the hyphens in the datestamp:
day = day.replace("-", "") day = day.replace("-", "")
@ -144,11 +144,11 @@ def test_compact_month_YYYY_MM(arg1):
"-M --files", "--month --files", "-M --files", "--month --files",
"-M -m", "--month -m", "-M -m", "--month -m",
"-M --mtime", "--month --mtime"]: "-M --mtime", "--month --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-M -c", "--month -c", elif arg1 in ["-M -c", "--month -c",
"-M --ctime", "--month --ctime"]: "-M --ctime", "--month --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# trim off the last three characters in the datestamp: # trim off the last three characters in the datestamp:
day = day[:-3] day = day[:-3]
@ -174,13 +174,13 @@ def test_default_pattern_YYYY_MM_DDThh_mm_ss(arg1):
"--withtime -f", "--withtime --files", "--withtime -f", "--withtime --files",
"-w -m", "-w --mtime", "-w -m", "-w --mtime",
"--withtime -m", "--withtime --mtime"]: "--withtime -m", "--withtime --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
second = query_file_modification().split()[1] second = query_modification_time().split()[1]
elif arg1 in ["-w -c", "-w --ctime", elif arg1 in ["-w -c", "-w --ctime",
"--withtime -c", "--withtime --ctime"]: "--withtime -c", "--withtime --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
second = query_file_creation().split()[1] second = query_creation_time().split()[1]
second = second.split(".")[0] # use integer seconds only second = second.split(".")[0] # use integer seconds only
second = second.replace(":", ".") # adjust representation second = second.replace(":", ".") # adjust representation
@ -209,11 +209,11 @@ def test_short_pattern_YYMMDD(arg1):
"-S --files", "--short --files", "-S --files", "--short --files",
"-S -m", "--short -m", "-S -m", "--short -m",
"-S --mtime", "--short --mtime"]: "-S --mtime", "--short --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-S -c", "--short -c", elif arg1 in ["-S -c", "--short -c",
"-S --ctime", "--short --ctime"]: "-S --ctime", "--short --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# drop the hyphens in the datestamp: # drop the hyphens in the datestamp:
day = day.replace("-", "") day = day.replace("-", "")

View file

@ -136,18 +136,18 @@
# https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac # https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac
result = os.stat(TFILE) result = os.stat(TFILE)
os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0)) os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0))
def query_file_creation(): def query_creation_time(name=TFILE):
"""Determine the time of creation of the file.""" """Determine the time of creation of the file/folder."""
created = os.stat(TFILE).st_ctime created = os.stat(name).st_ctime
created = str(datetime.fromtimestamp(created)) created = str(datetime.fromtimestamp(created))
return created return created
def query_file_modification(): def query_modification_time(name=TFILE):
"""Determine the time when the file was modified.""" """Determine the time when the file/folder was modified."""
modified = os.stat(TFILE).st_mtime modified = os.stat(name).st_mtime
modified = str(datetime.fromtimestamp(modified)) modified = str(datetime.fromtimestamp(modified))
return modified return modified
#+end_src #+end_src
@ -194,10 +194,10 @@
new = str("") new = str("")
if arg1 in [" ", "-f", "--files", "-m", "--mtime"]: if arg1 in [" ", "-f", "--files", "-m", "--mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-c", "--ctime"]: elif arg1 in ["-c", "--ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
new = "_".join([day, TFILE]) new = "_".join([day, TFILE])
test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}") test = getoutput(f"python3 {PROGRAM} {TFILE} {arg1}")
@ -227,11 +227,11 @@
"-C --files", "--compact --files", "-C --files", "--compact --files",
"-C -m", "--compact -m", "-C -m", "--compact -m",
"-C --mtime", "--compact --mtime"]: "-C --mtime", "--compact --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-C -c", "--compact -c", elif arg1 in ["-C -c", "--compact -c",
"-C --ctime", "--compact --ctime"]: "-C --ctime", "--compact --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# drop the hyphens in the datestamp: # drop the hyphens in the datestamp:
day = day.replace("-", "") day = day.replace("-", "")
@ -264,11 +264,11 @@
"-M --files", "--month --files", "-M --files", "--month --files",
"-M -m", "--month -m", "-M -m", "--month -m",
"-M --mtime", "--month --mtime"]: "-M --mtime", "--month --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-M -c", "--month -c", elif arg1 in ["-M -c", "--month -c",
"-M --ctime", "--month --ctime"]: "-M --ctime", "--month --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# trim off the last three characters in the datestamp: # trim off the last three characters in the datestamp:
day = day[:-3] day = day[:-3]
@ -298,13 +298,13 @@
"--withtime -f", "--withtime --files", "--withtime -f", "--withtime --files",
"-w -m", "-w --mtime", "-w -m", "-w --mtime",
"--withtime -m", "--withtime --mtime"]: "--withtime -m", "--withtime --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
second = query_file_modification().split()[1] second = query_modification_time().split()[1]
elif arg1 in ["-w -c", "-w --ctime", elif arg1 in ["-w -c", "-w --ctime",
"--withtime -c", "--withtime --ctime"]: "--withtime -c", "--withtime --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
second = query_file_creation().split()[1] second = query_creation_time().split()[1]
second = second.split(".")[0] # use integer seconds only second = second.split(".")[0] # use integer seconds only
second = second.replace(":", ".") # adjust representation second = second.replace(":", ".") # adjust representation
@ -338,11 +338,11 @@
"-S --files", "--short --files", "-S --files", "--short --files",
"-S -m", "--short -m", "-S -m", "--short -m",
"-S --mtime", "--short --mtime"]: "-S --mtime", "--short --mtime"]:
day = query_file_modification().split()[0] day = query_modification_time().split()[0]
elif arg1 in ["-S -c", "--short -c", elif arg1 in ["-S -c", "--short -c",
"-S --ctime", "--short --ctime"]: "-S --ctime", "--short --ctime"]:
day = query_file_creation().split()[0] day = query_creation_time().split()[0]
# drop the hyphens in the datestamp: # drop the hyphens in the datestamp:
day = day.replace("-", "") day = day.replace("-", "")