# -*- coding: utf-8 -*-
#
# Forked from Pardus by TUBITAK/UEKAE
# Copyright (C) 2012-2015, PisiLinux
# 2015 - Ayhan Yalçınsoy
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

"""Basic shell utilities working on files and directories."""

import os
import shutil


###############################
# Directory related functions #
###############################

def remove_dir(path):
    """Remove all content of a directory."""
    if os.path.exists(path):
        shutil.rmtree(path)


def dir_size(dir):
    """Calculate the size of files under a directory."""
    from os.path import getsize, islink, isdir, exists, join

    if exists(dir) and (not isdir(dir) and not islink(dir)):
        #so, this is not a directory but file..
        return getsize(dir)

    if islink(dir):
        return int(len(os.readlink(dir)))

    def sizes():
        for root, dirs, files in os.walk(dir):
            yield sum([getsize(join(root, name)) for name in files if not islink(join(root,name))])
            yield sum([int(len(os.readlink((join(root, name))))) for name in files if islink(join(root,name))])
    return sum( sizes() )



#########################
# File related funtions #
#########################

def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, "w").close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True



adca7fa99a1a206e3f6369ee21bf8889c0022b09
<mask token>


def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, 'w').close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True

<mask token>


def dir_size(dir):
    """Calculate the size of files under a directory."""
    from os.path import getsize, islink, isdir, exists, join
    if exists(dir) and (not isdir(dir) and not islink(dir)):
        return getsize(dir)
    if islink(dir):
        return int(len(os.readlink(dir)))

    def sizes():
        for root, dirs, files in os.walk(dir):
            yield sum([getsize(join(root, name)) for name in files if not
                islink(join(root, name))])
            yield sum([int(len(os.readlink(join(root, name)))) for name in
                files if islink(join(root, name))])
    return sum(sizes())


def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, 'w').close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True

<mask token>


def remove_dir(path):
    """Remove all content of a directory."""
    if os.path.exists(path):
        shutil.rmtree(path)


def dir_size(dir):
    """Calculate the size of files under a directory."""
    from os.path import getsize, islink, isdir, exists, join
    if exists(dir) and (not isdir(dir) and not islink(dir)):
        return getsize(dir)
    if islink(dir):
        return int(len(os.readlink(dir)))

    def sizes():
        for root, dirs, files in os.walk(dir):
            yield sum([getsize(join(root, name)) for name in files if not
                islink(join(root, name))])
            yield sum([int(len(os.readlink(join(root, name)))) for name in
                files if islink(join(root, name))])
    return sum(sizes())


def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, 'w').close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True

<mask token>
import os
import shutil


def remove_dir(path):
    """Remove all content of a directory."""
    if os.path.exists(path):
        shutil.rmtree(path)


def dir_size(dir):
    """Calculate the size of files under a directory."""
    from os.path import getsize, islink, isdir, exists, join
    if exists(dir) and (not isdir(dir) and not islink(dir)):
        return getsize(dir)
    if islink(dir):
        return int(len(os.readlink(dir)))

    def sizes():
        for root, dirs, files in os.walk(dir):
            yield sum([getsize(join(root, name)) for name in files if not
                islink(join(root, name))])
            yield sum([int(len(os.readlink(join(root, name)))) for name in
                files if islink(join(root, name))])
    return sum(sizes())


def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, 'w').close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True

# -*- coding: utf-8 -*-
#
# Forked from Pardus by TUBITAK/UEKAE
# Copyright (C) 2012-2015, PisiLinux
# 2015 - Ayhan Yalçınsoy
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

"""Basic shell utilities working on files and directories."""

import os
import shutil


###############################
# Directory related functions #
###############################

def remove_dir(path):
    """Remove all content of a directory."""
    if os.path.exists(path):
        shutil.rmtree(path)


def dir_size(dir):
    """Calculate the size of files under a directory."""
    from os.path import getsize, islink, isdir, exists, join

    if exists(dir) and (not isdir(dir) and not islink(dir)):
        #so, this is not a directory but file..
        return getsize(dir)

    if islink(dir):
        return int(len(os.readlink(dir)))

    def sizes():
        for root, dirs, files in os.walk(dir):
            yield sum([getsize(join(root, name)) for name in files if not islink(join(root,name))])
            yield sum([int(len(os.readlink((join(root, name))))) for name in files if islink(join(root,name))])
    return sum( sizes() )



#########################
# File related funtions #
#########################

def touch(filename):
    """Update file modification date, create file if necessary"""
    try:
        if os.path.exists(filename):
            os.utime(filename, None)
        else:
            open(filename, "w").close()
    except IOError as e:
        if e.errno != 13:
            raise
        else:
            return False
    except OSError as e:
        if e.errno != 13:
            raise
        else:
            return False
    return True


