def init(my): """initialize the widget_config, and from there retrieve the schema_config""" web = WebContainer.get_web() my.search_type = my.kwargs.get("search_type") element_name = my.kwargs.get("element_name") my.view = my.kwargs.get("view") # FIXME: comment out the assert for now to avoid error screen if not my.view: my.view = "table" # assert my.view my.config_xml = my.kwargs.get("config_xml") if not my.config_xml: my.config_xml = web.get_form_value("config_xml") my.default = my.kwargs.get("default") == "True" cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, element_name=element_name) Command.execute_cmd(cbk) my.config_string = "" my.data_type_string = "" my.name_string = "" my.title_string = "" my.nullable_string = "" my.has_column = True if element_name: if my.config_xml: my.config_string = my.config_xml whole_config_string = "<config><%s>%s</%s></config>" % (my.view, my.config_xml, my.view) config = WidgetConfig.get(xml=whole_config_string, view=my.view) my.config = WidgetConfigView(my.search_type, my.view, [config]) else: # don't pass in default here my.config = my.get_config(my.search_type, my.view) node = my.config.get_element_node(element_name) if node is not None: config_xml = my.config.get_xml() my.config_string = config_xml.to_string(node) my.title_string = config_xml.get_attribute(node, "title") schema_config = SearchType.get_schema_config(my.search_type) attributes = schema_config.get_element_attributes(element_name) my.data_type_string = attributes.get("data_type") # double_precision is float if my.data_type_string == "double precision": my.data_type_string = "float" my.name_string = attributes.get("name") my.nullable_string = attributes.get("nullable") my.is_new_column = attributes.get("new") == "True" # a database columnless widget if not my.name_string: my.has_column = False
def _test_status_change(self): '''Test a change to a single task.''' # Clear expression cache ExpressionParser.clear_cache() transaction = Transaction.get(create=True) task = Search.get_by_search_key(self.task_sk) new_status = 'pending' task.set_value("status", new_status) task.commit() transaction.commit() time.sleep(3) cmd = DynamicUpdateCmd(last_timestamp=self.last_timestamp, updates=self.updates) Command.execute_cmd(cmd) self.last_timestamp = cmd.get_info("timestamp") updates = cmd.get_info("updates") sobject = Search.get_by_search_key(self.search_key) num_tasks = Search.eval("@COUNT(@SOBJECT(sthpw/task))", sobject) self.assertEquals(updates["001"], num_tasks) self.assertEquals(updates["002"], new_status) self.assertEquals(updates["003"], "Loading ...") self.assertEquals(updates["004"], True) self.assertEquals(updates["005"], "Loading ...") self.assertEquals(updates["006"], num_tasks)
def _test_compare(self): '''Test early exiting of compare statements.''' # Clear expression cache ExpressionParser.clear_cache() transaction = Transaction.get(create=True) sobject = Search.get_by_search_key(self.search_key) tasks = Search.eval("@SOBJECT(sthpw/task)", sobject) new_status = 'complete' for task in tasks: task.set_value("status", new_status) task.commit() transaction.commit() time.sleep(3) cmd = DynamicUpdateCmd(last_timestamp=self.last_timestamp, updates=self.updates) Command.execute_cmd(cmd) self.last_timestamp = cmd.get_info("timestamp") updates = cmd.get_info("updates") self.assertEquals(updates["001"], 0) self.assertEquals(updates["002"], new_status) self.assertEquals(updates.get("003"), None) self.assertEquals(updates["004"], True) self.assertEquals(updates.get("005"), None) self.assertEquals(updates["006"], 0)
def checkin_textures(my, ticket, project_code, asset_code, paths, file_ranges, node_names, attrs, use_handoff_dir=False, md5s=[]): '''creates a number of textures under a single asset''' new_paths = [] try: my.init(ticket) Project.set_project(project_code) parent = Asset.get_by_code(asset_code) #parent = Search.get_by_search_key(search_key) context = 'publish' checkin = TextureCheckin(parent, context, paths, file_ranges, node_names, attrs, use_handoff_dir=use_handoff_dir, md5s=md5s) Command.execute_cmd(checkin) new_paths = checkin.get_texture_paths() #md5_list = checkin.get_texture_md5() file_code_list = checkin.get_file_codes() #loader_context = ProdLoaderContext() #updater = loader_context.get_updater(snapshot, asset_code, instance) #execute_xml = updater.get_execute_xml() #xml = execute_xml.to_string() finally: DbContainer.close_all() return new_paths, file_code_list
def execute(my): # get all of the commands web = WebContainer.get_web() # try the marshalled class marshall_list = [] marshalled = web.get_form_values("marshalled") for marshall in marshalled: # skip duplicated commands if marshall in marshall_list: continue else: marshall_list.append(marshall) marshaller = Marshaller.get_from_marshalled(marshall) cmd = marshaller.get_object() # we want to allow the page to draw, CmdReport will display the error try: Command.execute_cmd(cmd) except TacticException, e: pass except OSError, (errno, strerror): pass
def _test_insert(self): '''Test insertion of tasks and shots.''' # Commit creation of asset and tasks transaction = Transaction.get() transaction.commit() time.sleep(3) # Test initial insert of shot and tasks cmd = DynamicUpdateCmd(last_timestamp=self.last_timestamp, updates=self.updates) Command.execute_cmd(cmd) self.last_timestamp = cmd.get_info("timestamp") updates = cmd.get_info("updates") sobject = Search.get_by_search_key(self.search_key) num_tasks = Search.eval("@COUNT(@SOBJECT(sthpw/task))", sobject) self.assertEquals(updates["001"], num_tasks) task = Search.get_by_search_key(self.task_sk) status = task.get_value("status") self.assertEquals(updates["002"], status) self.assertEquals(updates["003"], "Loading ...") self.assertEquals(updates["004"], True) self.assertEquals(updates["005"], "Loading ...") self.assertEquals(updates["006"], num_tasks)
def checkin_shot_set(my, ticket, project_code, shot_code, process, context, \ checkin_as, currency, unknown_ref, desc): snapshot_code = '' try: my.init(ticket) Project.set_project(project_code) shot = Shot.get_by_code(shot_code) checkin = ShotCheckin(shot) checkin.set_description(desc) checkin.set_process(process) checkin.set_context(context) is_current = True if currency == 'False': is_current = False is_revision = False if checkin_as == 'Revision': is_revision = True checkin.set_current(is_current) checkin.set_revision(is_revision) checkin.set_option("unknown_ref", unknown_ref) Command.execute_cmd(checkin) snapshot_code = checkin.snapshot.get_code() finally: DbContainer.close_all() return snapshot_code
def _test_add_drop_column(my): #Project.set_project('unittest') from pyasm.command import ColumnAddCmd, ColumnDropCmd, Command cmd = ColumnAddCmd('unittest/country','special_place','varchar(256)') Command.execute_cmd(cmd) search_type = 'unittest/country' # clear cache SearchType.clear_column_cache(search_type) DatabaseImpl.clear_table_cache() exists = SearchType.column_exists(search_type, 'special_place') my.assertEquals(exists, True) # now drop the column cmd = ColumnDropCmd(search_type,'special_place') Command.execute_cmd(cmd) # clear cache SearchType.clear_column_cache(search_type) cache_dict = Container.get("DatabaseImpl:column_info") # assume database is the same as sthpw database_type = Project.get_by_code("unittest").get_database_type() db_resource = DbResource.get_default('unittest') table_info = cache_dict.get("%s:%s" % (db_resource, "country")) my.assertEquals(table_info == None, True) key = "%s:%s" % (db_resource, "country") cache_dict[key] = None exists = SearchType.column_exists(search_type, 'special_place') my.assertEquals(exists, False)
def create_set(my, ticket, project_code, set_name, cat_name, selected): '''an xml to create a new set node''' xml = '' asset_code = '' try: my.init(ticket) Project.set_project(project_code) cmd = MayaSetCreateCmd() cmd.set_set_name(set_name) cmd.set_cat_name(cat_name) Command.execute_cmd(cmd) asset_code = cmd.get_asset_code() if asset_code: cmd = CreateSetNodeCmd() cmd.set_asset_code(asset_code) cmd.set_instance(set_name) cmd.set_contents(selected) cmd.execute() execute_xml = cmd.get_execute_xml() xml = execute_xml.get_xml() finally: DbContainer.close_all() return [xml, asset_code]
def _test_add_drop_column(self): #Project.set_project('unittest') from pyasm.command import ColumnAddCmd, ColumnDropCmd, Command cmd = ColumnAddCmd('unittest/country', 'special_place', 'varchar(256)') Command.execute_cmd(cmd) search_type = 'unittest/country' # clear cache SearchType.clear_column_cache(search_type) DatabaseImpl.clear_table_cache() exists = SearchType.column_exists(search_type, 'special_place') self.assertEquals(exists, True) # now drop the column cmd = ColumnDropCmd(search_type, 'special_place') Command.execute_cmd(cmd) # clear cache SearchType.clear_column_cache(search_type) cache_dict = Container.get("DatabaseImpl:column_info") # assume database is the same as sthpw database_type = Project.get_by_code("unittest").get_database_type() db_resource = DbResource.get_default('unittest') table_info = cache_dict.get("%s:%s" % (db_resource, "country")) self.assertEquals(table_info == None, True) key = "%s:%s" % (db_resource, "country") cache_dict[key] = None exists = SearchType.column_exists(search_type, 'special_place') self.assertEquals(exists, False)
def test_all(my): '''entry point function''' my.description = "Checkin unit test" my.errors = [] Batch() # FIXME: this is needed for the triggers to be registerd. These # triggers have nothing to do with the web from pyasm.web import WebInit WebInit().execute() test_env = UnittestEnvironment() test_env.create() Project.set_project("unittest") try: Command.execute_cmd(my) # undo the command undo = UndoCmd() undo.execute() finally: test_env.delete()
def init(my): my.search_key = my.kwargs.get("search_key") my.update = my.kwargs.get("update") my.description = '' if my.update == "true": cmd = SecurityManagerCbk() cmd.set_search_key(my.search_key) Command.execute_cmd(cmd) my.description = cmd.get_description()
def init(self): self.search_key = self.kwargs.get("search_key") self.update = self.kwargs.get("update") self.description = '' if self.update == "true": cmd = SecurityManagerCbk() cmd.set_search_key(self.search_key) Command.execute_cmd(cmd) self.description = cmd.get_description()
def run_batch(kwargs): command = k.get("command") kwargs = k.get("kwargs") login = k.get("login") project_code = k.get("project_code") from pyasm.security import Batch Batch(project_code=project_code, login_code=login) cmd = Common.create_from_class_path(command, kwargs=kwargs) Command.execute_cmd(cmd)
def _test_empty_update(self): cmd = DynamicUpdateCmd(last_timestamp=self.last_timestamp, updates=self.updates) Command.execute_cmd(cmd) self.last_timestamp = cmd.get_info("timestamp") updates = cmd.get_info("updates") self.assertEquals(updates["001"], 0) self.assertEquals(updates.get("002"), None) self.assertEquals(updates.get("003"), None) self.assertEquals(updates.get("004"), None) self.assertEquals(updates.get("005"), None) self.assertEquals(updates.get("006"), None)
def _test_no_updates(self): '''Test no updates and set the initial timestamp''' transaction = Transaction.get(create=True) transaction.commit() from pyasm.command import Command cmd = DynamicUpdateCmd(last_timestamp=self.last_timestamp, updates=self.updates) Command.execute_cmd(cmd) self.last_timestamp = cmd.get_info("timestamp") updates = cmd.get_info("updates") self.assertEquals(updates, {})
def checkin_frames(my, ticket, project_code, queue_id): try: my.init(ticket) Project.set_project(project_code) cmd = CheckinFramesXMLRPC() cmd.set_args(ticket, queue_id) Command.execute_cmd(cmd) finally: DbContainer.close_all() return True
def main(): update = { "X123": { "search_key": "vfx/asset?project=vfx&code=chr001", "column": "name" }, "X124": { "search_key": "sthpw/login?code=admin", "expression": "@GET(.first_name) + ' ' + @GET(.last_name)" } } cmd = DynamicUpdateCmd(update=update) Command.execute_cmd(cmd)
def create_assets(my, ticket, project_code, set_code, names): try: my.init(ticket) Project.set_project(project_code) cmd = CreateSetAssetsCmd() cmd.set_set_code(set_code) cmd.set_names(names) Command.execute_cmd(cmd) asset_codes = cmd.get_asset_codes() finally: DbContainer.close_all() return asset_codes
def checkin_flash_shot(my, ticket, project_code,shot_code, context, comment): snapshot_code = '' try: my.init(ticket) Project.set_project(project_code) from pyasm.flash import FlashShotSObjectPublishCmd shot = Shot.get_by_code(shot_code) checkin = FlashShotSObjectPublishCmd(shot, context, comment) Command.execute_cmd(checkin) snapshot_code = checkin.snapshot.get_code() finally: DbContainer.close_all() return snapshot_code
def run_method(my, name, method): try: #upgrade = eval( '%s()' %my.__class__.__name__) upgrade = BaseUpgrade() except NameError: print "Failed to import upgrade script for %s" %my.__class__.__name__ return # substitute the function of 'execute' method with the # upgrade script Common.add_func_to_class(method, upgrade, upgrade.__class__, 'execute') upgrade.set_project(my.project_code) upgrade.set_upgrade_method(name) upgrade.set_quiet(my.quiet) upgrade.set_confirmed(my.is_confirmed) Command.execute_cmd(upgrade, call_trigger=False)
def checkin_set(my, ticket, project_code, asset_code, context): snapshot_code = '' try: my.init(ticket) Project.set_project(project_code) new_set = Asset.get_by_code(asset_code) checkin = MayaGroupCheckin(new_set) checkin.set_context(context) checkin.set_description("Initial Publish") Command.execute_cmd(checkin) snapshot_code = checkin.snapshot.get_code() finally: DbContainer.close_all() return snapshot_code
def run_method(my, name, method): try: #upgrade = eval( '%s()' %my.__class__.__name__) upgrade = BaseUpgrade() except NameError: print "Failed to import upgrade script for %s" % my.__class__.__name__ return # substitute the function of 'execute' method with the # upgrade script Common.add_func_to_class(method, upgrade, upgrade.__class__, 'execute') upgrade.set_project(my.project_code) upgrade.set_upgrade_method(name) upgrade.set_quiet(my.quiet) upgrade.set_confirmed(my.is_confirmed) Command.execute_cmd(upgrade, call_trigger=False)
def main(mode): manifest = ''' <manifest code='test_plugin' version='1'> <!-- <search_type code="prod/asset" path="search_type.spt"/> --> <sobject expr="@SOBJECT(config/custom_script['code','5CG'])" path="file.spt"/> <sobject expr="@SOBJECT(config/widget_config['code','35CG'])" path="file2.spt"/> </manifest> ''' if mode == 'create': plugin = PluginCreator(manifest=manifest) elif mode == 'install': plugin = PluginInstaller(manifest=manifest) elif mode == 'uninstall': plugin = PluginUninstaller(manifest=manifest) Command.execute_cmd(plugin)
def get_display(self): top = self.top top.add_style("padding: 10px") from tactic.command import IngestionCmd cmd = IngestionCmd(**self.kwargs) Command.execute_cmd(cmd) info = cmd.get_info() paths_matched = info.get("paths_matched") paths_not_matched = info.get("paths_not_matched") paths_irregular = info.get("paths_irregular") paths_invalid = info.get("paths_invalid") tags = info.get("tags") top.add("<br/>") #category_div = self.get_category_wdg(paths_matched, "Matched Paths", tags) #category_div = self.get_category_preview_wdg(paths_matched, "Matched Paths", tags) #top.add(category_div) category_div = self.get_category_wdg2(paths_matched, "Matched Paths", tags) top.add(category_div) top.add("<br/>") category_div = self.get_category_wdg2(paths_invalid, "Invalid Paths") top.add(category_div) top.add("<br/>") category_div = self.get_category_wdg2(paths_irregular, "Irregular Paths") top.add(category_div) top.add("<br/>") category_div = self.get_category_wdg2(paths_not_matched, "Unmatched Paths") top.add(category_div) return top
def test_all(my): # create a scene that will be checked in asset_code = "prp101" sid = "12345" # create an asset mel('sphere -n sphere1') mel('circle -n circle1') mel('group -n |%s |circle1 |sphere1' % asset_code) # convert node into a maya asset node = MayaNode("|%s" % asset_code) asset_node = MayaAssetNode.add_sid(node, sid) # checkin the asset checkin = MayaAssetNodeCheckin(asset_node) Command.execute_cmd(checkin) # create a file from this node asset_node.export()
def test_all(self): # create a scene that will be checked in asset_code = "prp101" sid = "12345" # create an asset mel('sphere -n sphere1') mel('circle -n circle1') mel('group -n |%s |circle1 |sphere1' % asset_code ) # convert node into a maya asset node = MayaNode("|%s" % asset_code ) asset_node = MayaAssetNode.add_sid( node, sid ) # checkin the asset checkin = MayaAssetNodeCheckin(asset_node) Command.execute_cmd(checkin) # create a file from this node asset_node.export()
def check_new_job(self, queue_type=None): num_jobs = len(self.jobs) if num_jobs >= self.max_jobs: print("Already at max jobs [%s]" % self.max_jobs) return self.job = self.get_next_job(queue_type) if not self.job: return # set the process key process_key = self.get_process_key() self.job.set_value("host", process_key) self.job.commit() self.jobs.append(self.job) # get some info from the job command = self.job.get_value("command") job_code = self.job.get_value("code") try: kwargs = self.job.get_json_value("data") except: try: # DEPRECATED kwargs = self.job.get_json_value("serialized") except: kwargs = {} if not kwargs: kwargs = {} login = self.job.get_value("login") script_path = self.job.get_value("script_path", no_exception=True) project_code = self.job.get_value("project_code") if script_path: command = 'tactic.command.PythonCmd' folder = os.path.dirname(script_path) title = os.path.basename(script_path) search = Search("config/custom_script") search.add_filter("folder", folder) search.add_filter("title", title) custom_script = search.get_sobject() script_code = custom_script.get_value("script") kwargs['code'] = script_code # add the job to the kwargs kwargs['job'] = self.job #print("command: ", command) #print("kwargs: ", kwargs) # Because we started a new thread, the environment may not # yet be initialized try: from pyasm.common import Environment Environment.get_env_object() except: # it usually is run at the very first transaction Batch() Project.set_project(project_code) queue = self.job.get_value("queue", no_exception=True) queue_type = 'repeat' stop_on_error = False print("Running job: ", self.job.get_value("code") ) if queue_type == 'inline': cmd = Common.create_from_class_path(command, kwargs=kwargs) try: Container.put(Command.TOP_CMD_KEY, None) Container.put(Transaction.KEY, None) Command.execute_cmd(cmd) # set job to complete self.job.set_value("state", "complete") except Exception as e: self.job.set_value("state", "error") self.job.commit() self.jobs.remove(self.job) self.job = None self.jobs_completed += 1 elif queue_type == 'repeat': attempts = 0 max_attempts = 3 retry_interval = 5 Container.put(Transaction.KEY, None) while 1: try: cmd = Common.create_from_class_path(command, kwargs=kwargs) Container.put(Command.TOP_CMD_KEY, None) Command.execute_cmd(cmd) #cmd.execute() # set job to complete self.job.set_value("state", "complete") break except TacticException as e: # This is an error on this server, so just exit # and don't bother retrying print("Error: ", e) self.job.set_value("state", "error") break except Exception as e: if stop_on_error: raise print("WARNING in Queue: ", e) import time time.sleep(retry_interval) attempts += 1 if attempts >= max_attempts: print("ERROR: reached max attempts") self.job.set_value("state", "error") break print("Retrying [%s]...." % attempts) self.job.commit() self.jobs.remove(self.job) self.job = None self.jobs_completed += 1 else: class ForkedTask(SchedulerTask): def __init__(self, **kwargs): super(ForkedTask, self).__init__(**kwargs) def execute(self): # check to see the status of this job """ job = self.kwargs.get('job') job_code = job.get_code() search = Search("sthpw/queue") search.add_filter("code", job_code) self.kwargs['job'] = search.get_sobject() if not job: print("Cancelling ...") return state = job.get_value("state") if state == "cancel": print("Cancelling 2 ....") return """ subprocess_kwargs = { 'login': login, 'project_code': project_code, 'command': command, 'kwargs': kwargs } subprocess_kwargs_str = jsondumps(subprocess_kwargs) install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = 'python' args = ['%s' % python, '%s/src/tactic/command/queue.py' % install_dir] args.append(subprocess_kwargs_str) import subprocess p = subprocess.Popen(args) DbContainer.close_thread_sql() return # can't use a forked task ... need to use a system call #Command.execute_cmd(cmd) # register this as a forked task task = ForkedTask(name=job_code, job=self.job) scheduler = Scheduler.get() scheduler.start_thread() # FIXME: the queue should not be inline if queue == 'interval': interval = self.job.get_value("interval") if not interval: interval = 60 scheduler.add_interval_task(task, interval=interval,mode='threaded') else: scheduler.add_single_task(task, mode='threaded')
class Usage(Exception): def __init__(self, msg): self.msg = msg if __name__ == '__main__': my_login = '******' batch = Batch(login_code=my_login) Project.set_project('flash') project_code = Project.get_project_code() args = sys.argv[1:] try: if len(args) != 1: raise Usage("A single episode code is expected.") seq = Episode.get_by_code(args[0]) if not seq: raise Usage("The episode code [%s] has not been registered for "\ "project [%s] in TACTIC. Please Insert it in the Episodes tab first." %(args[0], project_code)) except Usage, e: print e.msg sys.exit(2) command = AddFlashShotCmd(seq.get_code()) Command.execute_cmd(command)
def main(): cmd = TestPackageCmd() Command.execute_cmd(cmd)
def get_display(self): self.doc_mode = self.kwargs.get("doc_mode") path = self.kwargs.get("path") self.search_type = self.kwargs.get("search_type") self.last_path = None doc_key = self.kwargs.get("doc_key") if doc_key: self.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(self.doc) if snapshot: self.last_path = snapshot.get_lib_path_by_type('main') path = self.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not self.search_type: self.search_type = "test3/shot" self.column = "description" top = self.top top.add_class("spt_document_top") self.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' ''' } ) button.add_style("float: left") if not self.doc_mode: self.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(self.doc_mode) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not self.last_path and self.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = self.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(self.last_path, 'r') last_text = f.read() text = self.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) text = self.get_text(path, self.last_path) lines = text.split("\n") if self.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if self.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if self.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator( td,'TEXT_CTX' ) tr.add_class("spt_line"); else: SmartMenu.assign_as_local_activator( td,'TEXT_NEW_CTX' ) tr.add_class("spt_new_line"); td.add_class("spt_line_content"); td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' } ) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) # add a double click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' } ) # add a context menu ctx_menu = self.get_text_context_menu() ctx_new_menu = self.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu( text_wdg, menus_in, False ) panel = ViewPanelWdg( search_type=self.search_type, layout="blah" ) right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior( { 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' } ) top.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' } ) return top
self.command = None try: # reload the module #class_name = queue.get_value("command") #exec("reload(%s)" % class_name) self.command = pickle.loads( self.get_value("serialized") ) except Exception, e: print "Error: ", e.__str__() DbContainer.remove("sthpw") else: # execute the command print "executing: ", self.get_id(), self.command try: # refresh the environment and execute Command.execute_cmd(self.command) except Exception, e: ExceptionLog.log(e) print "Error: ", e.__str__() self.set_value("state", "error") description = self.get_value("description") self.set_value("description", "%s : %s" % \ (description, e.__str__()) ) self.commit() else: print "setting to done" self.set_value("state", "done") self.commit()
def get_display(my): my.doc_mode = my.kwargs.get("doc_mode") path = my.kwargs.get("path") my.search_type = my.kwargs.get("search_type") my.last_path = None doc_key = my.kwargs.get("doc_key") if doc_key: my.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(my.doc) if snapshot: my.last_path = snapshot.get_lib_path_by_type('main') path = my.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not my.search_type: my.search_type = "test3/shot" my.column = "description" top = my.top top.add_class("spt_document_top") my.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' ''' }) button.add_style("float: left") if not my.doc_mode: my.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(my.doc_mode) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not my.last_path and my.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = my.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(my.last_path, 'r') last_text = f.read() text = my.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) text = my.get_text(path, my.last_path) lines = text.split("\n") if my.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if my.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if my.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator(td, 'TEXT_CTX') tr.add_class("spt_line") else: SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX') tr.add_class("spt_new_line") td.add_class("spt_line_content") td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' }) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior({ 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' }) # add a double click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' }) # add a context menu ctx_menu = my.get_text_context_menu() ctx_new_menu = my.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False) panel = ViewPanelWdg(search_type=my.search_type, layout="blah") right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior({ 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' }) top.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' }) return top
def execute(my): web = WebContainer.get_web() alter_mode = my.kwargs.get("alter_mode") title = my.kwargs.get("title") config_mode = web.get_form_value("config_mode") view = web.get_form_value('view') constraint = web.get_form_value("config_constraint") data_type = '' if config_mode == "advanced": config_string = web.get_form_value("config_xml") if config_string: xml = Xml() xml.read_string(config_string) node = xml.get_root_node() data_type = xml.get_attribute(node, "data_type") nullable = xml.get_attribute(node, "nullable") in ['true', 'True'] else: data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() # if advanced is selected in the Widget Column view, data_type is '' # read from UI if not data_type and view == 'definition': data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() column_name = web.get_form_value("column_name") search_type = web.get_form_value("target_search_type") if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN: cmd = ColumnDropCmd(search_type, column_name) Command.execute_cmd(cmd) # delete widget config from definition view widget_config = WidgetDbConfig.get_by_search_type( search_type, 'definition') if widget_config: config = WidgetConfig.get( 'definition', xml=widget_config.get_xml_value('config')) config.remove_xml_element(column_name) new_xml = config.get_xml().to_string() widget_config.set_value("config", new_xml) widget_config.commit() # set cache to {} from pyasm.common import Container Container.put("WidgetConfigView:config_cache", {}) #Container.put("WidgetConfig:config_cache", {}) elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN: cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) element_options = {} element_options['type'] = data_type if title: element_options['title'] = title # handle the "default" view # update the widget config data type in the xml view = my.DEFAULT_VIEW config = WidgetDbConfig.get_by_search_type(search_type, view) if config: config.append_display_element(column_name, options={}, \ element_attrs=element_options) config.commit_config() elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN: cmd = ColumnAddCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) if constraint: # add constraint from pyasm.command import ColumnAddIndexWdg cmd = ColumnAddIndexWdg() cmd.execute() else: # remove constraint pass
def init(my): '''initialize the widget_config, and from there retrieve the schema_config''' web = WebContainer.get_web() my.search_type = my.kwargs.get('search_type') element_name = my.kwargs.get('element_name') my.view = my.kwargs.get('view') # FIXME: comment out the assert for now to avoid error screen if not my.view: my.view = 'table' #assert my.view my.config_xml = my.kwargs.get('config_xml') if not my.config_xml: my.config_xml = web.get_form_value('config_xml') my.default = my.kwargs.get('default') == 'True' cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, \ element_name=element_name) Command.execute_cmd(cbk) my.config_string = "" my.data_type_string = "" my.name_string = "" my.title_string = "" my.nullable_string = "" my.has_column = True if element_name: if my.config_xml: my.config_string = my.config_xml whole_config_string = "<config><%s>%s</%s></config>" % ( my.view, my.config_xml, my.view) config = WidgetConfig.get(xml=whole_config_string, view=my.view) my.config = WidgetConfigView(my.search_type, my.view, [config]) else: # don't pass in default here my.config = my.get_config(my.search_type, my.view) node = my.config.get_element_node(element_name) if node is not None: config_xml = my.config.get_xml() my.config_string = config_xml.to_string(node) my.title_string = config_xml.get_attribute(node, 'title') schema_config = SearchType.get_schema_config(my.search_type) attributes = schema_config.get_element_attributes(element_name) my.data_type_string = attributes.get("data_type") # double_precision is float if my.data_type_string == 'double precision': my.data_type_string = 'float' my.name_string = attributes.get("name") my.nullable_string = attributes.get("nullable") my.is_new_column = attributes.get("new") == 'True' # a database columnless widget if not my.name_string: my.has_column = False
def check_new_job(my): num_jobs = len(my.jobs) if num_jobs >= my.max_jobs: print "Already at max jobs [%s]" % my.max_jobs return my.job = my.get_next_job() if not my.job: return # set the process key process_key = my.get_process_key() my.job.set_value("host", process_key) my.job.commit() my.jobs.append(my.job) # get some info from the job command = my.job.get_value("command") job_code = my.job.get_value("code") try: kwargs = my.job.get_json_value("data") except: try: # DEPRECATED kwargs = my.job.get_json_value("serialized") except: kwargs = {} if not kwargs: kwargs = {} login = my.job.get_value("login") script_path = my.job.get_value("script_path", no_exception=True) project_code = my.job.get_value("project_code") if script_path: command = 'tactic.command.PythonCmd' folder = os.path.dirname(script_path) title = os.path.basename(script_path) search = Search("config/custom_script") search.add_filter("folder", folder) search.add_filter("title", title) custom_script = search.get_sobject() script_code = custom_script.get_value("script") kwargs['code'] = script_code # add the job to the kwargs kwargs['job'] = my.job #print "command: ", command #print "kwargs: ", kwargs # Because we started a new thread, the environment may not # yet be initialized try: from pyasm.common import Environment Environment.get_env_object() except: Batch() Project.set_project(project_code) queue = my.job.get_value("queue", no_exception=True) queue_type = 'repeat' stop_on_error = False print "Running job: ", my.job.get_value("code") if queue_type == 'inline': cmd = Common.create_from_class_path(command, kwargs=kwargs) try: Command.execute_cmd(cmd) # set job to complete my.job.set_value("state", "complete") except Exception, e: my.job.set_value("state", "error") my.job.commit() my.jobs.remove(my.job) my.job = None my.jobs_completed += 1
self.command = None try: # reload the module #class_name = queue.get_value("command") #exec("reload(%s)" % class_name) self.command = pickle.loads(self.get_value("serialized")) except Exception, e: print "Error: ", e.__str__() DbContainer.remove("sthpw") else: # execute the command print "executing: ", self.get_id(), self.command try: # refresh the environment and execute Command.execute_cmd(self.command) except Exception, e: ExceptionLog.log(e) print "Error: ", e.__str__() self.set_value("state", "error") description = self.get_value("description") self.set_value("description", "%s : %s" % \ (description, e.__str__()) ) self.commit() else: print "setting to done" self.set_value("state", "done") self.commit() def get_next_job(queue_type=None):
def execute(self): web = WebContainer.get_web() alter_mode = self.kwargs.get("alter_mode") title = self.kwargs.get("title") config_mode = web.get_form_value("config_mode") view = web.get_form_value('view') constraint = web.get_form_value("config_constraint") data_type = '' if config_mode == "advanced" : config_string = web.get_form_value("config_xml") if config_string: xml = Xml() xml.read_string(config_string) node = xml.get_root_node() data_type = xml.get_attribute(node, "data_type") nullable = xml.get_attribute(node, "nullable") in ['true','True'] else: data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() # if advanced is selected in the Widget Column view, data_type is '' # read from UI if not data_type and view == 'definition': data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() column_name = web.get_form_value("column_name") search_type = web.get_form_value("target_search_type") if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN: cmd = ColumnDropCmd(search_type, column_name) Command.execute_cmd(cmd) # delete widget config from definition view widget_config = WidgetDbConfig.get_by_search_type(search_type, 'definition') if widget_config: config = WidgetConfig.get('definition', xml=widget_config.get_xml_value('config')) config.remove_xml_element(column_name) new_xml = config.get_xml().to_string() widget_config.set_value("config", new_xml) widget_config.commit() # set cache to {} from pyasm.common import Container Container.put("WidgetConfigView:config_cache", {}) #Container.put("WidgetConfig:config_cache", {}) elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN: cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) element_options = {} element_options['type'] = data_type if title: element_options['title'] = title # handle the "default" view # update the widget config data type in the xml view = self.DEFAULT_VIEW config = WidgetDbConfig.get_by_search_type(search_type, view) if config: config.append_display_element(column_name, options={}, \ element_attrs=element_options) config.commit_config() elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN: cmd = ColumnAddCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) if constraint: # add constraint from pyasm.command import ColumnAddIndexWdg cmd = ColumnAddIndexWdg() cmd.execute() else: # remove constraint pass
def init(self): '''initialize the widget_config, and from there retrieve the schema_config''' web = WebContainer.get_web() self.search_type = self.kwargs.get('search_type') element_name = self.kwargs.get('element_name') self.view = self.kwargs.get('view') # FIXME: comment out the assert for now to avoid error screen if not self.view: self.view = 'table' #assert self.view self.config_xml = self.kwargs.get('config_xml') if not self.config_xml: self.config_xml = web.get_form_value('config_xml') self.default = self.kwargs.get('default') == 'True' cbk = ManageSearchTypeDetailCbk(search_type=self.search_type, view=self.view, \ element_name=element_name) Command.execute_cmd(cbk) self.config_string = "" self.data_type_string = "" self.name_string = "" self.title_string = "" self.nullable_string = "" self.has_column = True if element_name: if self.config_xml: self.config_string = self.config_xml whole_config_string = "<config><%s>%s</%s></config>"%(self.view, self.config_xml, self.view) config = WidgetConfig.get(xml=whole_config_string, view=self.view) self.config = WidgetConfigView(self.search_type, self.view, [config]) else: # don't pass in default here self.config = self.get_config(self.search_type, self.view) node = self.config.get_element_node(element_name) if node is not None: config_xml = self.config.get_xml() self.config_string = config_xml.to_string(node) self.title_string = config_xml.get_attribute(node, 'title') schema_config = SearchType.get_schema_config(self.search_type) attributes = schema_config.get_element_attributes(element_name) self.data_type_string = attributes.get("data_type") # double_precision is float if self.data_type_string == 'double precision': self.data_type_string = 'float' self.name_string = attributes.get("name") self.nullable_string = attributes.get("nullable") self.is_new_column = attributes.get("new") == 'True' # a database columnless widget if not self.name_string: self.has_column = False
search = Search(search_type) search.add_column("id") search.add_column("code") sobjects = search.get_sobjects() num = len(sobjects) print "Found [%s] of %s" % (num, search_type) for i, sobject in enumerate(sobjects): code = sobject.get_code() if code.startswith(server): continue if not code: #sobject.delete() continue if not code.startswith(prefixes[j]): continue print "(%s of %s) %s" % (i, num, code) new_code = "%s%s" % (server, code) sobject.set_value("code", new_code) sobject.commit() if __name__ == '__main__': cmd = RemapCodesCmd() Command.execute_cmd(cmd)
def _test_complete_trigger(my): cmd = WorkflowCmd() Command.execute_cmd(cmd)
def handle_transaction(my, base_dir, transaction_code, dirname): import time start = time.time() # check to see if the transaction exists already log = Search.get_by_code("sthpw/transaction_log", transaction_code) if log: print "Transaction [%s] already exists. Skipping ..." % log.get_code() return transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir, dirname) if not os.path.exists(transaction_path): # this file has not arrived yet, so ignore return manifest_path = "%s/%s/manifest.xml" % (base_dir, dirname) f = open(manifest_path) manifest_xml = f.read() f.close() transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir, dirname) search = Search("sthpw/sync_log") search.add_filter("transaction_code", transaction_code) sync_log = search.get_sobject() #if sync_log: # print "Already processed [%s]" % transaction_code # return try: from tactic.command import PluginInstaller from run_transaction_cmd import RunTransactionCmd # import the transaction data installer = PluginInstaller(manifest=manifest_xml) jobs = installer.import_data(transaction_path, commit=False) transaction_log = jobs[0] file_base_dir = "%s/%s" % (base_dir, dirname) # run the transaction in its own command from run_transaction_cmd import RunTransactionCmd run_transaction = RunTransactionCmd(transaction_xml=transaction_log, base_dir=file_base_dir) Command.execute_cmd(run_transaction) status = "complete" # May need special handing #except MissingItemException, e: # print "WARNING: Could not run transaction [%s]" % transaction_code # print "Error reported: ", str(e) # search = SearchType.create("sthpw/sync_error") except Exception, e: print "WARNING: Could not run transaction [%s]" % transaction_code print "Error reported: ", str(e) status = "error" error = str(e)
context == current_context): count += 1 if snapshot.get_value('is_latest') != True: change_count += 1 try: snapshot.set_latest() print "\t... set to is latest! ", search_type, search_id, context, version except Exception, e: print "\t ... WARNING: could not set latest:: ", search_type, search_id, context, version print "\t ... ", e current_search_type = search_type current_search_id = search_id current_context = context current_version = version print "Total is_latest: ", count print "Total is_latest set: ", change_count if __name__ == '__main__': Batch() Project.set_project("admin") start = time.time() cmd = FixIsLatestSnapshotCmd() Command.execute_cmd(cmd, call_trigger=False) print float(int( (time.time() - start) * 1000)) / 1000, "seconds"
def check_new_job(my): num_jobs = len(my.jobs) if num_jobs >= my.max_jobs: print "Already at max jobs [%s]" % my.max_jobs return my.job = my.get_next_job() if not my.job: return # set the process key process_key = my.get_process_key() my.job.set_value("host", process_key) my.job.commit() my.jobs.append(my.job) # get some info from the job command = my.job.get_value("command") job_code = my.job.get_value("code") #print "Grabbing job [%s] ... " % job_code try: kwargs = my.job.get_json_value("data") except: try: kwargs = my.job.get_json_value("serialized") except: kwargs = {} project_code = my.job.get_value("project_code") login = my.job.get_value("login") script_path = my.job.get_value("script_path", no_exception=True) if script_path: Project.set_project(project_code) command = 'tactic.command.PythonCmd' folder = os.path.dirname(script_path) title = os.path.basename(script_path) search = Search("config/custom_script") search.add_filter("folder", folder) search.add_filter("title", title) custom_script = search.get_sobject() script_code = custom_script.get_value("script") kwargs['code'] = script_code # add the job to the kwargs kwargs['job'] = my.job #print "command: ", command #print "kwargs: ", kwargs # Because we started a new thread, the environment may not # yet be initialized try: from pyasm.common import Environment Environment.get_env_object() except: print "running batch" Batch() queue = my.job.get_value("queue", no_exception=True) queue_type = 'repeat' print "running job: ", my.job.get_value("code") if queue_type == 'inline': cmd = Common.create_from_class_path(command, kwargs=kwargs) try: Command.execute_cmd(cmd) # set job to complete my.job.set_value("state", "complete") except Exception, e: my.job.set_value("state", "error") my.job.commit() my.jobs.remove(my.job) my.job = None