class docsis: """ Name: docsis module Purpose: docsis operating. Input: Absolute path of text file Fuction: decode(): return output file name(.txt) encode(output_type='cm_cfg') return output file name(.cfg or .bin) """ mibs_path_arg = "" def __init__(self, file_or_obj, tmpdir=None, mibs_paths=None): # TODO: fix at some point, this tmpdir is already relative to the CM config you # are grabbing? Not ideal as that dir might not be writeable, or a tftp or http URL # at some point - need to use a real local tmpdir or maybe even results so we can # save the resulting artifacts in other tools if tmpdir is None: tmpdir = os.path.join('tmp', config.board['station']) from devices import board if mibs_paths is None and hasattr(board, 'mibs_paths'): default = os.path.expandvars('/home/$USER/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp') mibs_path_arg = "-M " + default for mibs_path in board.mibs_paths: mibs_path_arg = mibs_path_arg + ":" + mibs_path self.mibs_path_arg = mibs_path_arg # TODO: this is all a bit wild here, need to clean up everything.. if isinstance(file_or_obj, cm_cfg): self.cm_cfg = file_or_obj # TODO: this seems like the wrong place to store these but OK self.dir_path=os.path.join(os.path.split(__file__)[0], tmpdir) self.file = self.cm_cfg.original_fname self.file_path = os.path.join(self.dir_path, self.file) else: self.file_path=file_or_obj self.dir_path=os.path.join(os.path.split(file_or_obj)[0], tmpdir) self.file=os.path.split(file_or_obj)[1] # make target tmpdir if it does not exist try: os.makedirs(self.dir_path) except OSError, err: import errno # Reraise the error unless it's about an already existing directory if err.errno != errno.EEXIST or not os.path.isdir(self.dir_path): raise if isinstance(file_or_obj, cm_cfg): self.cm_cfg.save(self.file_path) assert cmd_exists('docsis') assert cmd_exists('tclsh') tclsh = Tkinter.Tcl() assert tclsh.eval("package require sha1"), "please run apt-get install tcllib first"
class docsis: """ Name: docsis module Purpose: docsis operating. Input: Absolute path of text file Fuction: decode(): return output file name(.txt) encode(output_type='cm_cfg') return output file name(.cfg or .bin) """ def __init__(self, file_path, tmpdir=None): # TODO: fix at some point, this tmpdir is already relative to the CM config you # are grabbing? Not ideal as that dir might not be writeable, or a tftp or http URL # at some point - need to use a real local tmpdir or maybe even results so we can # save the resulting artifacts in other tools if tmpdir is None: tmpdir = os.path.join('tmp', config.board['station']) self.file_path = file_path self.dir_path = os.path.join(os.path.split(file_path)[0], tmpdir) self.file = os.path.split(file_path)[1] # make target tmpdir if it does not exist try: os.makedirs(self.dir_path) except OSError, err: import errno # Reraise the error unless it's about an already existing directory if err.errno != errno.EEXIST or not os.path.isdir(self.dir_path): raise assert cmd_exists('docsis') assert cmd_exists('tclsh') tclsh = Tkinter.Tcl() assert tclsh.eval( "package require sha1"), "please run apt-get install tcllib first"
def __init__(self, file_path): self.file_path=file_path self.dir_path=os.path.split(file_path)[0] self.file=os.path.split(file_path)[1] assert cmd_exists('docsis')