def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir plugin_dir = Environment.get_plugin_dir() builtin_plugin_dir = Environment.get_builtin_plugin_dir() dist_dir = Environment.get_dist_dir() log_dir = "%s/log" % Environment.get_tmp_dir() def CORS(): #cherrypy.response.headers["Access-Control-Allow-Origin"] = "http://192.168.0.15:8100" cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" cherrypy.response.headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept" cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS) config = { 'global': { 'server.socket_host': '127.0.0.1', 'server.socket_port': 80, 'log.screen': False, 'request.show_tracebacks': True, 'tools.log_headers.on': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.decode.on': True, 'tools.decode.encoding': 'utf-8', #'encoding_filter.on': True, #'decoding_filter.on': True 'tools.CORS.on': True }, '/context': {'tools.staticdir.on': True, 'tools.staticdir.dir': context_path, # Need to do this because on windows servers, jar files # are served as text/html 'tools.staticdir.content_types': { 'jar': 'application/java-archive' } }, '/assets': {'tools.staticdir.on': True, 'tools.staticdir.dir': Environment.get_asset_dir() }, '/doc': {'tools.staticdir.on': True, 'tools.staticdir.dir': doc_dir, 'tools.staticdir.index': "index.html" }, # NOTE: expose the entire plugins directory '/tactic/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/tactic/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/tactic/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, }, '/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, }, } # set up the root directory cherrypy.root = Root() cherrypy.tree.mount( cherrypy.root, config=config) from pyasm.search import Search search = Search("sthpw/project") search.add_filter("type", "resource", op="!=") projects = search.get_sobjects() # find out if one of the projects is the root root_initialized = False if not root_initialized: project_code = Project.get_default_project() if project_code and project_code !='default': from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True if not root_initialized: # load in the base site at root from tactic_sites.default.context.Index import Index cherrypy.root.tactic = Index() cherrypy.root.projects = Index() for project in projects: project_code = project.get_code() my.register_project(project_code, config) my.register_project("default", config) print from pyasm.security import Site site_obj = Site.get() site_obj.register_sites(my, config) #my.register_project("vfx", config, site="vfx_demo") #my.register_project("default", config, site="vfx_demo") return config
def __init__(my, **kwargs): super(PluginBase,my).__init__(**kwargs) # plugin sobject (Not really used anymore?) my.search_key = my.kwargs.get("search_key") zip_path = my.kwargs.get("zip_path") upload_file_name = my.kwargs.get("upload_file_name") my.base_dir = my.kwargs.get("base_dir") my.plugin_dir = my.kwargs.get("plugin_dir") my.manifest = my.kwargs.get("manifest") my.code = my.kwargs.get("code") my.version = my.kwargs.get("version") relative_dir = my.kwargs.get("relative_dir") my.verbose = my.kwargs.get("verbose") not in [False, 'false'] # at the end of this, the following variables are needed in order to # define the plugin # # version: the version of the plugin # plugin_dir: the directory where the plugin definition is located # manifest: the description of what is in the plugin if zip_path: # assume the zip path is the same as the basename basename = os.path.basename(zip_path) basename, ext = os.path.splitext(basename) assert ext == '.zip' tmp_dir = Environment.get_tmp_dir() unzip_dir = "%s/%s" % (tmp_dir, basename) if os.path.exists(unzip_dir): shutil.rmtree(unzip_dir) # unzip the file in to the tmp_dir or plugin_dir (for install) zip_util = ZipUtil() zip_util.extract(zip_path, base_dir=tmp_dir) # assume zip path my.plugin_dir, ext = os.path.splitext(zip_path) # mv from temp if my.plugin_dir != unzip_dir: if os.path.exists(my.plugin_dir): shutil.rmtree(my.plugin_dir) shutil.move(unzip_dir, my.plugin_dir) manifest_path = "%s/manifest.xml" % my.plugin_dir f = open(manifest_path, 'r') my.manifest = f.read() f.close() elif upload_file_name: # The path is moved to the plugin dir, if this process is taking # "local" file (such as one uploaded) upload_dir = Environment.get_upload_dir() upload_path = "%s/%s" % (upload_dir, upload_file_name) plugin_base_dir = Environment.get_plugin_dir() dist_dir = Environment.get_dist_dir() if not os.path.exists(dist_dir): os.makedirs(dist_dir) basename = os.path.basename(upload_path) #if os.path.exists("%s/%s" % (plugin_base_dir, basename)): # os.unlink("%s/%s" % (plugin_base_dir, basename) ) #shutil.move(upload_path, plugin_base_dir) # copy to dist folder if os.path.exists("%s/%s" % (dist_dir, basename)): os.unlink("%s/%s" % (dist_dir, basename) ) shutil.move(upload_path, dist_dir) zip_path = "%s/%s" % (dist_dir, upload_file_name) zip_util = ZipUtil() zip_util.extract(zip_path, base_dir=plugin_base_dir) my.plugin_dir = "%s/%s" % (plugin_base_dir, basename) my.plugin_dir = my.plugin_dir[:-4] manifest_path = "%s/manifest.xml" % (my.plugin_dir) if os.path.exists(manifest_path): f = open(manifest_path, 'r') my.manifest = f.read() f.close() else: # when uploading, this will likely not be needed my.manifest = "<manifest/>" return elif relative_dir: plugin_base_dir = Environment.get_plugin_dir() my.plugin_dir = "%s/%s" % (plugin_base_dir, relative_dir) manifest_path = "%s/manifest.xml" % my.plugin_dir if not os.path.exists(manifest_path): plugin_base_dir = Environment.get_builtin_plugin_dir() my.plugin_dir = "%s/%s" % (plugin_base_dir, relative_dir) manifest_path = "%s/manifest.xml" % my.plugin_dir f = open(manifest_path, 'r') my.manifest = f.read() f.close() elif my.plugin_dir: manifest_path = "%s/manifest.xml" % (my.plugin_dir) f = open(manifest_path, 'r') my.manifest = f.read() f.close() # get the plugin sobject elif my.search_key: plugin = SearchKey.get_by_search_key(my.search_key) my.manifest = plugin.get_value("manifest") my.code = plugin.get_code() my.version = plugin.get_value("version") elif my.manifest: # everything is extracted from the manifest later pass elif my.code: search = Search("config/plugin") search.add_filter("code", my.code) plugin = search.get_sobject() # In case there is extra plugins folder which is the case when the user # is developing. relative_dir = plugin.get_value("rel_dir") plugin_base_dir = Environment.get_plugin_dir() my.plugin_dir = "%s/%s" % (plugin_base_dir, relative_dir) # TODO: fix the ZipUtil.zip_dir() manifest_path = "%s/manifest.xml" % my.plugin_dir if not os.path.exists(manifest_path): plugin_base_dir = Environment.get_builtin_plugin_dir() my.plugin_dir = "%s/%s" % (plugin_base_dir, relative_dir) manifest_path = "%s/manifest.xml" % my.plugin_dir if os.path.exists(manifest_path): f = open(manifest_path, 'r') my.manifest = f.read() f.close() else: # this condition happens likely for a versioned installed plugin from a zip file # where it starts with an extra folder "plugins" and the rel_dir has not been recorded properly my.manifest = plugin.get_value("manifest") my.code = plugin.get_code() my.version = plugin.get_value("version") else: raise Exception("No plugin found") # assertions assert my.manifest # read the xml my.xml = Xml() my.xml.read_string(my.manifest) # if code is passed in, then use that. if not my.code: my.code = my.xml.get_value("manifest/data/code") # old implementation if not my.code: my.code = my.xml.get_value("manifest/@code") if not my.version: my.version = my.xml.get_value("manifest/data/version") assert my.code if not my.base_dir: if my.code.startswith("TACTIC"): my.base_dir = Environment.get_builtin_plugin_dir() else: my.base_dir = Environment.get_plugin_dir() # set the base directory for this particular plugin if not my.plugin_dir: if my.version: my.plugin_dir = "%s/%s-%s" % (my.base_dir, my.code, my.version) else: my.plugin_dir = "%s/%s" % (my.base_dir, my.code)
def execute(my): force = my.kwargs.get("force") clean = my.kwargs.get("clean") if clean in [False, 'false']: clean = False # ensure that plugin dir is empty if os.path.exists(my.plugin_dir): if clean: if force in ['true', True]: shutil.rmtree(my.plugin_dir) else: raise Exception("Plugin is already located at [%s]" % my.plugin_dir) if not os.path.exists(my.plugin_dir): os.makedirs(my.plugin_dir) # build the information from the manifest code = my.kwargs.get("code") if not code: code = my.xml.get_value("manifest/@code") version = my.kwargs.get("version") if not version: version = my.xml.get_value("manifest/@version") nodes = my.xml.get_nodes("manifest/*") # clean out all of the files my.delete_files(nodes) has_info = False sobjects = [] # handle all of the nodes in the manifest for i, node in enumerate(nodes): name = my.xml.get_node_name(node) if name == 'sobject': dumped_sobjects = my.handle_sobject(node) if not dumped_sobjects: dumped_sobjects = [] sobjects.extend(dumped_sobjects) elif name == 'search_type': my.handle_search_type(node) elif name == 'include': my.handle_include(node) elif name == 'python': my.handle_python(node) # make sure there is a data node and handle it data_node = my.xml.get_node("manifest/data") if data_node is None: root_node = my.xml.get_root_node() data_node = my.xml.create_element("data") child = my.xml.get_first_child(root_node) if child is None: my.xml.append_child(root_node, data_node) else: my.xml.insert_before(data_node, child) my.handle_data(data_node) manifest_path = "%s/manifest.xml" % (my.plugin_dir) file = codecs.getwriter('utf8')(open(manifest_path, 'wb')) file.write(my.xml.to_string()) file.close() # FIXME: leaving this out for now #my.handle_snapshots() dist_dir = my.kwargs.get("dist_dir") if not dist_dir: dist_dir = Environment.get_dist_dir() # get the basename of the code basecode = os.path.basename(my.code) # zip up the contents import zipfile if version: zip_path = "%s/%s-%s.zip" % (dist_dir, basecode, version) else: zip_path = "%s/%s.zip" % (dist_dir, basecode) print "Zipping up plugin file [%s]" % zip_path print " from [%s]" % my.plugin_dir from pyasm.common import ZipUtil ignore_dirs = ['.svn'] # ignore file #ignore_path = "%s/.ignore" % (my.plugin_dir) parts = my.code.split("/") root_dir = "%s/%s" % (my.base_dir, parts[0]) if len(parts) >= 2: include_dirs = ["/".join(parts[1:])] else: include_dirs = None ZipUtil.zip_dir(root_dir, zip_path, ignore_dirs=ignore_dirs, include_dirs=include_dirs) print "... done" #f = codecs.open(zip_path, 'w') #zip = zipfile.ZipFile(f, 'w', compression=zipfile.ZIP_DEFLATED) #my.zip_dir(zip, my.plugin_dir, "asset", rel_dir='') my.zip_path = zip_path # encrypt the file """ print "encrypting!!!!", zip_path my.enc_path = "%s.enc" % zip_path from pyasm.common import EncryptUtil ticket = "OMG" encrypt = EncryptUtil(ticket) encrypt.encrypt_file(zip_path) """ # register the plugin into the current project if my.kwargs.get("register") in [True, 'true']: # first check if a plugin with this code already exists plugin = Search.get_by_code("config/plugin", my.code) if plugin: raise TacticException("Plugin [%s] already existed in the project." % my.code) # create a new one plugin = SearchType.create("config/plugin") plugin.set_value("code", my.code) # update the information if version: plugin.set_value("version", version) # NOTE: not sure if this is desirable plugin.set_value("manifest", my.manifest) if my.plugin_dir.startswith(my.base_dir): rel_dir = my.plugin_dir.replace(my.base_dir, "") rel_dir = rel_dir.lstrip("/") plugin.set_value("rel_dir", rel_dir) plugin.commit() # record all of the sobject exported if plugin.get_value("type", no_exception=True) == "config": for sobject in sobjects: plugin_content = SearchType.create("config/plugin_content") plugin_content.set_value("search_type", sobject.get_search_type()) plugin_content.set_value("search_code", sobject.get_code()) plugin_content.set_value("plugin_code", my.code) plugin_content.commit()
# check that the main directories exists install_dir = os.getenv("TACTIC_INSTALL_DIR") data_dir = os.getenv("TACTIC_DATA_DIR") if not os.path.exists(install_dir): print "Environment variable TACTIC_INSTALL_DIR '%s' does not exist" % install_dir return if not os.path.exists(data_dir): print "Environment variable TACTIC_DATA_DIR '%s' does not exist" % data_dir return # create the dist folder dist_dir = Environment.get_dist_dir() if not os.path.exists(dist_dir): os.makedirs(dist_dir) self.create_temp_directory() self.change_directory_ownership() self.install_win32_service() if install_db == False: print "TACTIC setup successful. Next, the TACTIC database needs to be configured."
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir plugin_dir = Environment.get_plugin_dir() builtin_plugin_dir = Environment.get_builtin_plugin_dir() dist_dir = Environment.get_dist_dir() log_dir = "%s/log" % Environment.get_tmp_dir() config = { 'global': { 'server.socket_host': '127.0.0.1', 'server.socket_port': 80, 'log.screen': False, 'request.show_tracebacks': True, 'tools.log_headers.on': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.decode.on': True, 'tools.decode.encoding': 'utf-8', #'encoding_filter.on': True, #'decoding_filter.on': True }, '/context': { 'tools.staticdir.on': True, 'tools.staticdir.dir': context_path, # Need to do this because on windows servers, jar files # are served as text/html 'tools.staticdir.content_types': { 'jar': 'application/java-archive' } }, '/assets': { 'tools.staticdir.on': True, 'tools.staticdir.dir': Environment.get_asset_dir() }, '/doc': { 'tools.staticdir.on': True, 'tools.staticdir.dir': doc_dir, 'tools.staticdir.index': "index.html" }, # NOTE: expose the entire plugins directory '/tactic/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/tactic/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/tactic/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, } } # set up the root directory cherrypy.root = Root() cherrypy.tree.mount(cherrypy.root, config=config) from pyasm.search import Search search = Search("sthpw/project") search.add_filter("type", "resource", op="!=") projects = search.get_sobjects() # find out if one of the projects is the root root_initialized = False for project in projects: project_code = project.get_code() if False: from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True break if not root_initialized: project_code = Config.get_value("install", "default_project") if project_code and project_code != 'default': from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True if not root_initialized: # load in the base site at root from tactic_sites.default.context.Index import Index cherrypy.root.tactic = Index() cherrypy.root.projects = Index() for project in projects: project_code = project.get_code() my.register_site(project_code, config) my.register_site("default", config) return config
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir plugin_dir = Environment.get_plugin_dir() builtin_plugin_dir = Environment.get_builtin_plugin_dir() dist_dir = Environment.get_dist_dir() log_dir = "%s/log" % Environment.get_tmp_dir() config = { 'global': { 'server.socket_host': '127.0.0.1', 'server.socket_port': 80, 'log.screen': False, 'request.show_tracebacks': True, 'tools.log_headers.on': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.decode.on': True, 'tools.decode.encoding': 'utf-8', #'encoding_filter.on': True, #'decoding_filter.on': True } , '/context': {'tools.staticdir.on': True, 'tools.staticdir.dir': context_path, # Need to do this because on windows servers, jar files # are served as text/html 'tools.staticdir.content_types': { 'jar': 'application/java-archive' } }, '/assets': {'tools.staticdir.on': True, 'tools.staticdir.dir': Environment.get_asset_dir() }, '/doc': {'tools.staticdir.on': True, 'tools.staticdir.dir': doc_dir, 'tools.staticdir.index': "index.html" }, # NOTE: expose the entire plugins directory '/tactic/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/tactic/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/tactic/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, } } # set up the root directory cherrypy.root = Root() cherrypy.tree.mount( cherrypy.root, config=config) from pyasm.search import Search search = Search("sthpw/project") search.add_filter("type", "resource", op="!=") projects = search.get_sobjects() # find out if one of the projects is the root root_initialized = False """ for project in projects: project_code = project.get_code() if False: from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True break """ if not root_initialized: project_code = Project.get_default_project() if project_code and project_code !='default': from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True if not root_initialized: # load in the base site at root from tactic_sites.default.context.Index import Index cherrypy.root.tactic = Index() cherrypy.root.projects = Index() for project in projects: project_code = project.get_code() my.register_site(project_code, config) my.register_site("default", config) return config
asset_dir = Environment.get_asset_dir() if not os.path.exists(asset_dir): os.makedirs(asset_dir) # check that the main directories exists install_dir = os.getenv("TACTIC_INSTALL_DIR") data_dir = os.getenv("TACTIC_DATA_DIR") if not os.path.exists(install_dir): print "Environment variable TACTIC_INSTALL_DIR '%s' does not exist" % install_dir return if not os.path.exists(data_dir): print "Environment variable TACTIC_DATA_DIR '%s' does not exist" % data_dir return # create the dist folder dist_dir = Environment.get_dist_dir() if not os.path.exists(dist_dir): os.makedirs(dist_dir) self.create_temp_directory() self.change_directory_ownership() self.install_win32_service() if install_db == False: print "TACTIC setup successful. Next, the TACTIC database needs to be configured." return # dynamically load modules now that we know where they are from pyasm.search import DatabaseImpl, DbContainer
def execute(self, install_db=True, install_defaults=False, database_type='PostgresSQL', port_num='5432'): self.tactic_base_dir = None self.tactic_data_base_dir = None self.tactic_install_dir = None self.tmp_dir = None self.tactic_site_dir = None self.tactic_apache_user = '******' self.apache_conf_path = None self.database_type = database_type self.port_num = port_num self.backup_msg = None self.non_default_install = False project_code = "sthpw" project_type = "sthpw" self.print_header() # verification try: if install_db: self.check_db_program() self.check_db_exists(project_code) # install the necessary files to python directory self.install_to_python(install_defaults) except InstallException as e: print("Error: %s" %e.__str__()) print() print("Exiting...") print() sys.exit(2) self.update_tactic_configs() # check modules try: import tacticenv except ImportError: print('Error: Failed to "import tacticenv"') return self.check_modules(install_db) # create the asset_dir from pyasm.common import Environment asset_dir = Environment.get_asset_dir() if not os.path.exists(asset_dir): os.makedirs(asset_dir) # check that the main directories exists install_dir = os.getenv("TACTIC_INSTALL_DIR") data_dir = os.getenv("TACTIC_DATA_DIR") if not os.path.exists(install_dir): print("Environment variable TACTIC_INSTALL_DIR '%s' does not exist" % install_dir) return if not os.path.exists(data_dir): print("Environment variable TACTIC_DATA_DIR '%s' does not exist" % data_dir) return # create the dist folder dist_dir = Environment.get_dist_dir() if not os.path.exists(dist_dir): os.makedirs(dist_dir) self.create_temp_directory() self.change_directory_ownership() self.install_win32_service() if install_db == False: print("TACTIC setup successful. Next, the TACTIC database needs to be configured.") return # dynamically load modules now that we know where they are from pyasm.search import DatabaseImpl, DbContainer # create the sthpw database database = DatabaseImpl.get() # check if database exists print("Creating database '%s' ..." % project_code) print() db_exists = False from pyasm.search import DatabaseException try: if database.database_exists(project_code): print("... already exists. Please remove first") raise InstallException("Database '%s' already exists" % project_code) db_exists = True except DatabaseException as e: pass if not db_exists: # create the database database.create_database(project_code) # import the default schema database.import_schema(project_code, project_type) # import the default data database.import_default_data(project_code, project_type) # add the default user (admin) self.run_sql(''' --add in admin group INSERT INTO login_group (login_group, description) VALUES ('admin', 'Site Administration'); --add in admin user, default password 'tactic' INSERT INTO "login" ("login", "password", "upn", first_name, last_name) VALUES ('admin', '39195b0707436a7ecb92565bf3411ab1', 'admin', 'Admin', ''); --add the admin user to the admin group INSERT INTO login_in_group ("login", login_group) VALUES ('admin', 'admin'); ''') # add in the necessary triggers for email notification self.run_sql(''' --register notification INSERT INTO notification (code, description, "type", search_type, event) VALUES ('asset_attr_change', 'Attribute Changes For Assets', 'email', 'prod/asset', 'update|prod/asset'); INSERT INTO notification (code, description, "type", search_type, event) VALUES ('shot_attr_change', 'Attribute Changes For Shots', 'email', 'prod/shot', 'update|prod/shot'); ''') print("Upgrading the database schema in quiet mode...") print() from pyasm.search.upgrade import Upgrade from pyasm.security import Batch Batch() version = self.get_version() version.replace('.', '_') upgrade = Upgrade(version, is_forced=True, project_code=None, quiet=True) upgrade.execute() #print(os.system('python \"%s/src/bin/upgrade_db.py\" -f -q -y'%install_dir)) print() print() print("*** Installation of TACTIC completed at [%s] ***" %self.tactic_base_dir) print() print() #if self.backup_msg: # print(self.backup_msg) if os.name != 'nt': print("Next, please install the Apache Web Server and then copy the Apache config extension [%s] to the Apache web server config area. e.g. /etc/httpd/conf.d/"%self.apache_conf_path) else: print("Next, please install the Apache Web Server and then copy the Apache config extension [%s] to the Apache web server config area. e.g. C:/Program Files/Apache Software Foundation/Apache2.2/conf/"%self.apache_conf_path) print() print("Depending on the OS, you may need to add the following line to the main config file [httpd.conf] shipped with Apache as well:") print() if os.name == 'nt': print("Include conf/tactic_win32.conf") else: print("Include conf.d/*.conf") print()