Exemple #1
0
def get_latest_json(serv_url, download_dir, fname):
   json_path = join(download_dir, fname)
   json_url = urljoin(serv_url, fname)

   json_local = json_serv = None
   resuming = True

   try:
      json_serv = misc.json_from_url(json_url)
   except Exception e:
      var = traceback.format_exc()
      msg = "Can't get %s from %s. " % (fname, json_url)
      msg += "Got this error: %s" % var
      raise Error(error.DOWNLOAD, msg)

   json = read_json(json_path)
   if json is None:
      msg =  'No local %s file found. ' % fname
      msg += 'Downloading %s from server.' % fname
      logger.info(msg)
      json = json_serv
      resuming = False
   else:
      logger.info('Local %s found. Checking contents.' % fname)
      if same_dict(json, json_serv):
         logger.info('%s is latest.' % fname)
      else:
         logger.info('Local and remote %s differ.' % fname)
         resuming = False
         json = json_serv
   return json, resuming
Exemple #2
0
 def get_working_dir(self):
     if not self.is_running():
         return None
     path = u.expand_link(u.join('/proc', self.pid, 'cwd'))
     if u.file_exists(path):
         return path
     else:
         return None
Exemple #3
0
 def get_working_dir(self):
    if not self.is_running():
       return None
    path = u.expand_link(u.join('/proc', self.pid, 'cwd'))
    if u.file_exists(path):
       return path
    else:
       return None
Exemple #4
0
 def get_exe_path(self):
     if not self.is_running():
         return None
     try:
         path = u.expand_link(u.join('/proc', self.pid, 'exe'))
     except:
         return None
     if u.file_exists(path):
         return path
     else:
         return None
Exemple #5
0
 def get_exe_path(self):
    if not self.is_running():
       return None
    try:
       path = u.expand_link(u.join('/proc', self.pid, 'exe'))
    except:
       return None
    if u.file_exists(path):
       return path
    else:
       return None
Exemple #6
0
def find_by_name(name):
    proc_dirs = u.ls('/proc')
    for path in proc_dirs:
        if not u.is_file(u.join('/proc', path, 'maps')):
            continue
        p = Process(path)
        exe_path = p.get_exe_path()
        if not p.is_running() or not exe_path:
            continue
        fname = u.get_file_name(exe_path)
        if fname == name:
            return p
    return None
Exemple #7
0
def find_by_name(name):
   proc_dirs  = u.ls('/proc')
   for path in proc_dirs:
      if not u.is_file(u.join('/proc', path, 'maps')):
         continue
      p = Process(path)
      exe_path = p.get_exe_path()
      if not p.is_running() or not exe_path:
         continue
      fname = u.get_file_name(exe_path)
      if fname == name:
         return p
   return None
Exemple #8
0
 def read_maps(self):
     maps = []
     mapsStr = u.read_file(u.join('/proc', self.pid, 'maps')).strip()
     entries = mapsStr.split('\n')
     for entry in entries:
         lst = list(filter(lambda char: char != '', entry.split(' ')))
         p = lst[1]
         item = {
             'region': lst[0],
             'permission': p,
             'offset': lst[2],
             'device': lst[3],
             'inode': lst[4],
         }
         item['path'] = lst[5] if len(lst) == 6 else None
         maps.append(item)
     return maps
Exemple #9
0
 def read_maps(self):
    maps = []
    mapsStr = u.read_file(u.join('/proc', self.pid, 'maps')).strip()
    entries = mapsStr.split('\n')
    for entry in entries:
       lst = list(filter(lambda char: char!='', entry.split(' ')))
       p = lst[1]
       item = {
          'region'          : lst[0],
          'permission'      : p,
          'offset'          : lst[2],
          'device'          : lst[3],
          'inode'           : lst[4],
       }
       item['path'] = lst[5] if len(lst) == 6 else None
       maps.append(item)
    return maps
Exemple #10
0
def get_conf(serv_url, download_dir):
   if not file_exists(download_dir):
      shellutils.mkdir(download_dir)

   ret = get_latest_json(serv_url, download_dir, conf_fname)
   conf, latest_conf = ret
   ret = get_latest_json(serv_url, download_dir, hashes_fname)
   hashes, latest_hashes  = ret

   resuming = False
   if latest_conf and latest_hashes:
      resuming = True
      logger.info('Everything is up to date. Resuming.')
   else:
      logger.info('Files outdated. Restarting.')

   raw_f_name = conf['raw-file']
   raw_path = join(download_dir, raw_f_name)

   raw_url = urljoin(serv_url, raw_f_name)
   logger.info('raw file url: %s' % raw_url)

   #todo: left here
   return conf, raw_path, json_path, data_path, hashes_path, hashes, resuming, threadQueue, raw_url
Exemple #11
0
 def is_running(self):
     if not self.is_valid():
         return False
     return u.is_dir(u.join('/proc', self.pid))
Exemple #12
0
 def is_running(self):
    if not self.is_valid():
       return False
    return u.is_dir(u.join('/proc', self.pid))