Пример #1
0
def command_C(commands):
    """
    Functionalities within command C,
    will read the input and create a new file.
    :param commands: the input command
    :return: None
    """

    if len(commands) != 4:
        print_warning('There needs to be exactly 3 inputs for COMMAND C')
    else:

        p = commands[1] + '\\'
        name = commands[3]
        extention = '.dsu'
        path = p + name + extention

        if test_mode:
            print_error("[Test mode]COMMAND C's path: " + path)

        if commands[2] == '-n':
            try:
                path = Path(path)
                # create the dsu file
                path.touch()
                # for Profile creation (after the dsu file is created)
                create_profile(str(path))
            except FileNotFoundError:
                print_warning('This is a invalid directory')
        else:
            print_warning("This option is invalid for COMMAND C")
Пример #2
0
def main_func():
    """
    The function wrapper.
    :return: None
    """
    in_commands = input()
    commands = input_analyzer(in_commands)
    commands[0] = commands[0].upper()

    # for test purpose

    if test_mode:
        print_error("[Test mode]The command list after process: " +
                    str(commands))
    if commands[0] == 'L':
        command_L(commands)
    elif commands[0] == 'C':
        command_C(commands)
    elif commands[0] == 'D':
        command_D(commands)
    elif commands[0] == 'R':
        command_R(commands)
    elif commands[0] == 'Q':
        command_Q()
    elif commands[0] == 'H':
        helper()
    elif commands[0] == 'M':
        modify_profile()
    else:
        print_warning("Incorrect COMMAND")
Пример #3
0
def main(args):
	gl_url = args.url
	if not (gl_url.startswith("http://") or gl_url.startswith("https://")):
		gl_url = "https://" + gl_url
	try:
		gl_soup = helper.get_soup(gl_url)
	except IndexError, e:
		helper.print_error(e, "please pass url as arg1")
Пример #4
0
def command_L(commands):
    """
    Functionalities within command L.
    List the contents of the user specified directory.
    :param commands: the input command
    :return: None
    """
    if len(commands) < 2:
        print_warning('There needs to be at least 1 input for COMMAND L')
    else:
        p = Path(commands[1])
        try:
            all_items, dirs, files = command_L_get_items(p)
        except WindowsError:
            print_error("ERROR")

        if len(commands) == 2:
            for i in files:
                print(i)
            for i in dirs:
                print(i)

        elif len(commands) == 3:
            # options -r -f

            if commands[2] == '-r':
                r = command_L_r(p, [])
                for i in r:
                    print(i)
            elif commands[2] == '-f':
                command_L_f(p)
            else:
                print_warning('Option here should be either -r or -f')

        elif len(commands) == 4:
            # options -s -e -r-f

            if commands[2] == '-s':
                command_L_s(p, commands[3])
            elif commands[2] == '-e':
                command_L_e(p, commands[3])
            elif commands[2] == '-r' and commands[3] == '-f':
                command_L_r_f(p)

        elif len(commands) == 5:
            # options -r-s -r-e
            if commands[2] == '-r' and commands[3] == '-s':

                command_L_r_s(p, commands[4])

            elif commands[2] == '-r' and commands[3] == '-e':

                command_L_r_e(p, commands[4])
Пример #5
0
def loadMEStable(ceid):
    try:
        df = pd.read_csv(sub_ceid + '_MESTABLE.csv')
        df['open'], df['close_comment'] = 'Up&Open', ''
        col2str = [
            'operation', 'oper_process', 'product', 'route', 'main_moqr'
        ]
        df[col2str] = df[col2str].astype('str')
        df.update(df.select_dtypes(include=[np.number]).fillna(0))
        return df.fillna('.'), len(df)
    except OSError as err:
        print_error(err)
        return [], 0
