Example #1
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied. Returns bool
        """
        platform = PluginLoader.platform

        if dep['type'] == 'app':
            if (dep['binary'] and shell_status('which '+dep['binary']) != 0) \
            and shell_status('pacman -Q '+dep['package']) != 0:
                if platform == 'arch' or platform == 'arkos':
                    try:
                        if cat:
                            cat.put_statusmsg('Installing dependency %s...' % dep['name'])
                        shell('pacman -Sy --noconfirm --needed '+dep['package'])
                        shell('systemctl enable '+dep['binary'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'gentoo':
                    try:
                        shell('emerge '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                else:
                    raise SoftwareRequirementError(dep)
        if dep['type'] == 'plugin':
            if not dep['package'] in PluginLoader.list_plugins() or \
                    PluginLoader.__plugins[dep['package']].problem:
                raise PluginRequirementError(dep)
        if dep['type'] == 'module':
            try:
                exec('import %s'%dep['binary'])
            except:
                # Let's try to install it anyway
                shell('pip2 install %s' % dep['package'])
                raise ModuleRequirementError(dep, True)
Example #2
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied. Returns bool
        """
        platform = PluginLoader.platform

        if dep[0] == 'app':
            if shell_status('which ' + dep[2]) != 0 and shell_status(
                    'pacman -Q ' + dep[1]) != 0:
                if platform == 'arch' or platform == 'arkos':
                    try:
                        if cat:
                            cat.put_statusmsg('Installing dependency %s...' %
                                              dep[1])
                        shell('pacman -Sy --noconfirm --needed ' + dep[1])
                        shell('systemctl enable ' + dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install ' + dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'gentoo':
                    try:
                        shell('emerge ' + dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R ' + dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  ' + dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                else:
                    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:])
Example #3
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied.
        """
        platform = PluginLoader.platform
        log = PluginLoader.log

        if dep['type'] == 'app':
            if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \
            or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0:
                if platform == 'arch' or platform == 'arkos':
                    try:
                        if cat:
                            cat.put_statusmsg('Installing dependency %s...' %
                                              dep['name'])
                        log.warn(
                            'Missing %s, which is required by a plugin. Attempting to install...'
                            % dep['name'])
                        shell('pacman -Sy --noconfirm --needed ' +
                              dep['package'])
                        if dep['binary']:
                            shell('systemctl enable ' + dep['binary'])
                    except Exception, e:
                        log.error('Failed to install %s - %s' %
                                  (dep['name'], str(e)))
                        raise SoftwareRequirementError(dep)
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install ' +
                              dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'gentoo':
                    try:
                        shell('emerge ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                else:
                    raise SoftwareRequirementError(dep)
Example #4
0
File: api.py Project: tewe/genesis
    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))

            metafile = open(dir + '/genesis-backup', 'w')
            metafile.write(provider.id)
            metafile.close()

            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)
Example #5
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied.
        """
        platform = PluginLoader.platform
        log = PluginLoader.log

        if dep['type'] == 'app':
            if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \
            or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0:
                if platform == 'arch' or platform == 'arkos':
                    try:
                        if cat:
                            cat.put_statusmsg('Installing dependency %s...' % dep['name'])
                        log.warn('Missing %s, which is required by a plugin. Attempting to install...' % dep['name'])
                        shell('pacman -Sy --noconfirm --needed '+dep['package'])
                        if dep['binary']:
                            shell('systemctl enable '+dep['binary'])
                    except Exception, e:
                        log.error('Failed to install %s - %s' % (dep['name'], str(e)))
                        raise SoftwareRequirementError(dep)
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'gentoo':
                    try:
                        shell('emerge '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                else:
                    raise SoftwareRequirementError(dep)
Example #6
0
File: api.py Project: tewe/genesis
 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 / --exclude genesis-backup'%dir) != 0:
         raise Exception()
     os.unlink('%s/backup.tar.gz'%dir)
     shutil.rmtree(dir)
Example #7
0
File: api.py Project: ajvb/genesis
 def get_dbtypes(self):
     dblist = []
     for plugin in self.app.grab_plugins(apis.databases.IDatabase):
         active = None
         if plugin.task is not '':
             status = shell_status('systemctl is-active %s' % plugin.task)
             if status is 0:
                 active = True
             else:
                 active = False
         dblist.append((plugin.name, plugin.task, active))
     return dblist
Example #8
0
 def get_dbtypes(self):
     dblist = []
     for plugin in self.app.grab_plugins(apis.databases.IDatabase):
         active = None
         if plugin.plugin_info.db_task:
             status = shell_status('systemctl is-active %s' % plugin.plugin_info.db_task)
             if status is 0:
                 active = True
             else:
                 active = False
         dblist.append((plugin.plugin_info.db_name, plugin.plugin_info.db_task, active))
     return dblist
Example #9
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:])
Example #10
0
    def verify_dep(dep):
        """
        Verifies that given plugin dependency is satisfied. Returns bool
        """
        platform = PluginLoader.platform

        if dep[0] == 'app':
            if shell_status('which '+dep[2]) != 0:
                if platform == 'arch' or platform == 'arkos':
                    try:
                        shell('pacman -S --noconfirm '+dep[1])
                        shell('systemctl enable '+dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install '+dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'gentoo':
                    try:
                        shell('emerge '+dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R '+dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  '+dep[2])
                    except:
                        raise SoftwareRequirementError(*dep[1:])
                else:
                    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:])
