Пример #1
0
 def _arg_escape(arg):
     shell_chars = (' ', '"', "'", '(', ')', '`', '$', '!')
     if common.any_in_string(shell_chars, arg):
         # return "'{0}'".format(string_escape_char(arg, "'"))
         return "'{0}'".format(arg.replace("'", """'"'"'"""))
     else:
         return arg
Пример #2
0
 def _arg_escape(arg):
     shell_chars = (' ', '"', "'", '(', ')', '`', '$', '!')
     if common.any_in_string(shell_chars, arg):
         # return "'{0}'".format(string_escape_char(arg, "'"))
         return "'{0}'".format(arg.replace("'", """'"'"'"""))
     else:
         return arg
Пример #3
0
def escape_arguments_to_string(arguments):
    new_arguments = ""
    for argument in arguments:
        _pass = False
        # Test argument for an bash special characters
        print("Argument:", argument)
        if argument.startswith("'") and argument.endswith("'"):
            _pass = True
        elif common.any_in_string(['&', '(', ')', ';', '|', "\n", '<', '>', "'", '!', '*', '$', '[', ']', '`', '\\', ' ', '$'], argument):
            print("\tSpecial characters detected")
            new_argument = argument.replace("'", "\\'")
            new_arguments = "%s '%s'" % (new_arguments, new_argument)
        #elif common.any_in_string(["'", '*', '$', '`', '\\'], argument):
        #    new_argument = argument.replace("'", "'\\''")
        #    new_arguments = "%s '%s'" % (new_arguments, new_argument)
        #elif ' ' in argument:
        #    new_arguments = "%s '%s'" % (new_arguments, argument)
        else:
            print("\tNo special characters, passing through.")
            _pass = True

        if _pass:
            new_arguments = "%s %s" % (new_arguments, argument)
        #new_arguments = "%s %s" % (new_arguments, util.string_safe_shell(argument))
    return new_arguments[1:]
Пример #4
0
def get_file_type(file_path):
    """ Only recognises archive types for now """
    output = get_command_output(['file', '-b', '--mime', file_path])

    if len(output.strip()):
        #output = ':'.join(output.split(':')[1:]).strip()
        if output.startswith('application/x-gzip'):
            if common.any_in_string(('.tar.', '.tgz'), file_path.lower()):
                return 'tar.gz'
            else:
                return 'gz'
        elif output.startswith('application/x-bzip2'):
            if common.any_in_string(('.tar.', '.tgz'), file_path.lower()):
                return 'tar.bz2'
            else:
                return 'bz2'
        elif output.startswith('application/zip'):
            return 'zip'
        elif output.startswith('application/x-7z-compressed'):
            return '7zip'
        elif output.startswith('application/x-rar'):
            return 'rar'
    return output.split(';')[0]
Пример #5
0
def get_file_type(file_path):
    """ Only recognises archive types for now """
    output = get_command_output(['file', '-b', '--mime', file_path])

    if len(output.strip()):
        #output = ':'.join(output.split(':')[1:]).strip()
        if output.startswith('application/x-gzip'):
            if common.any_in_string(('.tar.', '.tgz'), file_path.lower()):
                return 'tar.gz'
            else:
                return 'gz'
        elif output.startswith('application/x-bzip2'):
            if common.any_in_string(('.tar.', '.tgz'), file_path.lower()):
                return 'tar.bz2'
            else:
                return 'bz2'
        elif output.startswith('application/zip'):
            return 'zip'
        elif output.startswith('application/x-7z-compressed'):
            return '7zip'
        elif output.startswith('application/x-rar'):
            return 'rar'
    return output.split(';')[0]