def _check(my): # This will kill the TACTIC process # This is very harsh and should be used sparingly if at all use_restart = Config.get_value("services", "use_periodic_restart") if use_restart in [True, 'true']: if my.num_checks and my.num_checks % my.kill_interval == 0: # read pid file log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir, my.port), "r") pid = file.read() file.close() print "Killing process: ", pid Common.kill(pid) #my.run() my.num_checks += 1 return my.num_checks += 1 start = time.clock() try: response = my.check() except IOError, e: print "Tactic IOError: ", str(e) # Kill if unresponsive ... (only on linux) log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir, my.port), "r") pid = file.read() file.close() print "Killing process: ", pid Common.kill(pid)
def execute(my): SearchType.set_project(my.project) # multiple layers can get rendered for search_key in my.search_keys: f = file('%s/temp/render_exec.jsfl' % Environment.get_tmp_dir(), 'w') render_command = my.get_render_command(search_key, my.cam_search_key) f.write(render_command) f.write(my.get_render_log_command()) f.close() os.startfile( "\"%s\"" %f.name) my.remove_file(my.get_render_log_path()) # check if the render is done sys.stdout.write("\nRendering") while not os.path.isfile(my.get_render_log_path()): sys.stdout.write('. ') time.sleep(2) print f = file(my.get_render_log_path(), 'a') now = time.localtime(time.time()) f.write(' at %s' %time.asctime(now)) f.close() #my.convert_images() print("Checking in Render. . .") my.checkin_render()
def startup(port, server=""): from tactic.startup import FirstRunInit cmd = FirstRunInit() cmd.execute() log_dir = "%s/log" % Environment.get_tmp_dir() if not os.path.exists(log_dir): os.makedirs(log_dir) try: file = open("%s/pid.%s" % (log_dir,port), "w") pid = os.getpid() file.write(str(pid)) file.close() except IOError, e: if e.errno == 13: print print "Permission error opening the file [%s/pid.%s]." % (log_dir,port) print if os.name=='nt': print "You may need to run this shell as the Administrator." else: print "The file should be owned by the same user that runs this startup.py process." sys.exit(2)
def get_side_bar_cache(self, left_nav_wdg): project = Project.get() project_code = project.get_code() # do it with sobject #key = "%s_side_bar" % project.get_code() #cache = Search.get("sthpw/widget_cache") #cache.add_filter("key", key) #sobject = cache.get_sobject() #value = sobject.get_value("cache") login = Environment.get_user_name() tmp_dir = "%s/cache/side_bar" % Environment.get_tmp_dir() filename = "%s__%s.html" % (project_code, login) path = "%s/%s" % (tmp_dir, filename) # use files import os if os.path.exists(path): f = open(path, "r") html = f.read() f.close() else: dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) f = open(path, "w") html = left_nav_wdg.get_buffer_display() f.write(html) f.close() return html
def execute(my): SearchType.set_project(my.project) # multiple layers can get rendered for search_key in my.search_keys: f = file('%s/temp/render_exec.jsfl' % Environment.get_tmp_dir(), 'w') render_command = my.get_render_command(search_key, my.cam_search_key) f.write(render_command) f.write(my.get_render_log_command()) f.close() os.startfile("\"%s\"" % f.name) my.remove_file(my.get_render_log_path()) # check if the render is done sys.stdout.write("\nRendering") while not os.path.isfile(my.get_render_log_path()): sys.stdout.write('. ') time.sleep(2) print f = file(my.get_render_log_path(), 'a') now = time.localtime(time.time()) f.write(' at %s' % time.asctime(now)) f.close() #my.convert_images() print("Checking in Render. . .") my.checkin_render()
def get_render_dir(my): ticket = Environment.get_security().get_ticket_key() tmpdir = Environment.get_tmp_dir() render_dir = "%s/temp/%s" % (tmpdir, ticket) System().makedirs(render_dir) return render_dir
def final_kill(self): '''Kill the startup, startup_queue, watch_folder processes. This is used primarily in Windows Service. Linux service should have actively killed the processes already''' log_dir = "%s/log" % Environment.get_tmp_dir() files = os.listdir(log_dir) ports = [] watch_folders = [] queues = [] for filename in files: base, ext = os.path.splitext(filename) if base == 'pid': ports.append(ext[1:]) elif base == 'watch_folder': watch_folders.append(ext[1:]) elif base == 'startup_queue': queues.append(ext[1:]) for port in ports: try: file_name = "%s/pid.%s" % (log_dir,port) file = open(file_name, "r") pid = file.readline().strip() file.close() Common.kill(pid) except IOError, e: continue
def final_kill(self): '''Kill the startup, startup_queue, watch_folder processes. This is used primarily in Windows Service. Linux service should have actively killed the processes already''' log_dir = "%s/log" % Environment.get_tmp_dir() files = os.listdir(log_dir) ports = [] watch_folders = [] queues = [] for filename in files: base, ext = os.path.splitext(filename) if base == 'pid': ports.append(ext[1:]) elif base == 'watch_folder': watch_folders.append(ext[1:]) elif base == 'startup_queue': queues.append(ext[1:]) for port in ports: try: file_name = "%s/pid.%s" % (log_dir, port) file = open(file_name, "r") pid = file.readline().strip() file.close() Common.kill(pid) except IOError, e: continue
def _check(self): # This will kill the TACTIC process # This is very harsh and should be used sparingly if at all use_restart = Config.get_value("services", "use_periodic_restart") if use_restart in [True, 'true']: if self.num_checks and self.num_checks % self.kill_interval == 0: # read pid file log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir,self.port), "r") pid = file.read() file.close() Common.kill(pid) #self.run() self.num_checks += 1 return self.num_checks += 1 start = time.clock() try: response = self.check() except IOError, e: pid = self._get_pid() if pid: Common.kill(pid)
def handle_encrypted(my, base_dir, transaction_code, encrypted): key = my.ticket from_path = "%s/%s" % (base_dir, encrypted) tmp_dir = Environment.get_tmp_dir(include_ticket=True) if encrypted.endswith(".enc"): to_path = "%s/%s" % (tmp_dir, encrypted) to_path = to_path.replace(".enc", "") encrypt_util = EncryptUtil(key) encrypt_util.decrypt_file(from_path, to_path) zip_util = ZipUtil() to_dir = os.path.dirname(to_path) zip_util.extract(to_path) else: to_path = from_path to_dir = tmp_dir zip_util = ZipUtil() zip_util.extract(to_path, to_dir) dirname = encrypted.replace(".enc", "") dirname = dirname.replace(".zip", "") print "Running transaction: [%s]" % transaction_code my.handle_transaction(to_dir, transaction_code, dirname)
def convert_file(my, src_path, dst_path): upgrade_dir = Environment.get_upgrade_dir() tmp_dir = Environment.get_tmp_dir() dir = os.path.dirname(dst_path) if dir and not os.path.exists(dir): os.makedirs(dir) f = open(src_path, 'r') f2 = open(dst_path, 'w') # prepend lines lines = my.get_prepend_lines() for line in lines: f2.write(line) for line in f.xreadlines(): line = my.handle_line(line) if line == None: continue f2.write(line) f.close() f2.close() return dst_path
def startup(port, server=""): from tactic.startup import FirstRunInit cmd = FirstRunInit() cmd.execute() log_dir = "%s/log" % Environment.get_tmp_dir() if not os.path.exists(log_dir): os.makedirs(log_dir) try: file = open("%s/pid.%s" % (log_dir,port), "w") pid = os.getpid() file.write(str(pid)) file.close() except IOError, e: if e.errno == 13: print print "Permission error opening the file [%s/pid.%s]." % (log_dir,port) print if os.name=='nt': print "You may need to run this shell as the Administrator." else: print "The file should be owned by the same user that runs this startup_dev.py process." sys.exit(2)
def execute(my): sobject = my.get_caller() search_type = sobject.get_base_search_type() all_logins = False if search_type == 'config/widget_config': category = sobject.get_value("category") if not category: category = sobject.get_value("search_type") if category != 'SideBarWdg': return user = sobject.get_value('login') user = user.strip() if not user: all_logins = True from pyasm.biz import Project project = Project.get() project_code = project.get_code() login = Environment.get_user_name() tmp_dir = "%s/cache/side_bar" % Environment.get_tmp_dir() project_check = True if search_type == 'sthpw/login_group': login_objs = sobject.get_logins() logins = [x.get_value('login') for x in login_objs] project_check = False else: if all_logins: expr = '@GET(sthpw/login.login)' logins = Search.eval(expr) else: logins = [login] filenames = [] if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) return search = Search('sthpw/project') projects = search.get_sobjects() project_codes = [x.get_value('code') for x in projects] for login in logins: if project_check: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) else: for project_code in project_codes: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) #filenames = os.listdir(tmp_dir) for filename in filenames: #if not filename.startswith("%s__" % project_code): # print "skip filename ", filename path = "%s/%s" % (tmp_dir, filename) if os.path.exists(path): print "Deleting: ", path os.unlink(path)
def convert_file(self, src_path, dst_path): upgrade_dir = Environment.get_upgrade_dir() tmp_dir = Environment.get_tmp_dir() dir = os.path.dirname(dst_path) if dir and not os.path.exists(dir): os.makedirs(dir) f = open(src_path, 'r') f2 = open(dst_path, 'w') # prepend lines lines = self.get_prepend_lines() for line in lines: f2.write(line) for line in f.xreadlines(): line = self.handle_line(line) if line == None: continue f2.write(line) f.close() f2.close() return dst_path
def execute(self): tmp_dir = Environment.get_tmp_dir() # remove the sidebar cache sidebar_cache_dir = "%s/cache/side_bar" % tmp_dir if os.path.exists(sidebar_cache_dir): import shutil shutil.rmtree(sidebar_cache_dir)
def _check(self): # This will kill the TACTIC process # This is very harsh and should be used sparingly if at all use_restart = Config.get_value("services", "use_periodic_restart") if use_restart in [True, 'true']: if self.num_checks and self.num_checks % self.kill_interval == 0: # read pid file log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir, self.port), "r") pid = file.read() file.close() Common.kill(pid) #self.run() self.num_checks += 1 return self.num_checks += 1 start = time.clock() try: response = self.check() except IOError, e: pid = self._get_pid() if pid: Common.kill(pid)
def get_side_bar_cache(my, left_nav_wdg): project = Project.get() project_code = project.get_code() # do it with sobject #key = "%s_side_bar" % project.get_code() #cache = Search.get("sthpw/widget_cache") #cache.add_filter("key", key) #sobject = cache.get_sobject() #value = sobject.get_value("cache") login = Environment.get_user_name() tmp_dir = "%s/cache/side_bar" % Environment.get_tmp_dir() filename = "%s__%s.html" % (project_code, login) path = "%s/%s" % (tmp_dir, filename) # use files import os if os.path.exists(path): f = open(path, "r") html = f.read() f.close() else: dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) f = open(path, "w") html = left_nav_wdg.get_buffer_display() f.write(html) f.close() return html
def write_log(self, msg): '''for debugging only''' log_dir = "%s/log" % Environment.get_tmp_dir() f = open('%s/monitor.log' % log_dir, 'a') import datetime f.write('\nTime: %s\n\n' % datetime.datetime.now()) f.write('%s\n' % msg)
def write_log(self, msg): '''for debugging only''' log_dir = "%s/log" % Environment.get_tmp_dir() f = open('%s/monitor.log' % log_dir,'a') import datetime f.write('\nTime: %s\n\n' %datetime.datetime.now()) f.write('%s\n'%msg)
def start(cls): print "Running Watch Folder ..." # Check whether the user define the drop folder path. # Default dop folder path: /tmp/drop parser = OptionParser() parser.add_option("-p", "--project", dest="project", help="Define the project_name.") parser.add_option("-d", "--drop_path", dest="drop_path", help="Define drop folder path") parser.add_option("-s", "--search_type", dest="search_type", help="Define search_type.") parser.add_option("-P", "--process", dest="process", help="Define process.") parser.add_option("-S", "--script_path",dest="script_path", help="Define script_path.") (options, args) = parser.parse_args() if options.project != None : project_code= options.project else: project_code= 'jobs' if options.drop_path!=None : drop_path= options.drop_path else: tmp_dir = Environment.get_tmp_dir() drop_path = "%s/drop" % tmp_dir print " using [%s]" % drop_path if not os.path.exists(drop_path): os.makedirs(drop_path) if options.search_type!=None : search_type = options.search_type else: search_type = 'jobs/media' if options.process!=None : process = options.process else: process= 'publish' if options.script_path!=None : script_path = options.script_path else: script_path="None" task = WatchDropFolderTask(base_dir=drop_path, project_code=project_code,search_type=search_type, process=process,script_path=script_path) scheduler = Scheduler.get() scheduler.add_single_task(task, delay=1) scheduler.start_thread() return scheduler
def _get_pid(self): '''Get PID from a file''' log_dir = "%s/log" % Environment.get_tmp_dir() pid_path = "%s/pid.%s" % (log_dir, self.port) pid = 0 if os.path.exists(pid_path): file = open(pid_path, "r") pid = file.read() file.close() return pid
def write_stop_monitor(): '''write a stop.monitor file to notify TacticMonitor to exit''' log_dir = "%s/log" % Environment.get_tmp_dir() if not os.path.exists(log_dir): os.makedirs(log_dir) file = open("%s/stop.monitor" % log_dir, "w") pid = os.getpid() file.write(str(pid)) file.close()
def convert_upgrade(self, namespace): self.namespace = namespace upgrade_dir = Environment.get_upgrade_dir() tmp_dir = Environment.get_tmp_dir() src_path ="%s/project/%s_upgrade.py" % (upgrade_dir, namespace) dst_path = "%s/upgrade/%s/%s_upgrade.py" % (tmp_dir, self.vendor, namespace) self.convert_file(src_path, dst_path) return dst_path
def _parse_form(my): # get the downloaded files and sort them web = WebContainer.get_web() my.upload_values.sort() filenames = [] ticket = web.get_cookie("login_ticket") # create a new entry for every file for upload_value in my.upload_values: tmp_dir = Environment.get_tmp_dir() basename = os.path.basename(upload_value) file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename) filenames.append(basename) creator = IconCreator(file_path) creator.create_icons() my.file_paths = [file_path] file_types = ["main"] web_path = creator.get_web_path() if web_path != None: my.file_paths.append(web_path) file_types.append("web") icon_path = creator.get_icon_path() if icon_path != None: my.file_paths.append(icon_path) file_types.append("icon") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) else: sobject = SObjectFactory.create(my.search_type) sobject.commit() checkin = FileCheckin( sobject, my.file_paths, file_types,\ column=my.column ) checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT)) checkin.execute() my.repo_file_list.append(checkin.file_dict) my.description = "Added files: %s" % filenames
def postprocess(my): if my.sobject.is_general_asset(): return # check to see if there are any snapshots # context is specified here to ignore any icon snapshots snapshot = Snapshot.get_latest_by_sobject(my.sobject, context='publish') if snapshot: return column = "snapshot" new_file_paths = [] file_paths = [] # copy the default file to /tmp template_code = my.get_default_code() template = my.get_template_obj() if template: template_code = template.get_value('code') tmpl_snapshot = Snapshot.get_latest_by_sobject(template) file_paths = tmpl_snapshot.get_all_lib_paths() else: file_types = ['.fla', '.png', '_icon.png', '.swf'] # TODO: this is a web depedency we don't need from pyasm.web import WebContainer web = WebContainer.get_web() for type in file_types: file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \ template_code, type)) for file_path in file_paths: # rename and copy each file to /tmp base_name = os.path.basename(file_path) base_name = File.remove_file_code(base_name) base_name = base_name.replace(template_code, \ my.get_naming().get_current_code(my.sobject) ) # do a straight copy : No undo tmp_dir = Environment.get_tmp_dir() new_file_path = "%s/download/%s" % (tmp_dir, base_name) shutil.copyfile(file_path, new_file_path) new_file_paths.append(new_file_path) file_types = [".fla", ".png", "icon", ".swf"] checkin = FileCheckin( my.sobject, new_file_paths, file_types, \ snapshot_type="flash", column=column ) checkin.execute()
def postprocess(my): if my.sobject.is_general_asset(): return # check to see if there are any snapshots # context is specified here to ignore any icon snapshots snapshot = Snapshot.get_latest_by_sobject(my.sobject, context='publish') if snapshot: return column = "snapshot" new_file_paths = [] file_paths = [] # copy the default file to /tmp template_code = my.get_default_code() template = my.get_template_obj() if template: template_code = template.get_value('code') tmpl_snapshot = Snapshot.get_latest_by_sobject(template) file_paths = tmpl_snapshot.get_all_lib_paths() else: file_types = ['.fla','.png','_icon.png','.swf'] # TODO: this is a web depedency we don't need from pyasm.web import WebContainer web = WebContainer.get_web() for type in file_types: file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \ template_code, type)) for file_path in file_paths: # rename and copy each file to /tmp base_name = os.path.basename(file_path) base_name = File.remove_file_code(base_name) base_name = base_name.replace(template_code, \ my.get_naming().get_current_code(my.sobject) ) # do a straight copy : No undo tmp_dir = Environment.get_tmp_dir() new_file_path = "%s/download/%s" % (tmp_dir,base_name) shutil.copyfile(file_path, new_file_path) new_file_paths.append(new_file_path) file_types = [".fla", ".png", "icon",".swf"] checkin = FileCheckin( my.sobject, new_file_paths, file_types, \ snapshot_type="flash", column=column ) checkin.execute()
def _check(my): # This will kill the TACTIC process # This is very harsh and should be used sparingly if at all use_restart = Config.get_value("services", "use_periodic_restart") if use_restart in [True, 'true']: if my.num_checks and my.num_checks % my.kill_interval == 0: # read pid file log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir,my.port), "r") pid = file.read() file.close() print "Killing process: ", pid Common.kill(pid) #my.run() my.num_checks += 1 return my.num_checks += 1 start = time.clock() try: response = my.check() except IOError, e: print "Tactic IOError: ", str(e) # Kill if unresponsive ... (only on linux) log_dir = "%s/log" % Environment.get_tmp_dir() file = open("%s/pid.%s" % (log_dir,my.port), "r") pid = file.read() file.close() print "Killing process: ", pid Common.kill(pid)
def _parse_form(my): # get the downloaded files and sort them web = WebContainer.get_web() my.upload_values.sort() filenames = [] ticket = web.get_cookie("login_ticket") # create a new entry for every file for upload_value in my.upload_values: tmp_dir = Environment.get_tmp_dir() basename = os.path.basename(upload_value) file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename) filenames.append(basename) creator = IconCreator(file_path) creator.create_icons() my.file_paths = [file_path] file_types = ["main"] web_path = creator.get_web_path() if web_path != None: my.file_paths.append(web_path) file_types.append("web") icon_path = creator.get_icon_path() if icon_path != None: my.file_paths.append(icon_path) file_types.append("icon") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) else: sobject = SObjectFactory.create(my.search_type) sobject.commit() checkin = FileCheckin(sobject, my.file_paths, file_types, column=my.column) checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT)) checkin.execute() my.repo_file_list.append(checkin.file_dict) my.description = "Added files: %s" % filenames
def dump(my, field_storage, file_name): web = WebContainer.get_web() ticket = web.get_form_value("transaction_ticket") if not ticket: security = Environment.get_security() ticket = security.get_ticket_key() tmpdir = Environment.get_tmp_dir() subdir = web.get_form_value("subdir") if subdir: file_dir = "%s/%s/%s/%s" % (tmpdir, "upload", ticket, subdir) else: file_dir = "%s/%s/%s" % (tmpdir, "upload", ticket) # With some recent change done in cherrypy._cpreqbody line 294 # we can use the field storage directly and just move the file # without using FileUpload path = field_storage.get_path() if path and file_name: if not os.path.exists(file_dir): os.makedirs(file_dir) basename = os.path.basename(path) to_path = "%s/%s" % (file_dir, file_name) if os.name == 'nt': # windows does not do anything.. and it shouldn't even get to # this point for windows. pass else: shutil.move(path, to_path) # Because _cpreqbody makes use of mkstemp, the file permissions # are set to 600. This switches to the permissions as defined # by the TACTIC users umask try: current_umask = os.umask(0) os.umask(current_umask) os.chmod(to_path, 0o666 - current_umask) except Exception, e: print "WARNING: ", e return [to_path]
def start(cls): print "Running Watch Folder ..." # Check whether the user define the drop folder path. # Default dop folder path: /tmp/drop parser = OptionParser() parser.add_option("-p", "--project", dest="project", help="Define the project_name.") parser.add_option("-d", "--drop_path", dest="drop_path", help="Define drop folder path") parser.add_option("-s", "--search_type", dest="search_type", help="Define search_type.") parser.add_option("-P", "--process", dest="process", help="Define process.") (options, args) = parser.parse_args() if options.project != None : project_code= options.project else: project_code= 'jobs' if options.drop_path!=None : drop_path= options.drop_path else: tmp_dir = Environment.get_tmp_dir() drop_path = "%s/drop" % tmp_dir print " using [%s]" % drop_path if not os.path.exists(drop_path): os.makedirs(drop_path) if options.search_type!=None : search_type = options.search_type else: search_type = 'jobs/media' if options.process!=None : process = options.process else: process= 'publish' task = WatchDropFolderTask(base_dir=drop_path, project_code=project_code,search_type=search_type, process=process) scheduler = Scheduler.get() scheduler.add_single_task(task, delay=1) scheduler.start_thread() return scheduler
def download_transaction_files(self, transactions): '''This uses a simple httpd download mechanism to get the files. ''' remote_host = sync_utils.get_remote_host() download_mode = 'http' # Try a mode where files are zipped if download_mode == 'zip': remote_server.download_zip(paths) # go through each transaction and look at the files for transaction in transactions: transaction_xml = transaction.get("transaction") cmd = TransactionFilesCmd(transaction_xml=transaction_xml, mode='relative') paths = cmd.execute() # download to the temp dir to_dir = Environment.get_tmp_dir() ticket = Environment.get_ticket() to_dir = "%s/%s" % (to_dir, ticket) # or we could download directly to that asset directory base_dir = Environment.get_asset_dir() # do the slow method for path in paths: url = "%s/assets/%s" % (remote_host, path) print("downloading: ", url) remote_server.download(url, to_dir) # FIXME: the problem with this is that it is not undoable #dirname = os.path.dirname(path) #to_dir = "%s/%s" % (base_dir, dirname) #print("to_dir: ", to_dir) remote_server.download(url, to_dir)
def convert_sqlite_upgrade(namespace): upgrade_dir = Environment.get_upgrade_dir() tmp_dir = Environment.get_tmp_dir() src_path = "%s/project/%s_upgrade.py" % (upgrade_dir, namespace) path = "%s/upgrade/sqlite/%s_upgrade.py" % (tmp_dir, namespace) dir = os.path.dirname(path) if not os.path.exists(dir): os.makedirs(dir) f = open(src_path, 'r') f2 = open(path, 'w') for line in f.xreadlines(): if line.find("serial PRIMARY KEY") != -1: line = line.replace("serial PRIMARY KEY", "integer PRIMARY KEY AUTOINCREMENT") elif line.find("PRIMARY KEY") != -1: if line.find("ALTER TABLE") != -1: pass else: pass elif line.find("now()") != -1: line = line.replace("now()", "CURRENT_TIMESTAMP") elif line.startswith("class "): line = "class Sqlite%sUpgrade(BaseUpgrade):\n" % namespace.capitalize( ) elif line.startswith("__all__ "): line = "__all__ = ['Sqlite%sUpgrade']\n" % namespace.capitalize() f2.write(line) #print line.rstrip() f.close() f2.close() return path
def write_pid(idx): log_dir = "%s/log" % Environment.get_tmp_dir() if not os.path.exists(log_dir): os.makedirs(log_dir) try: file = open("%s/startup_queue.%s" % (log_dir, idx), "w") pid = os.getpid() file.write(str(pid)) file.close() except IOError, e: if e.errno == 13: print print "Permission error opening the file [%s/startup_queue.%s]." % (log_dir, idx) print if os.name == 'nt': print "You may need to run this shell as the Administrator." else: print "The file should be owned by the same user that runs this startup_queue.py process." sys.exit(2)
def stop(): #startup.stop() log_dir = "%s/log" % Environment.get_tmp_dir() files = os.listdir(log_dir) ports = [] for filename in files: base, ext = os.path.splitext(filename) if base =='pid': ports.append(ext[1:]) for port in ports: try: file_name = "%s/pid.%s" % (log_dir,port) file = open(file_name, "r") pid = file.readline().strip() os.system('taskkill /F /PID %s'%pid) file.close() except IOError, e: print "Error opening file [%s]" %file_name continue
def monitor(self): '''monitor the tactic threads''' start_time = time.time() log_dir = "%s/log" % Environment.get_tmp_dir() while 1: end = False try: monitor_stop = os.path.exists('%s/stop.monitor' % log_dir) if monitor_stop: for tactic_thread in self.tactic_threads: tactic_thread.end = True break if self.check_interval: # don't check threads during startup period if not self.startup: time.sleep(self.check_interval) for tactic_thread in self.tactic_threads: tactic_thread._check() else: if time.time() - start_time > self.check_interval: self.startup = False else: # Windows Service does not need this 0 check_interval # any more. break except KeyboardInterrupt, e: #print("Keyboard interrupt ... exiting Tactic") for tactic_thread in self.tactic_threads: tactic_thread.end = True end = True if end: break
def monitor(self): '''monitor the tactic threads''' start_time = time.time() log_dir = "%s/log" % Environment.get_tmp_dir() while 1: end = False try: monitor_stop = os.path.exists('%s/stop.monitor'%log_dir) if monitor_stop: for tactic_thread in self.tactic_threads: tactic_thread.end = True break if self.check_interval: # don't check threads during startup period if not self.startup: time.sleep(self.check_interval) for tactic_thread in self.tactic_threads: tactic_thread._check() else: if time.time() - start_time > self.check_interval: self.startup = False else: # Windows Service does not need this 0 check_interval # any more. break except KeyboardInterrupt, e: #print("Keyboard interrupt ... exiting Tactic") for tactic_thread in self.tactic_threads: tactic_thread.end = True end = True if end: break
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 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
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 create_temp_directory(my): from pyasm.common import Environment my.tmp_dir = Environment.get_tmp_dir() print "Creating TACTIC temp directories: ", my.tmp_dir if not os.path.exists(my.tmp_dir): os.makedirs(my.tmp_dir)
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir log_dir = "%s/log" % Environment.get_tmp_dir() config = { 'global': { 'server.socket_host': 'localhost', 'server.socket_port': 80, 'server.log_to_screen': False, 'server.environment': 'production', 'server.show_tracebacks': True, 'server.log_request_headers': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'log_debug_info_filter.on': False, #'encoding_filter.on': True, #'decoding_filter.on': True, }, '/context': { 'static_filter.on': True, 'static_filter.dir': context_path }, '/assets': { 'static_filter.on': True, 'static_filter.dir': Environment.get_asset_dir() }, '/doc': { 'static_filter.on': True, 'static_filter.dir': doc_dir }, '/doc/': { 'static_filter.on': True, 'static_filter.file': "%s/index.html" % doc_dir }, } # set up the root directory cherrypy.root = Root() from tactic_sites.default.context.TitlePage import TitlePage cherrypy.root.tactic = TitlePage() cherrypy.root.projects = TitlePage() sites = [] # add the tactic projects install_dir = Environment.get_install_dir().replace("\\", "/") site_dir = "%s/src/tactic_sites" % install_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) # add all the custom projects site_dir = Environment.get_site_dir().replace("\\", "/") site_dir = "%s/sites" % site_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) for site in sites: my.register_site(site, config) # set up the images directory for subdir in ['images', 'doc']: config["/tactic/%s/%s/" % (site,subdir)] = { 'static_filter.on': True, 'static_filter.dir': '%s/sites/%s/context/%s/' % \ (site_dir,site, subdir) } return config
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir log_dir = "%s/log" % Environment.get_tmp_dir() config = { 'global': {'server.socket_host': 'localhost', 'server.socket_port': 80, 'server.log_to_screen': False, 'server.environment': 'production', 'server.show_tracebacks': True, 'server.log_request_headers': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'log_debug_info_filter.on': False, #'encoding_filter.on': True, #'decoding_filter.on': True, }, '/context': {'static_filter.on': True, 'static_filter.dir': context_path }, '/assets': {'static_filter.on': True, 'static_filter.dir': Environment.get_asset_dir() }, '/doc': {'static_filter.on': True, 'static_filter.dir': doc_dir }, '/doc/': {'static_filter.on': True, 'static_filter.file': "%s/index.html" % doc_dir }, } # set up the root directory cherrypy.root = Root() from tactic_sites.default.context.TitlePage import TitlePage cherrypy.root.tactic = TitlePage() cherrypy.root.projects = TitlePage() sites = [] # add the tactic projects install_dir = Environment.get_install_dir().replace("\\", "/") site_dir = "%s/src/tactic_sites" % install_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) # add all the custom projects site_dir = Environment.get_site_dir().replace("\\", "/") site_dir = "%s/sites" % site_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) for site in sites: my.register_project(site, config) # set up the images directory for subdir in ['images', 'doc']: config["/tactic/%s/%s/" % (site,subdir)] = { 'static_filter.on': True, 'static_filter.dir': '%s/sites/%s/context/%s/' % \ (site_dir,site, subdir) } return config
def start(cls): print "Running Watch Folder ..." # Check whether the user define the drop folder path. # Default dop folder path: /tmp/drop parser = OptionParser() parser.add_option("-p", "--project", dest="project", help="Define the project_name.") parser.add_option("-d", "--drop_path", dest="drop_path", help="Define drop folder path") parser.add_option("-s", "--search_type", dest="search_type", help="Define search_type.") parser.add_option("-P", "--process", dest="process", help="Define process.") parser.add_option("-S", "--script_path", dest="script_path", help="Define script_path.") parser.add_option( "-w", "--watch_folder_code", dest="watch_folder_code", help= "Define watch folder code. If no code is used, then it assumed that this process \ is managed in a standalone script.") parser.add_option("-x", "--site", dest="site", help="Define site.") parser.add_option("-c", "--handler", dest="handler", help="Define Custom Handler Class.") (options, args) = parser.parse_args() if options.project != None: project_code = options.project else: raise Exception("No project specified") if options.drop_path != None: drop_path = options.drop_path else: tmp_dir = Environment.get_tmp_dir() drop_path = "%s/drop" % tmp_dir print " using [%s]" % drop_path if not os.path.exists(drop_path): os.makedirs(drop_path) if options.search_type != None: search_type = options.search_type else: search_type = None if options.process != None: process = options.process else: process = 'publish' if options.script_path != None: script_path = options.script_path else: script_path = None if options.site != None: site = options.site else: site = None if options.handler != None: handler = options.handler else: handler = None if options.watch_folder_code != None: watch_folder_code = options.watch_folder_code else: watch_folder_code = None if watch_folder_code: # record pid in watch folder pid file pid = os.getpid() pid_file = "%s/log/watch_folder.%s" % (Environment.get_tmp_dir(), watch_folder_code) f = open(pid_file, "w") f.write(str(pid)) f.close() Batch(project_code=project_code, site=site) task = WatchDropFolderTask(base_dir=drop_path, site=site, project_code=project_code, search_type=search_type, process=process, script_path=script_path, handler=handler, watch_folder_code=watch_folder_code) scheduler = Scheduler.get() scheduler.add_single_task(task, delay=1) scheduler.start_thread() return scheduler
def handle_file_mode(self, base_dir, transaction_code, paths, log, transaction_xml, ticket): # drop the transaction into a folder timestamp = log.get_value("timestamp") timestamp = parser.parse(timestamp) timestamp = timestamp.strftime("%Y%m%d_%H%M%S") asset_dir = Environment.get_asset_dir() # create the transactions dir if it does not exist if not os.path.exists("%s/transactions" % base_dir): os.makedirs("%s/transactions" % base_dir) base_dir = "%s/transactions/%s" % (base_dir, transaction_code) is_encrypted = True if is_encrypted == True: # put the transaction in a temp folder tmp_dir = Environment.get_tmp_dir(include_ticket=True) tmp_dir = "%s/%s-%s" % (tmp_dir, transaction_code, timestamp) else: tmp_dir = "%s/%s" % (base_dir, timestamp) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) from pyasm.common import EncryptUtil encrypt = EncryptUtil(ticket) # create a simple manifest file f = open("%s/manifest.xml" % tmp_dir, 'wb') f.write('''<manifest code='transaction_log' version='1'>\n''') f.write(''' <sobject search_type="sthpw/transaction_log"/>\n''') f.write('''</manifest>\n''') f.close() tpath = "%s/sthpw_transaction_log.spt" % tmp_dir from pyasm.search import TableDataDumper dumper = TableDataDumper() dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#") dumper.set_include_id(False) dumper.set_sobjects([log]) dumper.dump_tactic_inserts(tpath, mode='sobject') tpath = "%s/_transaction.xml" % tmp_dir #f = open(tpath, 'wb') f = codecs.getwriter('utf8')(open(tpath, 'wb')) f.write(transaction_xml.to_string()) f.close() # copy the checked in files for path in paths: rel_path = path.replace(asset_dir, "") rel_path = rel_path.lstrip("/") to_path = "%s/%s" % (tmp_dir, rel_path) to_dir = os.path.dirname(to_path) if not os.path.exists(to_dir): os.makedirs(to_dir) shutil.copy(path, to_dir) # zip up and encrypt the transaction if is_encrypted: zip_path = "%s.zip" % (tmp_dir) from pyasm.common import ZipUtil zip = ZipUtil() zip.zip_dir("%s" % (tmp_dir), zip_path) encrypt.encrypt_file(zip_path) shutil.move("%s.enc" % zip_path, "%s-%s.zip.enc" % (base_dir, timestamp)) rmdir = os.path.dirname(tmp_dir) shutil.rmtree(rmdir) #os.unlink("%s.zip" % tmp_dir) job = self.kwargs.get("job") job.set_value("error_log", "") job.commit() return
def remove_monitor_pid(self): '''remove the stop.monitor file''' log_dir = "%s/log" % Environment.get_tmp_dir() if os.path.exists("%s/stop.monitor" % log_dir): os.unlink("%s/stop.monitor" % log_dir)
def copy_start(my): #import pdb; pdb.set_trace() data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) #import pdb; pdb.set_trace() # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir,filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True #import pdb; pdb.set_trace() asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config_path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def copy_start(self): data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) # create the dist folder to_dir = "%s/dist" % (data_dir) if not os.path.exists(to_dir): os.makedirs(to_dir) # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir, filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True # insert the plugin path to run get_asset_dir() plugin_dir = Environment.get_plugin_dir() sys.path.insert(0, plugin_dir) asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return