Example #11
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
Example #12
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
Example #13
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
Example #14
0
File: main.py Project: tewe/genesis
 def verify_composer(self):
     if not shell_status('which composer') == 0:
         self.install_composer()
     if not shell_status('which composer') == 0:
         raise Exception('Composer was not installed successfully.')
Example #15
0
 def is_busy(self):
     if utils.shell_status('pgrep pacman') != 0: return False
     return os.path.exists('/tmp/genesis-pacman-output')
Example #16
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/genesis-yum-output')
Example #17
0
 def is_busy(self):
     if utils.shell_status('pgrep pacman') != 0: return False
     return os.path.exists('/tmp/genesis-pacman-output')
Example #18
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied.
        """
        platform = PluginLoader.platform
        log = PluginLoader.log

        if dep['type'] == 'app':
            if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \
            or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0:
                if platform == 'arch' or platform == 'arkos':
                    if cat:
                        cat.statusmsg('Installing dependency %s...' %
                                      dep['name'])
                    log.warn(
                        'Missing %s, which is required by a plugin. Attempting to install...'
                        % dep['name'])
                    s = shell_cs('pacman -Sy --noconfirm --needed ' +
                                 dep['package'],
                                 stderr=True)
                    if s[0] != 0:
                        log.error('Failed to install %s - %s' %
                                  (dep['name'], str(s[1])))
                        raise SoftwareRequirementError(dep)
                    if dep['binary']:
                        shell('systemctl enable ' + dep['binary'])
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install ' +
                              dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'gentoo':
                    try:
                        shell('emerge ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  ' + dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                else:
                    raise SoftwareRequirementError(dep)
        if dep['type'] == 'plugin':
            if not dep['package'] in PluginLoader.list_plugins() or \
                    PluginLoader.__plugins[dep['package']].problem:
                raise PluginRequirementError(dep)
        if dep['type'] == 'module':
            if dep.has_key('binary') and dep['binary']:
                try:
                    exec('import %s' % dep['binary'])
                except:
                    # Let's try to install it anyway
                    s = shell_cs('pip%s install %s' %
                                 ('2' if platform in ['arkos', 'arch'] else '',
                                  dep['package']))
                    if s[0] != 0:
                        raise ModuleRequirementError(dep, False)
                    else:
                        return 'Restart Genesis for changes to take effect.'
                        raise ModuleRequirementError(dep, False)
            else:
                p = False
                s = shell('pip%s freeze' %
                          '2' if platform in ['arkos', 'arch'] else '')
                for x in s.split('\n'):
                    if dep['package'].lower() in x.split('==')[0].lower():
                        p = True
                if not p:
                    shell('pip%s install %s' %
                          ('2' if platform in ['arkos', 'arch'] else '',
                           dep['package']))
                    raise ModuleRequirementError(dep, True)
Example #19
0
    def verify_dep(dep, cat=''):
        """
        Verifies that given plugin dependency is satisfied.
        """
        platform = PluginLoader.platform
        log = PluginLoader.log

        if dep['type'] == 'app':
            if ((dep['binary'] and shell_status('which '+dep['binary']) != 0) \
            or not dep['binary']) and shell_status('pacman -Q '+dep['package']) != 0:
                if platform == 'arch' or platform == 'arkos':
                    if cat:
                        cat.statusmsg('Installing dependency %s...' % dep['name'])
                    log.warn('Missing %s, which is required by a plugin. Attempting to install...' % dep['name'])
                    s = shell_cs('pacman -Sy --noconfirm --needed '+dep['package'], stderr=True)
                    if s[0] != 0:
                        log.error('Failed to install %s - %s' % (dep['name'], str(s[1])))
                        raise SoftwareRequirementError(dep)
                    if dep['binary']:
                        shell('systemctl enable '+dep['binary'])
                elif platform == 'debian':
                    try:
                        shell('apt-get -y --force-yes install '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'gentoo':
                    try:
                        shell('emerge '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'freebsd':
                    try:
                        shell('portupgrade -R '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                elif platform == 'centos' or platform == 'fedora':
                    try:
                        shell('yum -y install  '+dep['package'])
                    except:
                        raise SoftwareRequirementError(dep)
                else:
                    raise SoftwareRequirementError(dep)
        if dep['type'] == 'plugin':
            if not dep['package'] in PluginLoader.list_plugins() or \
                    PluginLoader.__plugins[dep['package']].problem:
                raise PluginRequirementError(dep)
        if dep['type'] == 'module':
            if dep.has_key('binary') and dep['binary']:
                try:
                    exec('import %s'%dep['binary'])
                except:
                    # Let's try to install it anyway
                    s = shell_cs('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package']))
                    if s[0] != 0:
                        raise ModuleRequirementError(dep, False)
                    else:
                        return 'Restart Genesis for changes to take effect.'
                        raise ModuleRequirementError(dep, False)
            else:
                p = False
                s = shell('pip%s freeze'%'2' if platform in ['arkos', 'arch'] else '')
                for x in s.split('\n'):
                    if dep['package'].lower() in x.split('==')[0].lower():
                        p = True
                if not p:
                    shell('pip%s install %s' % ('2' if platform in ['arkos', 'arch'] else '', dep['package']))
                    raise ModuleRequirementError(dep, True)
Example #20
0
 def verify_composer(self):
     if not shell_status('which composer') == 0:
         self.install_composer()
     if not shell_status('which composer') == 0:
         raise Exception('Composer was not installed successfully.')