Пример #6
0
def send(np: NaClProfile,
         send_type,
         server: str,
         port: int,
         username: str,
         password: str,
         message: list,
         bio: str = None):
    '''
    The send function joins a ds server and sends a message, bio, or both
    :param np: it is the NaClProfile object passed in from the main program
    :param send_type: the sending type of this send (post / bio / post and bio)
    :param server: The ip address for the ICS_32 DS server.
    :param port: The port where the ICS_32 DS server is accepting connections.
    :param username: The user name to be assigned to the message.
    :param password: The password associated with the username.
    :param message: The list of posts to be sent to the server.
    :param bio: Optional, a bio for the user.
    '''
    global token
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((str(server), port))
    except socket.gaierror:
        print_warning('The address or port seems incorrect')
    else:
        done = "Upload done."

        send_types = ['p', 'b', 'pb']
        # make sure the send type is a valid one
        if send_type in send_types:
            # join the server
            join(sock, username, password, np.public_key)
            # if connected successfully, the token will be given a value
            # otherwise it's an empty string.
            if token != '':

                if send_type == 'p':
                    post(sock, message, np)
                    print_ok(done)
                elif send_type == 'b':
                    _bio(sock, bio, np)
                    print_ok(done)
                elif send_type == 'pb':
                    post(sock, message, np)
                    _bio(sock, bio, np)
                    print_ok(done)
        else:
            print_error("Please provide a valid send type.\n" "Upload failed.")
Пример #7
0
    def task_add(self, task: str, priority: int, description: str) -> None:
        """
        Add a task
        :param task: Task Name
        :param priority: Priority of the task. Starting with 1 as highest priority
        :param description: Task description
        :return: None
        """
        if len(task) == 0:
            return print_error("No Task")
        if not -1 < priority < 4:
            return print_error("Selected priority dont exist")

        task = self.taskModel.task_add(task, priority, description)
        self.event_task_add.fire(self.taskModel.tasks)
Пример #8
0
def generateData(lammps_file, seed, data_file, runner_folder):
    """
    Given a lammps_file, seed, and a place to write this information to runner
    Generates the data from the lammps file
    """
    lammps_filename = lammps_file[(
        max(lammps_file.rfind("/"), lammps_file.rfind("\\")) + 1):]
    lammps_dir = lammps_file[:(len(lammps_file) - len(lammps_filename))]
    os.chdir(lammps_dir)
    with open("runCommand.bash", "w") as f:
        f.write("lammps -echo screen -var seed " + str(seed) + " < " +
                lammps_filename)
    call(["bash", "runCommand.bash"])
    for i in range(max(lammps_dir.count("/"), lammps_dir.count("\\"))):
        os.chdir("..")
    call([
        "mv", lammps_dir + "runCommand.bash", runner_folder + "runCommand.bash"
    ])
    lammpstrj = ""
    log = lammps_dir + "log.lammps"
    # Copy lammps file to the runner folder
    with open(lammps_file, "r") as fi:
        with open(runner_folder + lammps_filename, "w") as fo:
            for line in fi:
                if line.strip().startswith("pair_style"):
                    fo.write(
                        "variable\tout equal 100\t# frequency of writing thermo quantities to output file\n"
                    )
                    fo.write(
                        "pair_style\trunner showew no showewsum ${out} maxew 10000 resetew yes dir .\n"
                    )
                    line = "#" + line
                if line.strip().startswith("pair_coeff"):
                    fo.write("pair_coeff\t* * 6.350126988  #12 angstrum\n")
                    line = "#" + line
                elif line.strip().startswith("dump"):
                    lammpstrj = lammps_dir + line[:line.find(
                        ".lammpstrj")].split()[-1] + ".lammpstrj"
                elif line.strip().startswith("log"):
                    log = lammps_dir + line.split()[-1]
                fo.write(line)
    if not lammpstrj:
        helper.print_error(
            "ERROR: lammpstrj file not written using dump, cannot proceed")
        exit()
    print("converting to data!")
    print data_file, log, lammpstrj
    lammpstrj_to_data(data_file, log, lammpstrj)
