Browse Source

Add logging to reading and writing of attribute files

tags/3.0.0Beta4
Safihre 5 years ago
parent
commit
3faa0f4f42
  1. 47
      sabnzbd/nzbstuff.py

47
sabnzbd/nzbstuff.py

@ -2108,40 +2108,35 @@ def scan_password(name):
def get_attrib_file(path, size): def get_attrib_file(path, size):
""" Read job's attributes from file """ """ Read job's attributes from file """
logging.debug("Reading %s attributes from %s", size, path)
attribs = [] attribs = []
path = os.path.join(path, ATTRIB_FILE) path = os.path.join(path, ATTRIB_FILE)
try: try:
f = open(path, "r", encoding="utf-8") with open(path, "r", encoding="utf-8") as attr_file:
except: for _ in range(size):
return [None for unused in range(size)] line = attr_file.readline().strip("\r\n ")
if line:
for unused in range(size): if line.lower() == "none":
line = f.readline().strip("\r\n ") line = None
if line: try:
if line.lower() == "none": line = int(line)
line = None except:
try: pass
line = int(line) attribs.append(line)
except: else:
pass attribs.append(None)
attribs.append(line) return attribs
else: except OSError:
attribs.append(None) return [None for _ in range(size)]
f.close()
return attribs
def set_attrib_file(path, attribs): def set_attrib_file(path, attribs):
""" Write job's attributes to file """ """ Write job's attributes to file """
logging.debug("Writing attributes %s to %s", attribs, path)
path = os.path.join(path, ATTRIB_FILE) path = os.path.join(path, ATTRIB_FILE)
try: with open(path, "w", encoding="utf-8") as attr_file:
f = open(path, "w", encoding="utf-8") for item in attribs:
except: attr_file.write("%s\n" % item)
return
for item in attribs:
f.write("%s\n" % item)
f.close()
def name_extractor(subject): def name_extractor(subject):

Loading…
Cancel
Save