Return to repo list

opet

Oblivion Proton .esp Tool
Return to HMagellan.com

tools.py (1553B)


      1 import os, sys, time
      2 
      3 ############
      4 # tools.py #
      5 ############
      6 
      7 # This file contains:
      8 #   1. Various objects that represent certain functionality of OPET
      9 
     10 #####################
     11 # Section 1 - Tools #
     12 #####################
     13 
     14 class DataPackTool(object):
     15     """
     16     Encapsulates the functionality of OPET
     17     to set .es[p|m] load order and activation.
     18     """
     19 
     20     def __init__(self, manager):
     21 
     22         # Setup
     23         self.manager = manager
     24 
     25     def get_load_order_list(self, path):
     26         """
     27         Construct a load order list out of the
     28         .es[p|m] files in the given directory and
     29         return it.
     30         """
     31         matches = []
     32         for f in list(sorted(os.listdir(path), key = lambda x: os.stat(os.path.join(path, x)).st_mtime)):
     33             if os.path.splitext(f)[1] in [".esp", ".esm"]:
     34                 matches.append(f)
     35         return matches
     36     
     37     def assign_load_order(self, orderlist, environment):
     38         """
     39         Assign load order by modyfing date
     40         of files in order of their appearance
     41         in 'orderlist'.
     42         """
     43         for e in orderlist:
     44             os.utime(os.path.join(os.path.expanduser(environment["OblivionDataPath"]), e["name"]))
     45             time.sleep(0.01)
     46 
     47     def enable_esps(self, enablelist, environment):
     48         """
     49         Enable the given ESPs.
     50         """
     51         with open(os.path.join(os.path.expanduser(environment["OblivionPrefixAppdata"]), "Plugins.txt"), "w") as f:
     52             for e in enablelist:
     53                 if e["enabled"]:
     54                     f.write(e["name"] + '\n')
     55