Пример #9
0
def extract_json(json_msg: str) -> DataTuple:
    '''
    Call the json.loads function on a json string and convert it to a DataTuple object
    '''
    try:
        type_list = ['error', 'ok']

        json_obj = json.loads(json_msg)

        # make sure the type is either ok or error
        if json_obj['response']['type'] not in type_list:
            raise ValueError('Type is not ok or error.')

        type_ = json_obj['response']['type']
        message = json_obj['response']['message']

        # when token is present for ok response
        if 'token' in json_obj['response']:
            token = json_obj['response']['token']
        # when token is not present for error response
        else:
            token = ''

    except json.JSONDecodeError:
        print_error("Json cannot be decoded.")
    except KeyError:
        print_error("Non-standard response received.")
    except ValueError as e:
        print_error(e)
    else:
        return DataTuple(type_, message, token)
Пример #10
0
def generateData(lammps_file, seed, data_file, runner_folder):
    """
    Given a lammps_file, seed, and a place to write this information to runner
    Generates the data from the lammps file
    """
    lammps_filename = lammps_file[(max(lammps_file.rfind("/"), lammps_file.rfind("\\")) + 1):]
    lammps_dir = lammps_file[:(len(lammps_file)-len(lammps_filename))]
    os.chdir(lammps_dir)
    with open("runCommand.bash", "w") as f:
        f.write("lammps -echo screen -var seed " + str(seed) + " < " + lammps_filename)
    call(["bash", "runCommand.bash"])
    for i in range(max(lammps_dir.count("/"), lammps_dir.count("\\"))):
        os.chdir("..")
    call(["mv", lammps_dir + "runCommand.bash", runner_folder + "runCommand.bash"])
    lammpstrj = ""
    log = lammps_dir + "log.lammps"
    # Copy lammps file to the runner folder
    with open(lammps_file, "r") as fi:
        with open(runner_folder + lammps_filename, "w") as fo:
            for line in fi:
                if line.strip().startswith("pair_style"):
                    fo.write("variable\tout equal 100\t# frequency of writing thermo quantities to output file\n")
                    fo.write("pair_style\trunner showew no showewsum ${out} maxew 10000 resetew yes dir .\n")
                    line = "#" + line
                if line.strip().startswith("pair_coeff"):
                    fo.write("pair_coeff\t* * 6.350126988  #12 angstrum\n")
                    line = "#" + line
                elif line.strip().startswith("dump"):
                    lammpstrj = lammps_dir + line[:line.find(".lammpstrj")].split()[-1] + ".lammpstrj"
                elif line.strip().startswith("log"):
                    log = lammps_dir + line.split()[-1]
                fo.write(line)
    if not lammpstrj:
        helper.print_error("ERROR: lammpstrj file not written using dump, cannot proceed")
        exit()
    print("converting to data!")
    print data_file, log, lammpstrj
    lammpstrj_to_data(data_file, log, lammpstrj)
Пример #11
0
def response(sock: socket) -> DataTuple:
    """
    Respond to the user about detailed message retrieved from
    the server response JSON

    Sample server JSON response:

    {"response": {"type": "ok", "message": "Welcome back, ffyuanda",
    "token": "551db8b5-7adb-4f9c-b610-a8aecd5793b0"}}

    {"response": {"type": "error",
    "message": "Post rejected: invalid timestamp"}}

    :param sock: current connecting socket
    :return: a DataTuple that contains the info from the server
    response JSON.
    """
    recv = sock.makefile('r')
    resp = recv.readline()

    # resolve the conflict of two modules importing each other
    from ds_client import test_mode

    if test_mode:
        print_error('[Test mode]resp\'s value: ' + resp)
    # DataTuple conversion
    resp = extract_json(resp)
    if resp.type == 'ok':

        if resp.message.startswith('Welcome back'):
            print_ok("Successfully logged in.")
            print_ok('Server says: {}\n'.format(resp.message))

        elif resp.message.startswith('Welcome to'):
            print_ok("Successfully registered in.")
            print_ok('Server says: {}\n'.format(resp.message))

        elif 'Bio' in resp.message:
            print_ok("Bio successfully updated.")
            print_ok('Server says: {}\n'.format(resp.message))

        elif 'Post' in resp.message:
            print_ok("Post successfully sent.")
            print_ok('Server says: {}\n'.format(resp.message))

    elif resp.type == 'error':
        print_error("An error occurs.")
        print_error('Error message: {}\n'.format(resp.message))

    return resp
Пример #12
0
def lexic_process(char):
    global currPos
    global currLine
    global state
    global prev_status

    acii = take_acii_code(char)

    if state == 'WS' and acii not in dictionary['spaces']:
        state = 'S'
    elif state == 'ERROR' and (acii in dictionary['spaces'] or char
                               in dictionary['delimeters'] or not char):
        state = 'S'

    elif state == 'IDN':
        result = process_idn(char)
        if result == False:
            location = {'line': currLine, 'pos': currPos}
            print_error('incorrect defining identifier: ', char, location)
            state = 'ERROR'
        elif result != None:
            token_process(result, 'IDN')
            state = 'S'

    elif state == 'NUM':
        result = process_num(char)
        if result == False:
            location = {'line': currLine, 'pos': currPos}
            print_error('incorrect defining number', char, location)
            state = 'ERROR'
        elif result != None:
            token_process(result, 'NUM')
            state = 'S'

    elif state == 'BCOM':
        if char != '*':
            location = {'line': currLine, 'pos': currPos}
            print_error('Expected * instead of', char, location)
            state = 'S'
        else:
            state = 'COM'

    elif state == 'COM':
        if char == '*':
            state = 'ECOM'
        elif not char:
            location = {'line': currLine, 'pos': currPos}
            print_error('Unexpected end of file', char, location)

    elif state == 'ECOM':
        if not char:
            location = {'line': currLine, 'pos': currPos}
            print_error('Unexpected end of file', char, location)
        elif char == ')':
            prev_status = 'ECOM'
            state = 'S'
            currPos += 1
            return None
        elif char == '*':
            state = 'ECOM'
        else:
            state = 'COM'

    if state == 'S':
        if not char:
            return {
                'idns': idns,
                'consts': consts,
                'delimeters': delimeters,
                'tokens': tokens
            }

        elif char.isalpha():
            state = 'IDN'
            process_idn(char)

        elif char.isdigit():
            state = 'NUM'
            process_num(char)

        elif char == '(':
            state = 'BCOM'

        elif char == '*' and prev_status == 'ECOM':
            state = 'ECOM'

        elif acii in dictionary['spaces']:
            state = 'WS'

        elif char in dictionary['delimeters']:
            token_process(char, 'DELIMETERS')

        else:
            location = {'line': currLine, 'pos': currPos}
            print_error('unknown symbol', char, location)

    if acii == 10 or acii == 13:
        currPos = 0
        currLine += 1

    currPos += 1
    return None
Пример #13
0
    df_out.columns = ["".join(x) for x in df_out.columns.ravel()]
    df_out.fillna(0, inplace=True)
    return df_out if df_summ.empty else pd.concat([df_summ, df_out])


# ###############################################################
os.chdir(workdir)
amct_dic = amct2moduleDic()
ceid_needed_fix, ceid_legend = loadSubCeidLegend()
df_summ = pd.DataFrame()

for sub_ceid, amct in amct_dic.items():

    mes_table, mes_size = loadMEStable(sub_ceid)
    if mes_size == 0:
        print_error(sub_ceid + ': mes_table Missing!')
        continue

    if sub_ceid in ceid_needed_fix:
        mes_table['ceid'] = mes_table.apply(fix_ceid,
                                            axis=1,
                                            args=(ceid_legend, ))

    mes_table.apply(mes_state, axis=1)

    tables, tables_size = loadAMCTtables(amct)
    drop_rows = []
    for idx, mes_row in mes_table.iterrows():

        restricted, comment = restrictMoq(mes_row)
        if restricted:
Пример #14
0
def helper():
    print(
        "\nThis color represents an input prompt or normal system information."
    )
    print_ok("This color represents successful or approved operations.")
    print_warning(
        "This color represents user's illegal inputs or unexpected operations."
    )
    print_error("This color represents systematic error or test mode message "
                "that should be handled by developers.\n")

    print("""Usage format: [COMMAND] [INPUT] [[-]OPTION] [INPUT]
    
    Some tips:
    If you want to CREATE a file, go to COMMAND: C
    If you want to MODIFY a file, go to COMMAND: M
    If you want to UPLOAD a file, go to COMMAND: R
    
    COMMAND: L - List the contents of the user specified directory.

                OPTIONs:
                -r Output directory content recursively.
                -f Output only files, excluding directories in the results.
                -s Output only files that match a given file name.
                -e Output only files that match a give file extension.

                Example usage:
                L c:\\users\\mark\\a1
                L c:\\users\\mark\\a1 -r
                L c:\\users\\mark\\a1 -f
                L c:\\users\\mark\\a1 -r -s readme.txt
                L c:\\users\\mark\\a1 -s readme.txt
                L c:\\users\\mark\\a1 -r -e jpg

    COMMAND: Q - Quit the program.

                Example usage:
                Simply press Q.

    COMMAND: C - Create a new file in the specified directory.
                 And you need to enter DSU server, username, and
                 password by the following prompt.

                 After the creation of DSU file and profile, the
                 program will ask you if you want to upload things
                 to the DSU server.

                OPTIONs:
                -n Specify the name to be used for a new file.

                Example usage:
                C c:\\users\\mark\\a1 -n mark

    COMMAND: M - Modify a saved DSU file and the profile relates to it.
                 After the command is typed in, the system will load up
                 a DSU file to a Profile object to modify the data.
                 It will prompt you how to modify and save the data.

                Example usage:
                M (just put in 'M' and wait for the prompt)

    COMMAND: D - Delete the file.

                Example usage:
                D c:\\users\\mark\\a1\\mark.dsu

    COMMAND: R - Read the contents of a file and upload it to the server.


                OPTIONs:
                -l load the specified file from the path, If you want to 
                upload a file directly, use this.

                After the loading of DSU file and profile, the
                program will ask you if you want to upload things
                to the DSU server.

                Example usage:
                R c:\\users\\mark\\a1\\mark.dsu
                R c:\\users\\mark\\a1\\mark.dsu -l
                
    API Supports:
    
                When you are writing posts, you have some API add-ins support
                available for better writing! All the keywords will be transcluded
                before the DSU file is saved. You will see "Transcluding..." when
                the file is being transcluded.
                
                OpenWeather API:
                You can simply add '@weather' in your post at anywhere, and the
                '@weather' script will translate to the current weather in Irvine.
                Supports for your current location will be added later.
                               
                LastFM API:
                You can simply add '@lastfm' in your post at anywhere, and the
                '@lastfm' script will translate to the United Stats' top hit 
                song on LastFM in current time period.
                Supports for other countries will be added later.
                
                Joke API:
                You can simply add '@extracredit' in your post at anywhere, and the
                '@extracredit' script will translate to a random joke.
                
                !CAUTION!: this api may not be accessible in some regions since
                the IP address of the api's server is blocked in some area, if
                you encounter a trancluding problem or connection issue, please
                connect to UCI's VPN when you are using this feature. 
              """)
