Skip to content

Commit

Permalink
rename to rebrand tunel to another project
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Dec 6, 2021
1 parent a596ab5 commit baac9c5
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 292 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Tunel
# Singularity Tunel

Application and general cluster tools using Singularity containers.

## Introduction

Manager and recipe generator for local Singularity containers

## Deployment
You should clone the repo, and build the container (or you can also just clone and then use docker-compose and it will be pulled from Docker Hub).


```bash
git clone https://www.github.com/vsoch/tunel
cd tunel
git clone https://github.com/singularityhub/singularity-tunel
cd singularity-tunel
docker build -t vanessa/tunel .
```

Expand Down
95 changes: 45 additions & 50 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,50 @@
# HELPER FUNCTIONS #######################################################################
##########################################################################################


def get_lookup():
'''get version by way of singularity.version, returns a
lookup dictionary with several global variables without
needing to import singularity
'''
lookup = dict()
version_file = os.path.join('tunel', 'version.py')
version_file = os.path.join("tunel", "version.py")
with open(version_file) as filey:
exec(filey.read(), lookup)
return lookup


# Read in requirements
def get_requirements(lookup=None):
'''get_requirements reads in requirements and versions from
the lookup obtained with get_lookup'''

if lookup == None:
lookup = get_lookup()

install_requires = []
for module in lookup['INSTALL_REQUIRES']:
for module in lookup["INSTALL_REQUIRES"]:
module_name = module[0]
module_meta = module[1]
if "exact_version" in module_meta:
dependency = "%s==%s" %(module_name,module_meta['exact_version'])
dependency = "%s==%s" % (module_name, module_meta["exact_version"])
elif "min_version" in module_meta:
if module_meta['min_version'] == None:
if module_meta["min_version"] == None:
dependency = module_name
else:
dependency = "%s>=%s" %(module_name,module_meta['min_version'])
dependency = "%s>=%s" % (module_name, module_meta["min_version"])
install_requires.append(dependency)
return install_requires


# Make sure everything is relative to setup.py
install_path = os.path.dirname(os.path.abspath(__file__))
install_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(install_path)

# Get version information from the lookup
lookup = get_lookup()
VERSION = lookup['__version__']
NAME = lookup['NAME']
AUTHOR = lookup['AUTHOR']
AUTHOR_EMAIL = lookup['AUTHOR_EMAIL']
PACKAGE_URL = lookup['PACKAGE_URL']
KEYWORDS = lookup['KEYWORDS']
DESCRIPTION = lookup['DESCRIPTION']
LICENSE = lookup['LICENSE']
with open('README.md') as filey:
VERSION = lookup["__version__"]
NAME = lookup["NAME"]
AUTHOR = lookup["AUTHOR"]
AUTHOR_EMAIL = lookup["AUTHOR_EMAIL"]
PACKAGE_URL = lookup["PACKAGE_URL"]
KEYWORDS = lookup["KEYWORDS"]
DESCRIPTION = lookup["DESCRIPTION"]
LICENSE = lookup["LICENSE"]
with open("README.md") as filey:
LONG_DESCRIPTION = filey.read()

##########################################################################################
Expand All @@ -67,31 +61,32 @@ def get_requirements(lookup=None):

INSTALL_REQUIRES = get_requirements(lookup)

setup(name=NAME,
version=VERSION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=AUTHOR,
maintainer_email=AUTHOR_EMAIL,
packages=find_packages(),
include_package_data=True,
zip_safe=False,
url=PACKAGE_URL,
license=LICENSE,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
keywords=KEYWORDS,
install_requires = INSTALL_REQUIRES,
classifiers=[
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
'Operating System :: Unix',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
entry_points = {'console_scripts': [ 'tunel=tunel:main' ] })
setup(
name=NAME,
version=VERSION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=AUTHOR,
maintainer_email=AUTHOR_EMAIL,
packages=find_packages(),
include_package_data=True,
zip_safe=False,
url=PACKAGE_URL,
license=LICENSE,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
keywords=KEYWORDS,
install_requires=INSTALL_REQUIRES,
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: C",
"Programming Language :: Python",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
],
entry_points={"console_scripts": ["tunel=tunel:main"]},
)
21 changes: 7 additions & 14 deletions tunel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
from flask import (
Flask,
url_for
)
from flask import Flask, url_for

from singularity.cli import Singularity
from utils import (
get_containers,
get_bases
)
from utils import get_containers, get_bases
import tempfile
import uuid
import os


# SERVER CONFIGURATION ##############################################
class SingularityServer(Flask):

def __init__(self, *args, **kwargs):
super(SingularityServer, self).__init__(*args, **kwargs)

self.containers = get_containers()
self.bases = get_bases()
self.tmpdir = tempfile.mkdtemp()
self.image = None # Holds image to run
self.image = None # Holds image to run
self.cli = Singularity()


