def do_show(self, arguments): server = arguments.server target = arguments.target ext = arguments.external db_path = os.path.join(get_project_path(), Seekplum_DB_FILE) if not os.path.exists(db_path): return if server: ServerConfig.show()
import numpy as np import os from sklearn.model_selection import train_test_split # 添加路径读utils文件夹中的util文件 import sys print(sys.path) sys.path.append("/home/apollo/craft/Projects/Holy-Miner") print(sys.path) from utils.util import get_project_path max_features = 20000 max_length = 200 # cut texts after this number of words (among top max_features most common words) batch_size = 1024 root_path = get_project_path() print(root_path) def read_data_from_folder(folder_path): """ read data from neg and pos folder """ files = os.listdir(folder_path) all_line = [] for file in files: if not os.path.isdir(file): with open(folder_path + '/' + file) as f: for line in f: all_line.append(line) return all_line
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from sqlalchemy import create_engine from sqlalchemy import inspect from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import MetaData from sqlalchemy.orm import sessionmaker, scoped_session from contextlib import contextmanager from conf import Seekplum_DB_FILE_LOCAL from utils.util import get_project_path dbfile = os.path.join(get_project_path(), Seekplum_DB_FILE_LOCAL) engine = create_engine("sqlite:///{}".format(dbfile)) Session = scoped_session( sessionmaker(bind=engine, autocommit=False, autoflush=False)) # make sure the session id is unique metadata = MetaData(bind=engine) session = Session() @contextmanager def open_session(): global session try: session.close() session = Session() yield session session.commit()
def main(self): introduction = "{term}(version {version})\nType \"help\", \"copyright\" for more information.\n{copyright}".format( term=TERM_NAME, version=VERSION, copyright=COPYRIGHT) argv = sys.argv length = len(argv) if length >= 2: subcommand = argv[1] subcommand_list = self.cs_map.keys() if subcommand in subcommand_list and length == 2: self.current_command = argv[1].strip() self.completer.update(self.current_command) self.at = "@" elif subcommand in subcommand_list and length > 2: self.run_command_in_one() return else: print_red("Unrecognized command '{}'".format(subcommand)) return print introduction # history = InMemoryHistory() project_path = get_project_path() history_file = os.path.join(project_path, TERM_HISTORY_FILE) history = FileHistory(history_file) while True: try: self.completer.update(self.current_command) if self.xterm: text = get_input( completer=self.completer, get_prompt_tokens=self.get_prompt_tokens, style=QSTYLE, history=history, enable_history_search=Always(), on_abort=AbortAction.RETRY, display_completions_in_columns=True, ) else: text = get_input( get_prompt_tokens=self.get_prompt_tokens, history=history, style=QSTYLE_NOCOLOR, enable_history_search=Always(), on_abort=AbortAction.RETRY, display_completions_in_columns=True, ) text = text.strip() if not text: continue # print help when type "help" or "?" or "h" if text in ["help", "?", "h"]: if not self.current_command: self.help() else: self.run_command(self.current_command, ["-h"]) # print "exit/quite" to exit the current command or exit elif text in ["exit", "quite"]: if self.current_command: self.current_command = "" self.at = "" continue else: break # print version elif text in ["version", "v"]: print "{}({})".format(TERM_NAME, VERSION) continue # copyright elif text == "copyright": print COPYRIGHT continue # run cmd elif text.startswith("!"): # ssh在本地执行命令 enter_shell(text[1:]) continue else: # get the command text_list = text.split() command = text_list[0] if len(text_list) == 1 and command in self.cs_map.keys(): self.current_command = command self.at = "@" continue # new subcommand elif command in self.cs_map.keys() and len(text_list) > 1: if text_list[-1] == "?": self.run_command(command, ["-h"]) elif text_list[-1] != "?": self.run_command(command, text_list[1:]) continue else: # use old subcommand if self.current_command: if text_list[-1] == "?": self.run_command(self.current_command, [command, "-h"]) else: self.run_command(self.current_command, text_list) # unknow subcommand else: print_red("Unrecognized command '{}'".format(text)) except SystemExit: continue except EOFError: break except KeyboardInterrupt: error_logger.exception("exception operation cancel") print_red("Operation cancelled!") except Exception as e: logging.error(e.message) print_red("Invalid Operation...") error_logger.exception("exception")
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import six from sqlalchemy import create_engine from sqlalchemy import inspect from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import MetaData from sqlalchemy.orm import sessionmaker, scoped_session from contextlib import contextmanager from utils.util import get_project_path dbfile = os.path.join(get_project_path(), "seekplum_local.db") engine = create_engine("sqlite:///{}".format(dbfile)) Session = scoped_session( sessionmaker(bind=engine, autocommit=False, autoflush=False)) # make sure the session id is unique metadata = MetaData(bind=engine) session = Session() @contextmanager def open_session(): global session try: session.close() session = Session() yield session