Пример #15
0
def input_analyzer(in_commands):
    """
    Analyze the input string and turn it into
    readable list format.
    :param in_commands: the user input string
    :return: a list that contains the processed user input (commands)
    """
    out_commands = []
    command_list = ['L', 'Q', 'C', 'D', 'R', 'M']
    option_list = ['-s', '-r', '-f', '-e', '-n', '-l']
    built_ins = command_list + option_list
    real_path = ''

    # raw split by space
    commands = [x for x in in_commands.split(' ')]
    length = len(commands)

    # try to find out the real path that may contain whitespace, which
    # 1. has to not in the built_ins keywords
    # 2. its left and right elements are not both built-ins keywords
    for i in range(length):
        # does not check first and last element
        if test_mode:
            print_error("[Test mode]real_path in input_analyzer:" + real_path)

        if 0 < i < length - 1:

            if commands[i] not in built_ins:

                # i is not the last digit
                if i < length - 1:
                    # this is a path with whitespaces
                    if (commands[i + 1] not in built_ins) \
                            or (commands[i - 1] not in built_ins):
                        real_path += commands[i] + ' '
                    # this is a path without whitespaces
                    else:
                        real_path = commands[i]

                # i is the last digit
                else:

                    # this is a path with whitespaces
                    if commands[i - 1] not in built_ins:
                        real_path += commands[i] + ' '

                    # there are only two elements, and command[i] is a
                    # valid path without whitespace
                    elif commands[i - 1] in command_list:
                        real_path = commands[i]

                    # the last element (extension/filename etc.)
                    else:
                        out_commands.append(commands[i])
            else:
                # built-ins keywords
                out_commands.append(commands[i])
        else:
            # first and last element
            out_commands.append(commands[i])

    # remove trailing whitespaces
    if len(real_path) > 0:
        real_path = real_path.strip()
        out_commands.insert(1, real_path)
    return out_commands
Пример #16
0
ignored_modules_list = list()
ext_map = {}

print(chr(27) + "[2J")

print("-------------------------------------------------------")
print("Android Project Combine v" + __version__)
print("-------------------------------------------------------")

# combine_name = raw_input("Please input the name of the combine poject: ")
# if combine_name is None or combine_name.strip() == '':
#     combine_name = DEFAULT_COMBINE_NAME

if exists(combine_project_path):
    print_error(
        "Fatal error: there is the same project with the " + combine_name + " on combine project folder: " +
        combine_project_path)
    exit("Goodbye!")

if argv.__len__() > 1 and argv[1] is not None:
    conf_file_path = argv[1]
else:
    conf_file_path = repos_conf_path

tmp_repo_addr_list = list()
repo_path_list = list()
dep_version_map = {}

# addr/path: [module]
tmp_ignore_modules_map = {}
process_dep_version_conf('dependencies-version.conf', dep_version_map)
Пример #17
0
		sys.stdout.write ("\t\t\t\t\t\t\t\r")
	return iterator

def main(args):
	gl_url = args.url
	if not (gl_url.startswith("http://") or gl_url.startswith("https://")):
		gl_url = "https://" + gl_url
	try:
		gl_soup = helper.get_soup(gl_url)
	except IndexError, e:
		helper.print_error(e, "please pass url as arg1")
	except URLError, e:
		try:
			gl_soup = helper.get_soup_alternate(gl_url)
		except:
			helper.print_error(e, "bad url")

	gl_articletitle = get_articletitle(args, gl_soup)
	[s.extract() for s in gl_soup(EXTRACT_HTML_TAGS)]

	table_parent_wordcount = {}
	table_text = {}
	treerecurse(gl_soup, None, table_parent_wordcount, table_text)

	designated_node_parent = max(table_parent_wordcount, key=lambda k: (table_parent_wordcount[k], len(k)))
	gl_array_article_text = table_text[designated_node_parent]


	gl_table_word_frequency = summrio.get_word_frequency(gl_array_article_text, gl_articletitle)

	if args.tscore: