2018-05-04 13:53:29 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-02-05 16:15:09 +01:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
import time
|
|
|
|
from packages import Paste
|
2016-02-10 16:39:06 +01:00
|
|
|
from pubsublogger import publisher
|
2016-02-05 16:15:09 +01:00
|
|
|
from Helper import Process
|
|
|
|
import re
|
|
|
|
|
2018-05-02 17:07:10 +02:00
|
|
|
import signal
|
|
|
|
|
|
|
|
class TimeoutException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def timeout_handler(signum, frame):
|
|
|
|
raise TimeoutException
|
|
|
|
|
|
|
|
signal.signal(signal.SIGALRM, timeout_handler)
|
|
|
|
|
2017-05-09 11:13:16 +02:00
|
|
|
'''
|
|
|
|
This module takes its input from the global module.
|
|
|
|
It applies some regex and publish matched content
|
|
|
|
'''
|
|
|
|
|
2016-02-10 16:39:06 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
publisher.port = 6380
|
|
|
|
publisher.channel = "Script"
|
|
|
|
config_section = "Release"
|
|
|
|
p = Process(config_section)
|
2018-05-02 17:07:10 +02:00
|
|
|
max_execution_time = p.config.getint("Curve", "max_execution_time")
|
2016-02-10 16:39:06 +01:00
|
|
|
publisher.info("Release scripts to find release names")
|
2016-02-05 16:15:09 +01:00
|
|
|
|
2016-02-10 16:39:06 +01:00
|
|
|
movie = "[a-zA-Z0-9.]+\.[0-9]{4}.[a-zA-Z0-9.]+\-[a-zA-Z]+"
|
|
|
|
tv = "[a-zA-Z0-9.]+\.S[0-9]{2}E[0-9]{2}.[a-zA-Z0-9.]+\.[a-zA-Z0-9.]+\-[a-zA-Z0-9]+"
|
|
|
|
xxx = "[a-zA-Z0-9._]+.XXX.[a-zA-Z0-9.]+\-[a-zA-Z0-9]+"
|
2016-02-05 16:15:09 +01:00
|
|
|
|
2016-02-10 16:39:06 +01:00
|
|
|
regexs = [movie, tv, xxx]
|
2016-02-05 16:15:09 +01:00
|
|
|
|
2016-02-10 16:39:06 +01:00
|
|
|
regex = '|'.join(regexs)
|
|
|
|
while True:
|
|
|
|
filepath = p.get_from_set()
|
|
|
|
if filepath is None:
|
|
|
|
publisher.debug("Script Release is Idling 10s")
|
2018-04-16 14:50:04 +02:00
|
|
|
print('Sleeping')
|
2016-02-10 16:39:06 +01:00
|
|
|
time.sleep(10)
|
|
|
|
continue
|
2016-02-05 16:15:09 +01:00
|
|
|
|
2016-02-10 16:39:06 +01:00
|
|
|
paste = Paste.Paste(filepath)
|
|
|
|
content = paste.get_p_content()
|
2016-02-05 16:15:09 +01:00
|
|
|
|
2018-05-02 17:07:10 +02:00
|
|
|
signal.alarm(max_execution_time)
|
|
|
|
try:
|
|
|
|
releases = set(re.findall(regex, content))
|
|
|
|
if len(releases) == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
to_print = 'Release;{};{};{};{} releases;{}'.format(paste.p_source, paste.p_date, paste.p_name, len(releases), paste.p_path)
|
|
|
|
print(to_print)
|
|
|
|
if len(releases) > 30:
|
|
|
|
publisher.warning(to_print)
|
|
|
|
else:
|
|
|
|
publisher.info(to_print)
|
|
|
|
|
|
|
|
except TimeoutException:
|
|
|
|
print ("{0} processing timeout".format(paste.p_path))
|
|
|
|
continue
|
2016-02-10 16:39:06 +01:00
|
|
|
else:
|
2018-05-02 17:07:10 +02:00
|
|
|
signal.alarm(0)
|