2018-05-04 13:53:29 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-08-06 11:43:40 +02:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The ZMQ_Sub_Attribute Module
|
|
|
|
============================
|
|
|
|
|
2017-05-09 11:13:16 +02:00
|
|
|
This module is saving Attribute of the paste into redis
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
"""
|
2014-08-14 17:55:18 +02:00
|
|
|
import time
|
|
|
|
from packages import Paste
|
2014-08-06 11:43:40 +02:00
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
from Helper import Process
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
if __name__ == "__main__":
|
2014-08-22 17:35:40 +02:00
|
|
|
publisher.port = 6380
|
2014-08-20 15:14:57 +02:00
|
|
|
publisher.channel = "Script"
|
2014-08-14 17:55:18 +02:00
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
config_section = 'Attributes'
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
p = Process(config_section)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
# FUNCTIONS #
|
2014-08-29 19:37:56 +02:00
|
|
|
publisher.info("Attribute is Running")
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
while True:
|
2014-08-14 17:55:18 +02:00
|
|
|
try:
|
2014-08-29 19:37:56 +02:00
|
|
|
message = p.get_from_set()
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-14 17:55:18 +02:00
|
|
|
if message is not None:
|
2014-08-29 19:37:56 +02:00
|
|
|
PST = Paste.Paste(message)
|
2014-08-06 11:43:40 +02:00
|
|
|
else:
|
2014-08-29 19:37:56 +02:00
|
|
|
publisher.debug("Script Attribute is idling 1s")
|
2018-04-16 14:50:04 +02:00
|
|
|
print('sleeping')
|
2014-08-29 19:37:56 +02:00
|
|
|
time.sleep(1)
|
2014-08-06 11:43:40 +02:00
|
|
|
continue
|
|
|
|
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME do it directly in the class
|
|
|
|
PST.save_attribute_redis("p_encoding", PST._get_p_encoding())
|
2016-07-13 08:59:48 +02:00
|
|
|
#PST.save_attribute_redis("p_language", PST._get_p_language())
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME why not all saving everything there.
|
2014-08-21 12:22:07 +02:00
|
|
|
PST.save_all_attributes_redis()
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME Not used.
|
|
|
|
PST.store.sadd("Pastes_Objects", PST.p_path)
|
2014-08-06 11:43:40 +02:00
|
|
|
except IOError:
|
2018-04-16 14:50:04 +02:00
|
|
|
print("CRC Checksum Failed on :", PST.p_path)
|
2014-08-21 14:39:17 +02:00
|
|
|
publisher.error('Duplicate;{};{};{};CRC Checksum Failed'.format(
|
|
|
|
PST.p_source, PST.p_date, PST.p_name))
|