Commit be70bde6 authored by Janez K's avatar Janez K

Merge branch 'dev' of workflow.ijs.si:mothra into dev

parents 70d8956a c971b69b
......@@ -4,6 +4,7 @@ import os
PROJECT_DIR = os.path.dirname(__file__)
PUBLIC_DIR = os.path.join(PROJECT_DIR, 'public')
BACKUP_DIR = os.path.join(PROJECT_DIR, 'backup')
DEBUG = False
TEMPLATE_DEBUG = True
......
import os
# === STANDARD PACKAGE SETTINGS ===
PACKAGE_ROOT = os.path.dirname(__file__)
# === AUTO IMPORT OPTIONS ===
#If auto_import_package_data is true then given data file is automatically imported when ClowdFlows project is newly deployed or refreshed from git
AUTO_IMPORT_DB = True
#For auto_import_package_data_replace_option description see the 'replace' option in workflows/import_package command
AUTO_IMPORT_DB_REPLACE_OPTION = True
#If file(s) other than ./db/package_data.json should be imported, auto_import_package_data_files should be corrected
AUTO_IMPORT_DB_FILES = [os.path.join(PACKAGE_ROOT,'db/package_data.json')]
import sys
from django.shortcuts import render
from workflows import packageLibImporter
from workflows import module_importer
def setattr_local(name, value, package):
setattr(sys.modules[__name__], name, value)
packageLibImporter.importAllPackagesLib("interaction_views",setattr_local)
module_importer.import_all_packages_libs("interaction_views",setattr_local)
def test_interaction(request,input_dict,output_dict,widget):
return render(request, 'interactions/test_interaction.html',{'widget':widget})
......
This diff is collapsed.
import logging
import os
import sys
from settings import *
from settings import PACKAGE_ROOT
#------------------------------------------------------------------------------
# prepare environment for loading latino (Python.net interpreter should be used)
# see: http://pythonnet.sourceforge.net/
#------------------------------------------------------------------------------
sys.path.append(package_bin)
sys.path.append(os.path.join(PACKAGE_ROOT, 'bin'))
try:
from LatinoCloudFlows import *
import System
import Latino
from LatinoClowdFlows import *
except Exception:
logging.warning("LatinoClowdFlows could not be imported! Either there are no Latino dll available or a "\
"wrong interpreter is used. See 'http://pythonnet.sourceforge.net' for interpreter details. "\
"Other functionality (besides latino) will work as .")
logging.warning("DotNet assemblies could not be loaded! Probable reasons: missing dlls or wrong interpreter (see http://pythonnet.sourceforge.net). "
"Other functionality of ClowdFlows (besides .Net assemblies) should be OK!")
pass
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
\ No newline at end of file
This diff is collapsed.
from django.core.management.base import BaseCommand, CommandError
from workflows.models import Category, AbstractWidget, AbstractInput, AbstractOutput, AbstractOption
from django.core import serializers
from collections import Counter
from optparse import make_option
from workflows.latino.latino import LatinoCF
from pprint import pprint
import sys
class Command(BaseCommand):
args = 'file_name'
help = 'Export all widgets marked in the c# dll package as widgets to the json file which can be imported to the mothra database'
def handle(self, *args, **options):
if (len(args)<1):
raise CommandError('Argument "file_name" is required!')
try:
f = open(args[0], 'w')
except:
raise CommandError('There was a problem with creating/overwriting given output file')
self.stdout.write('Creating json representations of widgets, inputs, outputs, options and categories ... ')
outstr = LatinoCF.GetJsonDbDefinitions()
self.stdout.write('done.\n')
try:
f.write(outstr)
except:
raise CommandError('There was a problem with writing to the given output file')
self.stdout.write('Json definitions successfully created. Results written to the file.\n')
\ No newline at end of file
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
from collections import Counter
from optparse import make_option
from workflows.latino.import_dotnet import LatinoCF
from workflows.latino.import_dotnet import ClowdFlowsDefinitions
from pprint import pprint
import sys
from workflows.latino.settings import create_backups
from workflows.latino.settings import package_root
import workflows.management.commands.import_package
import os
import shutil
from datetime import datetime
from workflows.latino import serialization_utils
class Command(BaseCommand):
args = 'file_name'
help = 'Export all widgets marked in the c# dll package as widgets and directly imports them to the mothra database.' \
'As if "latino.generate_package a.json" followed by "workflows.import_package a.json" would be called.' \
'!However!, the export file goes to the standard place (latino/db/package_data.json) and replaces the existing file.' \
'Variable "create_backups" in "latino/setings.py" controls whether backups of package_data.json are kept in "latino/backups".'
option_list = BaseCommand.option_list + (
make_option('-f', '--force',
action="store_true",
dest='force',
default=False,
help='By default, the old "package_data.json" and newly generated definition strings are compared. In case there are no differences'
'nothing happens. This switch forces (regardles of equality) the import of the newly generated data and creation of backups '
'(if latino/setings.py/create_backups == True).'
),
make_option('-r', '--replace',
action="store_true",
dest='replace',
default=False,
help='Completely replace whole widgets with the new one where UIDs match. Default behaviour merges widgets sub-models (AbstractInputs, AbstractOutputs and AbstratcOptions)'
'based on their sub-model\'s own UID. When using the option "--replace" then all widget\'s old submodels are deleted and completely replaced by new sub-models.)'
),
)
def handle(self, *args, **options):
timeStamp = datetime.now().strftime('.backup_%Y%m%d_%H%M%S.json')
backupDir = os.path.join(package_root,"backup")
dataFileName = "package_data.json"
dataFilePath = os.path.join(package_root,"db",dataFileName)
dataFileBackupPath = os.path.join(backupDir,dataFileName)+timeStamp
codeFileName = "library_gen.py"
codeFilePath = os.path.join(package_root, codeFileName)
codeFileBackupPath = os.path.join(backupDir,codeFileName)+timeStamp
self.stdout.write('Creating json and python code representations of widgets, inputs, outputs, options and categories ... ')
newDataCode = serialization_utils.ToPyObj(ClowdFlowsDefinitions.Get())
newDataDef = newDataCode['json']
newCodeDef = newDataCode['library']
self.stdout.write('done.\n')
self.stdout.write('Reading previous json definitions if existing and compare to the new ... ')
oldDataDef = ""
try:
oldDataDef = open(dataFilePath).read()
except:
pass
self.stdout.write('done.\n')
dataReplace = True
if oldDataDef == newDataDef:
self.stdout.write('The newly generated data is the same as the file "latino/db/package_data.json".\n')
if not options['force']:
self.stdout.write('Nothing will be done with the data definition (use "--force" option to force the import).\n')
dataReplace = False
else:
self.stdout.write('The newly generated data is new or different from the file "latino/db/package_data.json".\n')
self.stdout.write('Reading previous code definitions if existing and compare to the new ... ')
oldCodeDef = ""
try:
oldCodeDef = open(codeFilePath).read()
except:
pass
self.stdout.write('done.\n')
codeReplace = True
if oldCodeDef == newCodeDef:
self.stdout.write('The newly generated code is the same as the file "latino/library_gen.py".\n')
if not options['force']:
self.stdout.write('Nothing will be done with the code file (use "--force" option to force the code replace).\n')
dataReplace = False
else:
self.stdout.write('The newly generated definitions are new or different from the file "latino/library_gen.py".\n')
if (dataReplace or codeReplace) and create_backups:
if not os.path.exists(backupDir):
os.makedirs(backupDir)
if dataReplace and create_backups and os.path.exists(dataFilePath):
try:
shutil.move(dataFilePath, dataFileBackupPath)
self.stdout.write('Backup of database successfully created.\n')
except:
raise CommandError('There was a problem with the operation of backing up the data file. '
'Procedure update_package was terminated without any changes to the database.')
if dataReplace:
open(dataFilePath,"w").write(newDataDef)
self.stdout.write('New data file successfully written to its location.\n')
importString = workflows.management.commands.import_package.Command()
importString.import_package_string(self, newDataDef, options['replace'])
self.stdout.write('Widget definitions in the database were updated successfully from the dll library.\n')
if codeReplace and create_backups and os.path.exists(codeFilePath):
try:
shutil.move(codeFilePath, codeFileBackupPath)
self.stdout.write('Backup of code successfully created.\n')
except:
raise CommandError('There was a problem with the operation of backing up the code file. Procedure update_package terminated.')
if codeReplace:
open(codeFilePath,"w").write(newCodeDef)
self.stdout.write('New code file successfully written to its location.\n')
self.stdout.write('Procedure update_package successfully finished.\n')
from import_dotnet import *
import time
import logging
try:
from import_dotnet import LatinoCF
from import_dotnet import Latino
from import_dotnet import System
except:
pass
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
#------------------------------supposed----------------------------------------
......@@ -281,7 +276,10 @@ def ToPyObj(data):
l.append(ToPyObj(val))
return tuple(l)
if hasattr(data, "GetType"):
for interface in data.GetType().GetInterfaces():
type = data.GetType()
if type.IsArray:
return [ToPyObj(x) for x in data]
for interface in type.GetInterfaces():
if interface.Name == u'ISerializable':
return LSO(data)
return data
import os
package_name = 'latino'
package_root = os.path.dirname(__file__)
package_statics = os.path.join(os.path.dirname(__file__), 'static', package_name)
package_bin = os.path.join(package_root, 'bin')
auto_update_db = True
create_backups = True
# === STANDARD PACKAGE SETTINGS ===
PACKAGE_ROOT = os.path.dirname(__file__)
# === AUTO IMPORT OPTIONS ===
#If auto_import_package_data is true then given data file is automatically imported when ClowdFlows project is newly deployed or refreshed from git
AUTO_IMPORT_DB = False
#For auto_import_package_data_replace_option description see the 'replace' option in workflows/import_package command
AUTO_IMPORT_DB_REPLACE_OPTION = True
#If file(s) other than ./db/package_data.json should be imported, auto_import_package_data_files should be corrected
AUTO_IMPORT_DB_FILES = [os.path.join(PACKAGE_ROOT,'db/package_data.json')]
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment