ail-framework/bin/Attributes.py

51 lines
1.4 KiB
Python
Raw Permalink Normal View History

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