def list(name=""):
        names = glob.glob(os.path.join(app.config['artifact-dir'],
                          '*' + name + '*'))
        try:
            content = [[strftime('%y-%m-%d', gmtime(os.stat(x).st_atime)),
                       cache.check(os.path.basename(x)),
                       os.path.basename(x)] for x in names]
        except:
            content = [['--------',
                       cache.check(os.path.basename(x)),
                       os.path.basename(x)] for x in names]

        return template('kbas',
                        title='Available Artifacts:',
                        content=reversed(sorted(content)),
                        css='static/style.css')
Exemple #2
0
    def list(name=""):
        names = glob.glob(os.path.join(app.config['artifact-dir'],
                          '*' + name + '*'))
        try:
            content = [[strftime('%y-%m-%d', gmtime(os.stat(x).st_atime)),
                       cache.check(os.path.basename(x)),
                       os.path.basename(x)] for x in names]
        except:
            content = [['--------',
                       cache.check(os.path.basename(x)),
                       os.path.basename(x)] for x in names]

        return template('kbas',
                        title='Available Artifacts:',
                        content=reversed(sorted(content)),
                        css='static/style.css')
    def post_artifact():
        if app.config['password'] is 'insecure' or \
                request.forms.get('password') != app.config['password']:
            print 'Upload attempt: password fail'
            app.config['last-reject'] = \
                datetime.now().strftime('%y-%m-%d %H:%M:%S')
            response.status = 401  # unauthorized
            return

        cache_id = request.forms.get('filename')
        if re.match('^[a-zA-Z0-9\.\-\_\@]*$', cache_id) is None:
            response.status = 400  # bad request, cache_id contains bad things
            return

        if os.path.isdir(os.path.join(app.config['artifact-dir'], cache_id)):
            if cache.check(cache_id) == request.forms.get('checksum', 'XYZ'):
                response.status = 777  # this is the same binary we have
                return
            response.status = 405  # not allowed, this artifact exists
            return

        tempfile.tempdir = app.config['artifact-dir']
        tmpdir = tempfile.mkdtemp()
        try:
            upload = request.files.get('file')
            artifact = os.path.join(tmpdir, cache_id)

            try:
                upload.save(artifact)
            except:
                # upload.save is only available in recent versions of bottle
                # troves (for example) have an older version... hence:
                with open(artifact, "w") as f:
                    f.write(upload.value)

            if call(['tar', 'tf', artifact]):
                app.log('UPLOAD', 'ERROR: not a valid tarfile:', artifact)
                raise
            checksum = cache.md5(artifact)
            with open(artifact + '.md5', "a") as f:
                f.write(checksum)
            shutil.move(tmpdir, os.path.join(app.config['artifact-dir'],
                                             cache_id))
            response.status = 201  # success!
            app.config['last-upload'] = datetime.now()
            return
        except:
            # something went wrong, clean up
            import traceback
            traceback.print_exc()
            try:
                shutil.rmtree(tmpdir)
            except:
                pass
            response.status = 500

        return
Exemple #4
0
    def post_artifact():
        if app.config['password'] is 'insecure' or \
                request.forms.get('password') != app.config['password']:
            print 'Upload attempt: password fail'
            app.config['last-reject'] = \
                datetime.now().strftime('%y-%m-%d %H:%M:%S')
            response.status = 401  # unauthorized
            return

        cache_id = request.forms.get('filename')
        if re.match('^[a-zA-Z0-9\.\-\_\@]*$', cache_id) is None:
            response.status = 400  # bad request, cache_id contains bad things
            return

        if os.path.isdir(os.path.join(app.config['artifact-dir'], cache_id)):
            if cache.check(cache_id) == request.forms.get('checksum', 'XYZ'):
                response.status = 777  # this is the same binary we have
                return
            response.status = 405  # not allowed, this artifact exists
            return

        tempfile.tempdir = app.config['artifact-dir']
        tmpdir = tempfile.mkdtemp()
        try:
            upload = request.files.get('file')
            artifact = os.path.join(tmpdir, cache_id)

            try:
                upload.save(artifact)
            except:
                # upload.save is only available in recent versions of bottle
                # troves (for example) have an older version... hence:
                with open(artifact, "w") as f:
                    f.write(upload.value)

            if call(['tar', 'tf', artifact]):
                app.log('UPLOAD', 'ERROR: not a valid tarfile:', artifact)
                raise
            checksum = cache.md5(artifact)
            with open(artifact + '.md5', "a") as f:
                f.write(checksum)
            shutil.move(tmpdir,
                        os.path.join(app.config['artifact-dir'], cache_id))
            response.status = 201  # success!
            app.config['last-upload'] = datetime.now()
            return
        except:
            # something went wrong, clean up
            import traceback
            traceback.print_exc()
            try:
                shutil.rmtree(tmpdir)
            except:
                pass
            response.status = 500

        return
Exemple #5
0
    def post_artifact():
        if app.config['password'] is 'insecure' or \
                request.forms.get('password') != app.config['password']:
            print 'Upload attempt: password fail'
            app.config['last-reject'] = \
                datetime.now().strftime('%y-%m-%d %H:%M:%S')
            response.status = 401  # unauthorized
            return
        cache_id = request.forms.get('filename')
        if os.path.isdir(os.path.join(app.config['artifact-dir'], cache_id)):
            if cache.check(cache_id) == request.forms.get('checksum', 'XYZ'):
                response.status = 777  # this is the same binary we have
                return
            response.status = 405  # method not allowed, this artifact exists
            return

        tempfile.tempdir = app.config['artifact-dir']
        tmpdir = tempfile.mkdtemp()
        try:
            upload = request.files.get('file')
            artifact = os.path.join(tmpdir, cache_id)
            upload.save(artifact)
            if call(['tar', 'tf', artifact]):
                app.log(this, 'ERROR: not a valid tarfile:', artifact)
                raise
            checksum = cache.md5(artifact)
            with open(artifact + '.md5', "a") as f:
                f.write(checksum)
            shutil.move(tmpdir, os.path.join(app.config['artifact-dir'],
                                             cache_id))
            response.status = 201  # success!
            app.config['last-upload'] = datetime.now()
            return
        except:
            # something went wrong, clean up
            try:
                shutil.rmtree(tmpdir)
            except:
                pass
            response.status = 999

        return