<commit_before># -*- coding: utf-8 -*-

# Copyright (c) 2009, 2010, 2011 <NAME>.
# See LICENSE.txt for details.

from __future__ import print_function, unicode_literals
import pycoreutils
import ctypes
import sys


@pycoreutils.onlyunix
def parseargs(p):
    '''
    Add arguments and `func` to `p`.

    :param p: ArgumentParser
    :return:  ArgumentParser
    '''
    available_filesystems = get_available_filesystems()
    available_filesystems.sort()

    p.set_defaults(func=func)
    p.description = "Mount a filesystem"
    p.add_argument('SOURCE', nargs='?')
    p.add_argument('DEST', nargs='?')
    p.add_argument("-a", "--all", action="store_true",
            help="ignore, for compatibility with other versions")
    #p.add_argument("-o", "--options", default=0,
            #help="print only the effective group ID")
    p.add_argument("-t", "--types", default="ext2",
            help="Filesystem type. Supported types: " +\
                 ", ".join(available_filesystems))
    return p


def func(args):
    if args.SOURCE and args.DEST:
        _mount(args.SOURCE, args.DEST, args.types)
    elif args.SOURCE:
        try:
            with open('/etc/fstab') as fd:
                lines = fd.readlines()
        except IOError:
            print("Error: Couldn't read /etc/ftab", file=sys.stderr)
            return
        for line in lines:
            source, dest, fstype, options, freq, passno = line.split()
            if source == args.SOURCE:
                return _mount(source, dest, fstype)
            elif dest == args.SOURCE:
                return _mount(source, dest, fstype)
        print(args.SOURCE + " not found in /etc/fstab", file=sys.stderr)
    else:
        try:
            print(open('/etc/mtab').read().strip())
        except IOError:
            print("Error: Couldn't read /etc/mtab", file=sys.stderr)


def _mount(source, dest, fstype, options=0, data=''):
    libc = ctypes.CDLL(ctypes.util.find_library('c'))
    res = libc.mount(str(source), str(dest), str(fstype), options, str(data))
    if res < 0:
        print("Error: Mounting {0} on {1} failed!".format(source, dest),
              file=sys.stderr)

<commit_msg>Updated mount<commit_after># -*- coding: utf-8 -*-

# Copyright (c) 2009, 2010, 2011 <NAME>.
# See LICENSE.txt for details.

from __future__ import print_function, unicode_literals
import pycoreutils
import ctypes
import ctypes.util
import sys

# TODO: mount options


@pycoreutils.onlyunix
def parseargs(p):
    '''
    Add arguments and `func` to `p`.

    :param p: ArgumentParser
    :return:  ArgumentParser
    '''
    available_filesystems = get_available_filesystems()
    available_filesystems.sort()

    p.set_defaults(func=func)
    p.description = "Mount a filesystem"
    p.add_argument('SOURCE', nargs='?')
    p.add_argument('DEST', nargs='?')
    p.add_argument("-a", "--all", action="store_true",
            help="Mount all filesystems mentioned in fstab")
    #p.add_argument("-o", "--options", default=0,
            #help="print only the effective group ID")
    p.add_argument("-t", "--types", default="ext2",
            help="Filesystem type. Supported types: " +\
                 ", ".join(available_filesystems))
    p.add_argument("-v", "--verbose", action="store_true",
            help="Output debugging information")
    return p


def func(args):
    if args.SOURCE and args.DEST:
        mount_c(args.SOURCE, args.DEST, args.types, args.verbose)
    elif args.SOURCE or args.all:
        # Read fstab
        try:
            with open('/etc/fstab') as fd:
                lines = fd.readlines()
        except IOError:
            print("Error: Couldn't read /etc/ftab", file=sys.stderr)
            return

        # Mount filesystem
        mounted_something = False
        for line in lines:
            line = line.partition('#')[0]  # Remove comments
            source, dest, fstype, options, freq, passno = line.split()
            if source == args.SOURCE or dest == args.SOURCE or args.all:
                mount_c(dest, dest, fstype, args.verbose)
                mounted_something = True
        if not mounted_something:
            print(args.SOURCE + " not found in /etc/fstab", file=sys.stderr)
    else:
        # Display currently mounted filesystems
        try:
            print(open('/etc/mtab').read().strip())
        except IOError:
            print("Error: Couldn't read /etc/mtab", file=sys.stderr)


def mount_c(source, dest, fstype, options=0, data='', verbose=False):
    '''
    Frontend to libc mount
    '''
    if verbose:
        print("Trying to mount {0} on {1} as type {2}".format(source, dest,
                                                                       fstype))
    libc = ctypes.CDLL(ctypes.util.find_library('c'))
    res = libc.mount(str(source), str(dest), str(fstype), options, str(data))
    if res < 0:
        print("Error: Mounting {0} on {1} failed!".format(source, dest),
              file=sys.stderr)


{'fraction_non_alphanumeric': 0.13536854790118497, 'fraction_numerical': 0.008435428800964049, 'mean_word_length': 2.3739837398373984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1534757', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1492, 'n_words': 390}