Browse Source

Better documentation and various fixes.

master
Bernd Zeimetz 9 years ago
parent
commit
5863d7011a
5 changed files with 28 additions and 14 deletions
  1. +17
    -3
      bin/diskquota
  2. +1
    -0
      setup.py
  3. +2
    -4
      src/diskquota/config.py
  4. +2
    -5
      src/diskquota/diskquota.cfg
  5. +6
    -2
      src/diskquota/manage.py

+ 17
- 3
bin/diskquota View File

@@ -42,11 +42,25 @@ if __name__ == '__main__':

usage = """
%s [-h|--help] show help
%s -p PATH [-u USER|-A] -q QUOTA -e UNTIL -r REASON write a quota override entry into the databse
%s -p PATH [-u USER|-A] -q QUOTA -e UNTIL -r REASON write a quota override entry into the database
%s -p PATH [-u USER|-A] -d remove quota override
%s -p PATH [-u USER|-A] -l list quota settings
%s -p PATH -x run Quota expiry job on PATH
""" %((prog, ) * 5)
%s -p PATH [-u USER|-A] -s (re)set quota for user
%s -p PATH -x run quota expiry job on PATH (you want to run this from cron)

%s needs to be configured in /etc/diskquota.cfg. The file is in
ini-style format with paths as sections and - for now -
one entry called "quota", which specifies the default quota
for the different groups. If a user is member of several groups,
the highest value will be applied.

For example:
[/foo/bar]
quota = students : 12233445, admins : 0, vips : 1000

[/fuzz/fuzzl/fuzzzz]
quota = users : 100, adm : 1400000000
""" %((prog, ) * 7)

epilog = """Disk quota management tool. Copyright (C) 2007-2010 Technische Universitaet Darmstadt, Fachbereich Architektur. Author: Bernd Zeimetz <bernd@bzed.de>. 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."""



+ 1
- 0
setup.py View File

@@ -54,4 +54,5 @@ setup(name="diskquota",
packages = ['diskquota'],
scripts=['bin/diskquota'],
long_description = __long_desc__,
data_files=[('/etc', [ 'src/diskquota/diskquota.cfg'])]
)

+ 2
- 4
src/diskquota/config.py View File

@@ -97,13 +97,11 @@ config = ConfigParser.ConfigParser()
config.read([os.path.join(os.path.realpath(os.path.dirname(__file__)), 'diskquota.cfg'), '/etc/diskquota.cfg'])

def get_quota_settings(path):
""" Return a dict with the quota settings for path.
If path was not specified, return the default settings. """
""" Return a dict with the quota settings for path."""
if config.has_section(path):
return GroupQuotaDict(config.get(path, 'quota'))
else:
return GroupQuotaDict(config.defaults()['quota'])

raise ValueError, "no configuration for %s available" %(path,)

def get_paths():
return config.sections()

+ 2
- 5
src/diskquota/diskquota.cfg View File

@@ -1,5 +1,2 @@
[DEFAULT]
quota = bzed : 12343423

[/mnt/foo]
quota = bzed : 1234, www-data : 12345
[/home]
quota = users : 1000000, adm : 0

+ 6
- 2
src/diskquota/manage.py View File

@@ -58,6 +58,8 @@ def __path_groups__(path):
and the configured groups for this path.
"""
config_path = __find_configured_path__(path)
if not config_path:
raise ValueError("Could not find a valid configuration for %s" %(path, ))
groups = config.get_quota_settings(config_path)
return groups

@@ -90,11 +92,13 @@ def set_quota(user, path):
if not new_quota == None:
for gid in groups.iterkeys():
if __user_in_group__(user, gid):
if (not new_quota) or groups[gid] > new_quota:
if groups[gid] == 0:
new_quota = 0
elif (not new_quota == None) or groups[gid] > new_quota:
new_quota = groups[gid]
#if we need to set a quota:
if new_quota:
if not new_quota == None:
diskquota.setquota(user, new_quota, new_quota, 0, 0, False)

def get_quota_override(user, path):


Loading…
Cancel
Save