Added SortApp project
This commit is contained in:
commit
6c5e520a94
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>sortapp</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
|
|
||||||
|
|
||||||
|
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||||
|
<path>/${PROJECT_DIR_NAME}/src</path>
|
||||||
|
</pydev_pathproperty>
|
||||||
|
</pydev_project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/sortapp/issupport.py=utf-8
|
||||||
|
encoding//src/sortapp/sortapp.py=utf-8
|
||||||
|
encoding//src/sortapp/storagehub/storagehubcommand.py=utf-8
|
||||||
|
encoding//src/sortapp/storagehub/storagehubcommanditemdownload.py=utf-8
|
||||||
|
encoding//src/sortapp/storagehub/storagehubcommanditemupload.py=utf-8
|
||||||
|
encoding/setup.py=utf-8
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Base
|
||||||
|
FROM python:3.6-alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache bash
|
||||||
|
|
||||||
|
# Istall deps
|
||||||
|
COPY ./requirements.txt /
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
|
||||||
|
# Install dist package sortapp
|
||||||
|
COPY ./dist/sortapp-1.0.0.tar.gz /
|
||||||
|
|
||||||
|
RUN pip3 install sortapp-1.0.0.tar.gz
|
||||||
|
|
||||||
|
#
|
||||||
|
#RUN rm sortapp-1.0.0.tar.gz
|
||||||
|
#RUN rm requirements.txt
|
||||||
|
#RUN rm -r /root/.cache
|
||||||
|
|
||||||
|
### Alternative ###
|
||||||
|
# Create a working directory and Bundle app source
|
||||||
|
# WORKDIR /sortapp
|
||||||
|
# COPY src/sortapp /sortapp
|
||||||
|
|
||||||
|
# Copy all subfolder
|
||||||
|
#ADD . /
|
||||||
|
|
||||||
|
# Autorun
|
||||||
|
# CMD [ "python3", "./sortapp.py" ]
|
|
@ -0,0 +1 @@
|
||||||
|
#Mit License
|
|
@ -0,0 +1,2 @@
|
||||||
|
include README.md
|
||||||
|
include LICENSE.md
|
|
@ -0,0 +1,42 @@
|
||||||
|
#SortAPP
|
||||||
|
|
||||||
|
SortApp is simple example that sort a file in input.
|
||||||
|
Starting from this example, you can first create an installable package via pip3 and then a docker image in which it is installed the created package.
|
||||||
|
The package declares the sortapp command as entrypoint.
|
||||||
|
So once the package is installed you can use this command at command line to run the example:
|
||||||
|
|
||||||
|
- sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||||
|
|
||||||
|
The image created in this way can be executed in a container with the following command:
|
||||||
|
|
||||||
|
- docker run -i -t --rm --name sortapp-cont sortapp sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||||
|
|
||||||
|
|
||||||
|
##Useful Commands
|
||||||
|
|
||||||
|
###Create Distribution Package
|
||||||
|
python3 setup.py sdist --formats=gztar
|
||||||
|
|
||||||
|
###Create Docker Image
|
||||||
|
docker build -t sortapp .
|
||||||
|
|
||||||
|
###Save Docker Image in file
|
||||||
|
docker save sortapp | gzip > sortapp.tar.gz
|
||||||
|
|
||||||
|
###Publish Docker Image on DockerHub
|
||||||
|
Name your local images using:
|
||||||
|
By re-tagging an existing local image:
|
||||||
|
|
||||||
|
- docker tag sortapp <hub-user>/<repo-name>[:<tag>]
|
||||||
|
|
||||||
|
Login in DockerHub(use your Docker ID):
|
||||||
|
|
||||||
|
- docker login
|
||||||
|
|
||||||
|
Now you can push this repository to the registry designated by its name or tag:
|
||||||
|
|
||||||
|
- docker push <hub-user>/<repo-name>:<tag>
|
||||||
|
|
||||||
|
Then logout for security:
|
||||||
|
|
||||||
|
- docker logout
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
###### Requirements without Version Specifiers ######
|
||||||
|
requests
|
||||||
|
|
||||||
|
###### Requirements with Version Specifiers ######
|
|
@ -0,0 +1,10 @@
|
||||||
|
python3
|
||||||
|
|
||||||
|
Token
|
||||||
|
xxxx-xxxx-xxxx-xxxx-xxxx
|
||||||
|
|
||||||
|
FileItemId
|
||||||
|
548eade8-25cf-4978-9f61-0f0c652900be
|
||||||
|
|
||||||
|
FolderItemId
|
||||||
|
32c0422f-a777-4452-adea-007347ec4484
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2020/06/12
|
||||||
|
#
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
with open("README.md", "r") as freadme:
|
||||||
|
l_description = freadme.read()
|
||||||
|
|
||||||
|
with open("LICENSE.md", "r") as flicense:
|
||||||
|
license_description = flicense.read()
|
||||||
|
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name="sortapp",
|
||||||
|
version="1.0.0",
|
||||||
|
author="Giancarlo Panichi",
|
||||||
|
author_email="giancarlo.panichi@isti.cnr.it",
|
||||||
|
description="A application for sort un text file",
|
||||||
|
long_description=l_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
license=license_description,
|
||||||
|
url="https://code-repo.d4science.org/gCubeSystem/sortapp",
|
||||||
|
package_dir={"": "src"},
|
||||||
|
packages=setuptools.find_packages(where="src"),
|
||||||
|
entry_points={
|
||||||
|
'console_scripts': ['sortapp=sortapp.sortapp:main']
|
||||||
|
},
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
platforms=["Linux"],
|
||||||
|
python_requires='>=3.6',
|
||||||
|
)
|
|
@ -0,0 +1,38 @@
|
||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: sortapp
|
||||||
|
Version: 1.0.0
|
||||||
|
Summary: A application for sort un text file
|
||||||
|
Home-page: https://code-repo.d4science.org/gCubeSystem/sortapp
|
||||||
|
Author: Giancarlo Panichi
|
||||||
|
Author-email: giancarlo.panichi@isti.cnr.it
|
||||||
|
License: #Mit License
|
||||||
|
Description: #SortAPP
|
||||||
|
|
||||||
|
SortApp is simple example that sort a file in input.
|
||||||
|
Starting from this example, you can first create an installable package via pip3 and then a docker image in which it is installed the created package.
|
||||||
|
The package declares the sortapp command as entrypoint.
|
||||||
|
So once the package is installed you can use this command at command line to run the example:
|
||||||
|
|
||||||
|
- sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||||
|
|
||||||
|
The image created in this way can be executed in a container with the following command:
|
||||||
|
|
||||||
|
- docker run -i -t --rm --name sortapp-cont sortapp-img sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||||
|
|
||||||
|
|
||||||
|
##Useful Commands
|
||||||
|
|
||||||
|
###Create Distribution Package
|
||||||
|
python3 setup.py sdist --formats=gztar
|
||||||
|
|
||||||
|
###Create Docker Image
|
||||||
|
docker build -t sortapp-img .
|
||||||
|
|
||||||
|
###Save Docker Image in file
|
||||||
|
docker save sortapp-img | gzip > sortapp-img.tar.gz
|
||||||
|
Platform: Linux
|
||||||
|
Classifier: Programming Language :: Python :: 3
|
||||||
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
|
Classifier: Operating System :: OS Independent
|
||||||
|
Requires-Python: >=3.6
|
||||||
|
Description-Content-Type: text/markdown
|
|
@ -0,0 +1,17 @@
|
||||||
|
LICENSE.md
|
||||||
|
MANIFEST.in
|
||||||
|
README.md
|
||||||
|
setup.py
|
||||||
|
src/sortapp/__init__.py
|
||||||
|
src/sortapp/__main__.py
|
||||||
|
src/sortapp/issupport.py
|
||||||
|
src/sortapp/sortapp.py
|
||||||
|
src/sortapp.egg-info/PKG-INFO
|
||||||
|
src/sortapp.egg-info/SOURCES.txt
|
||||||
|
src/sortapp.egg-info/dependency_links.txt
|
||||||
|
src/sortapp.egg-info/entry_points.txt
|
||||||
|
src/sortapp.egg-info/top_level.txt
|
||||||
|
src/sortapp/storagehub/__init__.py
|
||||||
|
src/sortapp/storagehub/storagehubcommand.py
|
||||||
|
src/sortapp/storagehub/storagehubcommanditemdownload.py
|
||||||
|
src/sortapp/storagehub/storagehubcommanditemupload.py
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[console_scripts]
|
||||||
|
sortapp = sortapp.sortapp:main
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
sortapp
|
|
@ -0,0 +1 @@
|
||||||
|
print("sortapp init")
|
|
@ -0,0 +1,2 @@
|
||||||
|
print('__main__.py executed')
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2018/06/15
|
||||||
|
#
|
||||||
|
import requests
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
class ISSupport:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
# dev
|
||||||
|
#self.serviceUrl = "https://node10-d-d4s.d4science.org"
|
||||||
|
# prod
|
||||||
|
self.serviceUrl = "http://registry.d4science.org"
|
||||||
|
self.storageHubServiceClass = "DataAccess"
|
||||||
|
self.storageHubServiceName = "StorageHub"
|
||||||
|
|
||||||
|
def discoverStorageHub(self,gcubeToken):
|
||||||
|
print("Discover StorageHub")
|
||||||
|
urlString = self.serviceUrl + "/icproxy/gcube/service/GCoreEndpoint/" + self.storageHubServiceClass + "/" + self.storageHubServiceName + "?gcube-token=" + gcubeToken
|
||||||
|
r = requests.get(urlString)
|
||||||
|
print(r.status_code)
|
||||||
|
print(r.text)
|
||||||
|
if r.status_code!=200:
|
||||||
|
print("Error discovering StorageHub: "+r.status_code)
|
||||||
|
raise Exception("Error retrieving StorageHub url info: "+r.status_code)
|
||||||
|
else:
|
||||||
|
root = ElementTree.fromstring(r.text)
|
||||||
|
print(root)
|
||||||
|
gcoreEndpoint=root.findall("Result/Resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint")
|
||||||
|
print(gcoreEndpoint)
|
||||||
|
for child in gcoreEndpoint:
|
||||||
|
print(child.tag, child.attrib)
|
||||||
|
if child.attrib["EntryName"]=="org.gcube.data.access.storagehub.StorageHub":
|
||||||
|
print("Endpoint Found")
|
||||||
|
print(child.text)
|
||||||
|
return child.text
|
||||||
|
|
||||||
|
print("Error discovering StorageHub url not found")
|
||||||
|
raise Exception("Error retrieving StorageHub url not found!")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'ISSupport[serviceUrl=' + str(self.serviceUrl) + ']'
|
|
@ -0,0 +1,78 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2020/06/12
|
||||||
|
#
|
||||||
|
import sys
|
||||||
|
from .issupport import ISSupport
|
||||||
|
from .storagehub.storagehubcommanditemdownload import StorageHubCommandItemDownload
|
||||||
|
from .storagehub.storagehubcommanditemupload import StorageHubCommandItemUpload
|
||||||
|
|
||||||
|
|
||||||
|
class SortApp:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.gcubeToken = sys.argv[1]
|
||||||
|
self.fileItemId = sys.argv[2]
|
||||||
|
self.tempFolderItemId = sys.argv[3]
|
||||||
|
self.destinationFile = "elements.txt"
|
||||||
|
self.storageHubUrl = None
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
print(self)
|
||||||
|
issup = ISSupport()
|
||||||
|
self.storageHubUrl = issup.discoverStorageHub(self.gcubeToken)
|
||||||
|
self.executeSort()
|
||||||
|
|
||||||
|
def executeSort(self):
|
||||||
|
print("Execute Sort")
|
||||||
|
print('gcubeToken: ' + self.gcubeToken)
|
||||||
|
print('fileItemId: ' + self.fileItemId)
|
||||||
|
|
||||||
|
if not self.gcubeToken:
|
||||||
|
raise Exception('Error Token is null')
|
||||||
|
|
||||||
|
if not self.fileItemId:
|
||||||
|
raise Exception('Error File Item Id is null')
|
||||||
|
|
||||||
|
cmdItemDownload = StorageHubCommandItemDownload(self.gcubeToken, self.storageHubUrl,
|
||||||
|
self.fileItemId, self.destinationFile)
|
||||||
|
cmdItemDownload.execute()
|
||||||
|
|
||||||
|
with open(self.destinationFile, 'r') as f:
|
||||||
|
elementsList = [line.strip() for line in f]
|
||||||
|
|
||||||
|
print ("Elements found: ")
|
||||||
|
print(*elementsList, sep="\n")
|
||||||
|
|
||||||
|
#if self.elementsOrder and self.elementsOrder == 'Desc':
|
||||||
|
# elementsList.sort(reverse=True)
|
||||||
|
#else:
|
||||||
|
elementsList.sort(reverse=False)
|
||||||
|
|
||||||
|
print ("Elements sorted: ")
|
||||||
|
print(*elementsList, sep="\n")
|
||||||
|
|
||||||
|
with open(self.destinationFile, 'w') as out_file:
|
||||||
|
out_file.write('\n'.join(elementsList))
|
||||||
|
|
||||||
|
print("Elements saved in file: " + self.destinationFile)
|
||||||
|
|
||||||
|
cmdItemUpload = StorageHubCommandItemUpload(self.gcubeToken, self.storageHubUrl, self.tempFolderItemId,
|
||||||
|
self.destinationFile, self.destinationFile, self.destinationFile)
|
||||||
|
cmdItemUpload.execute()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Sort App'
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print('SortApp main()')
|
||||||
|
sortApp = SortApp()
|
||||||
|
sortApp.main()
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
print("sortapp/storagehub init")
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2018/06/15
|
||||||
|
#
|
||||||
|
|
||||||
|
class StorageHubCommand:
|
||||||
|
def execute(self):
|
||||||
|
print("StorageHubCommand")
|
||||||
|
def __str__(self):
|
||||||
|
return 'StorageHubCommand'
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2018/06/15
|
||||||
|
#
|
||||||
|
import requests
|
||||||
|
from .storagehubcommand import StorageHubCommand
|
||||||
|
|
||||||
|
|
||||||
|
class StorageHubCommandItemDownload(StorageHubCommand):
|
||||||
|
|
||||||
|
def __init__(self, gcubeToken, storageHubUrl, itemId, destinationFile):
|
||||||
|
self.gcubeToken = gcubeToken
|
||||||
|
self.storageHubUrl = storageHubUrl
|
||||||
|
self.itemId = itemId
|
||||||
|
self.destinationFile = destinationFile
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
print("Execute StorageHubCommandItemDownload")
|
||||||
|
print(self.storageHubUrl + "/items/" + self.itemId + "/download?");
|
||||||
|
|
||||||
|
urlString = self.storageHubUrl + "/items/" + self.itemId + "/download?gcube-token=" + self.gcubeToken
|
||||||
|
r = requests.get(urlString)
|
||||||
|
print(r.status_code)
|
||||||
|
if r.status_code != 200:
|
||||||
|
print("Error in execute StorageHubCommandItemDownload: " + r.status_code)
|
||||||
|
raise Exception("Error in execute StorageHubCommandItemDownload: " + r.status_code)
|
||||||
|
with open(self.destinationFile, 'w') as file:
|
||||||
|
file.write(r.text)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return ('StorageHubCommandItemDownload[storageHubUrl=' + str(self.storageHubUrl) +
|
||||||
|
'itemId=' + self.itemId +
|
||||||
|
', destinationFile=' + self.destinationFile + ']')
|
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# @author: Giancarlo Panichi
|
||||||
|
#
|
||||||
|
# Created on 2018/06/15
|
||||||
|
#
|
||||||
|
import requests
|
||||||
|
from .storagehubcommand import StorageHubCommand
|
||||||
|
|
||||||
|
|
||||||
|
class StorageHubCommandItemUpload(StorageHubCommand):
|
||||||
|
|
||||||
|
def __init__(self, gcubeToken, storageHubUrl, folderItemId, file, filename, fileDescription):
|
||||||
|
self.gcubeToken = gcubeToken
|
||||||
|
self.folderItemId = folderItemId
|
||||||
|
self.storageHubUrl = storageHubUrl
|
||||||
|
self.file = file
|
||||||
|
self.filename = filename
|
||||||
|
self.fileDescription = fileDescription
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
print("Execute StorageHubCommandItemUpload")
|
||||||
|
print(self.storageHubUrl + "/items/" + self.folderItemId + "/create/FILE?");
|
||||||
|
|
||||||
|
filedata = {'name': self.filename, 'description': self.fileDescription, "file": ("file", open(self.file, "rb"))}
|
||||||
|
|
||||||
|
urlString = self.storageHubUrl + "/items/" + self.folderItemId + "/create/FILE?gcube-token=" + self.gcubeToken
|
||||||
|
r = requests.post(urlString, files=filedata)
|
||||||
|
print(r)
|
||||||
|
print(r.status_code)
|
||||||
|
if r.status_code != 200:
|
||||||
|
print("Error in execute StorageHubCommandItemUpload: " + r.status_code)
|
||||||
|
raise Exception("Error in execute StorageHubCommandItemUpload: " + r.status_code)
|
||||||
|
print(str(r.text))
|
||||||
|
return r.text
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return ('StorageHubCommandItemUpload[itemId=' + self.folderItemId +
|
||||||
|
', storageHubUrl=' + str(self.storageHubUrl) +
|
||||||
|
', folderItemId=' + str(self.folderItemId) +
|
||||||
|
', filename=' + str(self.filename) +
|
||||||
|
', fileDescription=' + str(self.fileDescription) + ']')
|
Loading…
Reference in New Issue