Expand All @@ -33,10 +26,10 @@ def __init__(self, *args, **kwargs):
from views import *
from containers import *

if __name__ == '__main__':
if not os.path.exists('client_id.json'):
print('Client secrets file (client_id.json) not found in the app path.')
if __name__ == "__main__":
if not os.path.exists("client_id.json"):
print("Client secrets file (client_id.json) not found in the app path.")
exit()
app.debug = True
app.secret_key = str(uuid.uuid4())
app.run(host='0.0.0.0')
app.run(host="0.0.0.0")
61 changes: 31 additions & 30 deletions tunel/api.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
from flask_restful import Resource, Api
from singularity.cli import Singularity
from utils import (
get_container_links,
get_container_args,
get_container_labels
)
from utils import get_container_links, get_container_args, get_container_labels

from . import app

api = Api(app)


class apiContainers(Resource):
'''apiContainers
"""apiContainers
Main view for REST API to display all available containers
'''
"""

def get(self):
# Generate the url list for each container
response = {}
for cname,cpath in app.containers:
response[cname] = url_for('.api_container',cname)
for cname, cpath in app.containers:
response[cname] = url_for(".api_container", cname)
return response


class apiContainerArgs(Resource):
'''apiContainerArgs
'''
"""apiContainerArgs"""

def get(self, name):
if name in app.containers:
image_path = app.containers[name]
return get_container_args(image_path,cli=app.cli)
return get_container_args(image_path, cli=app.cli)
else:
return {'error':'Not Found'}
return {"error": "Not Found"}


class apiContainerLabels(Resource):
'''apiContainerLabels
'''
"""apiContainerLabels"""

def get(self, name):
if name in app.containers:
image_path = app.containers[name]
return get_container_labels(image_path,cli=app.cli)
return get_container_labels(image_path, cli=app.cli)
else:
return {'error':'Not Found'}
return {"error": "Not Found"}


class apiContainer(Resource):
'''apiContainer
display metadata and endpoints for a container
'''
"""apiContainer
display metadata and endpoints for a container
"""

def get(self, name):
if name in app.containers:
response = dict()
image_path = app.containers[name]
response['links'] = get_container_links(name)
response['args'] = get_container_args(image_path,cli=app.cli)
response['labels'] = get_container_labels(image_path,cli=app.cli)
response['name'] = name
response["links"] = get_container_links(name)
response["args"] = get_container_args(image_path, cli=app.cli)
response["labels"] = get_container_labels(image_path, cli=app.cli)
response["name"] = name
return response
else:
return {'error':'Not Found'}
return {"error": "Not Found"}



api.add_resource(apiContainers,'/api/containers')
api.add_resource(apiContainer,'/api/container/<string:name>')
api.add_resource(apiContainerArgs,'/api/container/args/<string:name>')
api.add_resource(apiContainerLabels,'/api/container/labels/<string:name>')
api.add_resource(apiContainers, "/api/containers")
api.add_resource(apiContainer, "/api/container/<string:name>")
api.add_resource(apiContainerArgs, "/api/container/args/<string:name>")
api.add_resource(apiContainerLabels, "/api/container/labels/<string:name>")
30 changes: 17 additions & 13 deletions tunel/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

# Supporting Functions


def get_home():
return pwd.getpwuid(os.getuid())[5]


def get_credentials():
userhome = get_home()
srcc = os.path.join(userhome,".srcc")
srcc = os.path.join(userhome, ".srcc")
if not os.path.exists(srcc):
os.mkdir(srcc)
credential_path = os.path.join(srcc,"gdrive-migration-credentials.json")
credential_path = os.path.join(srcc, "gdrive-migration-credentials.json")
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
Expand All @@ -27,21 +29,23 @@ def get_credentials():
return credentials



# Auth views

@app.route('/oauth2callback')
def oauth2callback():
flow = client.flow_from_clientsecrets('client_id.json',
scope='https://www.googleapis.com/auth/drive',
redirect_uri=flask.url_for('oauth2callback', _external=True))

flow.params['include_granted_scopes'] = 'true'
if 'code' not in flask.request.args:
@app.route("/oauth2callback")
def oauth2callback():
flow = client.flow_from_clientsecrets(
"client_id.json",
scope="https://www.googleapis.com/auth/drive",
redirect_uri=flask.url_for("oauth2callback", _external=True),
)

flow.params["include_granted_scopes"] = "true"
if "code" not in flask.request.args:
auth_uri = flow.step1_get_authorize_url()
return flask.redirect(auth_uri)
else:
auth_code = flask.request.args.get('code')
auth_code = flask.request.args.get("code")
credentials = flow.step2_exchange(auth_code)
open('credentials.json','w').write(credentials.to_json())
return flask.redirect(flask.url_for('index'))
open("credentials.json", "w").write(credentials.to_json())
return flask.redirect(flask.url_for("index"))

0 comments on commit baac9c5

Please sign in to comment.