Created
July 28, 2014 15:23
-
-
Save jyuch/e01ff581fcc67f3a24e4 to your computer and use it in GitHub Desktop.
IronPythonオンリーイベント
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import clr | |
import sys | |
from os import path, stat | |
from datetime import date | |
from System import Console, ConsoleColor | |
# http://en.wikipedia.org/wiki/Rabbit | |
usagi = "usage : ipy exists.py <filename date in yyyymmdd> <generate date in yyyymmdd>" | |
def main(argv): | |
if len(argv) != 2: | |
print usagi | |
sys.exit(0) | |
if len(argv[0]) != 8 or len(argv[1]) != 8: | |
print usagi | |
sys.exit(0) | |
if not argv[1].isdigit(): | |
print usagi | |
sys.exit(0) | |
check_list = [] | |
result = [] | |
with open("list.txt") as f: | |
for line in f: | |
target = line.strip() | |
target = target.replace('yyyy', argv[0][0:4]) | |
target = target.replace('mm', argv[0][4:6]) | |
target = target.replace('dd', argv[0][6:8]) | |
check_list.append(target) | |
for it in check_list: | |
is_exists = path.exists(it) | |
is_timestamp = False | |
if is_exists: | |
generated_date = date.fromtimestamp(stat(it).st_mtime) | |
is_timestamp = (generated_date.year == int(argv[1][0:4]) and | |
generated_date.month == int(argv[1][4:6]) and | |
generated_date.day == int(argv[1][6:8])) | |
result.append((it, is_exists, is_timestamp)) | |
print "{0:<40} {1:6} {2:9}".format("Filename", "Exists", "Timestamp") | |
for it in result: | |
file_path, is_exists, is_timestamp = it | |
Console.Write("{0:<40}".format(path.basename(file_path))) | |
Console.Write(" [") | |
if is_exists: | |
print_ok() | |
else: | |
print_fail() | |
Console.Write("] [") | |
if is_timestamp: | |
print_ok() | |
else: | |
print_fail() | |
Console.WriteLine("]") | |
def print_ok(): | |
Console.ForegroundColor = ConsoleColor.Green | |
Console.Write(" ok ") | |
Console.ResetColor() | |
def print_fail(): | |
Console.ForegroundColor = ConsoleColor.Red | |
Console.Write("fail") | |
Console.ResetColor() | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment