Beispiel #1
0
    def do_pull(self):
        print "[+] Pulling '{}'".format(self['name'])
        try:
            repo = Repo(self.path())

            if self['private']:
                with repo.git.custom_environment(
                        GIT_SSH_COMMAND=self['ssh_cmd']):
                    repo.remotes.origin.pull()
            else:
                repo.remotes.origin.pull()

            # Make sure we delete orphan .pyc files
            for root, dirs, files in os.walk(self.path()):
                for f in files:
                    f = os.path.join(root, f)
                    if f.endswith(".pyc") and not os.path.exists(f[:-1]):
                        print "Deleting orphan file '{}'".format(f)
                        os.remove(f)

            dispatcher.update_modules(self)
            self.update_value('status', 'active')
        except Exception, e:
            self['status'] = 'error'
            self['error_msg'] = 'Could not update repository.\n{}'.format(e)
            self.save()
Beispiel #2
0
    def do_clone(self):
        print(("[+] Cloning '{}'".format(self['name'])))
        try:
            if self['private']:
                Repo.clone_from(self['address'], self.path(), env=dict(GIT_SSH_COMMAND=self['ssh_cmd']))
            else:
                Repo.clone_from(self['address'], self.path())

            dispatcher.update_modules(self)
            self.update_value('status', 'active')
        except Exception as e:
            self['status'] = 'error'
            self['error_msg'] = 'Could not clone repository, probably due to authentication issues.\n{}'.format(e)
            self.save()

        internals = Internals.get(name="updates")
        internals.update_value("last_update", time())
Beispiel #3
0
    def reload(self):
        """Reload the workers

        .. :quickref: Module; Reload workers

        Requires the `manage_modules` permission.

        Returns "ok".
        """
        for repository in Repository.get_collection().find():
            dispatcher.update_modules(Repository(repository))

        updates = Internals(
            get_or_404(Internals.get_collection(), name="updates"))
        updates.update_value("last_update", time())

        flash(
            'Workers will reload once they are done with their current tasks',
            'success')

        return redirect('ok', url_for('ModulesView:index'))