Esempio n. 1
0
    def backup(self, provider):
        try:
            os.makedirs(os.path.join(self.dir, provider.id))
        except:
            pass
        dir = tempfile.mkdtemp()
        
        try:
            for f in provider.list_files():
                for x in glob.glob(f):
                    xdir = os.path.join(dir, os.path.split(x)[0][1:])
                    shell('mkdir -p \'%s\'' % xdir)
                    shell('cp -r \'%s\' \'%s\'' % (x, xdir))

            if shell_status('cd %s; tar czf backup.tar.gz *'%dir) != 0:
                raise Exception()
            
            name = 0
            try:
                name = int(os.listdir(self.dir+'/'+provider.id)[0].split('.')[0])
            except:
                pass
            
            while os.path.exists('%s/%s/%i.tar.gz'%(self.dir,provider.id,name)):
                name += 1
            
            shutil.move('%s/backup.tar.gz'%dir, '%s/%s/%s.tar.gz'%(self.dir,provider.id,name))
        except:
            raise
        finally:
            shutil.rmtree(dir)
Esempio n. 2
0
 def restore(self, provider, revision):
     dir = tempfile.mkdtemp()
     shutil.copy('%s/%s/%s.tar.gz'%(self.dir,provider.id,revision), '%s/backup.tar.gz'%dir)
     for f in provider.list_files():
         for x in glob.glob(f):
             os.unlink(x)
     if shell_status('cd %s; tar xf backup.tar.gz -C /'%dir) != 0:
         raise Exception()
     os.unlink('%s/backup.tar.gz'%dir)
     shutil.rmtree(dir)
Esempio n. 3
0
 def verify_dep(dep):
     """
     Verifies that given plugin dependency is satisfied. Returns bool
     """
     if dep[0] == 'app':
         if shell_status('which '+dep[2]) != 0:
             raise SoftwareRequirementError(*dep[1:])
     if dep[0] == 'plugin':
         if not dep[1] in PluginLoader.list_plugins() or \
                 PluginLoader.__plugins[dep[1]].problem:
             raise PluginRequirementError(*dep[1:])
     if dep[0] == 'module':
         try:
             exec('import %s'%dep[1])
         except:
             raise ModuleRequirementError(*dep[1:])
Esempio n. 4
0
 def verify_dep(dep):
     """
     Verifies that given plugin dependency is satisfied. Returns bool
     """
     if dep[0] == 'app':
         if shell_status('which ' + dep[2]) != 0:
             raise SoftwareRequirementError(*dep[1:])
     if dep[0] == 'plugin':
         if not dep[1] in PluginLoader.list_plugins() or \
                 PluginLoader.__plugins[dep[1]].problem:
             raise PluginRequirementError(*dep[1:])
     if dep[0] == 'module':
         try:
             exec('import %s' % dep[1])
         except:
             raise ModuleRequirementError(*dep[1:])
Esempio n. 5
0
 def _parse_pm(self, ss):
     r = {}
     while len(ss)>0:
         s = ss[0].split()
         ss.pop(0)
         try:
             if '/' in s[0]:
                 s[0] = s[0].split('/')[1]
             r[s[0]] = apis.pkgman.Package()
             r[s[0]].name = s[0]
             r[s[0]].version = s[1]
             r[s[0]].description = ''
             r[s[0]].state = 'installed' if utils.shell_status('pacman -Q '+s[0])==0 else 'removed'
             while ss[0][0] in ['\t', ' '] and len(ss)>0:
                 r[s[0]].description += ss[0]
                 ss.pop(0)
             if len(r.keys()) > 250: break
         except:
             pass
     return r
Esempio n. 6
0
 def is_busy(self):
     if utils.shell_status('pgrep apt-get') != 0: return False
     return os.path.exists('/tmp/netcontrolnetcontrol-apt-output')
Esempio n. 7
0
 def is_busy(self):
     if utils.shell_status(
             'ps ax | grep \"/usr/bin/python /usr/bin/yum\" | grep -v \"grep /usr/bin/python /usr/bin/yum\" | awk \'{print $1}\''
     ) != 0:
         return False
     return os.path.exists('/tmp/netcontrol-yum-output')
Esempio n. 8
0
 def test(self):
     return shell_status('supervisorctl status') == 0
Esempio n. 9
0
 def has_param(self, param):
     return shell_status('grep \'%s=\' %s'%(param,self.file)) == 0
Esempio n. 10
0
 def is_busy(self):
     if utils.shell_status('pgrep apt-get') != 0: return False
     return os.path.exists('/tmp/netcontrolnetcontrol-apt-output')
Esempio n. 11
0
 def is_busy(self):
     if utils.shell_status('pgrep pacman') != 0: return False
     return os.path.exists('/tmp/netcontrol-pacman-output')
Esempio n. 12
0
 def is_busy(self):
     if utils.shell_status('ps ax | grep \"/usr/bin/python /usr/bin/yum\" | grep -v \"grep /usr/bin/python /usr/bin/yum\" | awk \'{print $1}\'') != 0: return False
     return os.path.exists('/tmp/netcontrol-yum-output')