summaryrefslogtreecommitdiff
path: root/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'config.py')
-rwxr-xr-x[-rw-r--r--]config.py96
1 files changed, 55 insertions, 41 deletions
diff --git a/config.py b/config.py
index 3e00eb0..8b48c66 100644..100755
--- a/config.py
+++ b/config.py
@@ -1,58 +1,69 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-from user import home
-import commands
+try:
+ from subprocess import check_output
+except(ImportError):
+ from commands import getoutput
+ def check_output(*popenargs,**kwargs):
+ cmd=" ".join(*popenargs)
+ return getoutput(cmd)
import os
-time__ = commands.getoutput("date +%Y%m%d-%H:%M")
+stringvars=("mirror", "mirrorpath", "logname", "tempdir", "archdb",
+ "repodir", "blacklist", "whitelist", "pending",
+ "rsync_blacklist",)
+listvars=("repo_list", "dir_list", "arch_list", "other",)
+boolvars=("output", "debug",)
-# Mirror Parameters
-mirror = "mirrors.eu.kernel.org"
-mirrorpath = "::mirrors/archlinux"
+config=dict()
-# Directories and files
+def exit_if_none(var):
+ if os.environ.get(var) is None:
+ exit("%s is not defined" % var)
-## Optionals
-path = home + "/parabolagnulinux.org"
-docs = path + "/docs"
-logdir = path + "/log"
+for var in stringvars:
+ exit_if_none(var)
+ config[var]=os.environ.get(var)
-## Must be defined
-logname= logdir + "/" + time__ + "-repo-maintainer.log"
-freedir= path + "/free/"
-repodir= path + "/repo"
-tmp = home + "/tmp"
-archdb = tmp + "/db"
+for var in listvars:
+ exit_if_none(var)
+ config[var]=tuple(os.environ.get(var).split(":"))
-free_path= path + "/free/"
-
-# Repo, arch, and other folders to use for repo
-# This are tuples, so **always keep a comma before closing parenthesis **
-repo_list = ("core", "extra", "community", "testing", "community-testing", "multilib",)
-dir_list = ("pool",)
-arch_list = ("i686", "x86_64",)
-other = ("any",)
-
-# Output
-output = True
-verbose = True
-
-# Files
-blacklist = docs + "/blacklist.txt"
-whitelist = docs + "/whitelist.txt"
-pending = docs + "/pending"
-rsync_blacklist = docs + "/rsyncBlacklist"
+for var in boolvars:
+ exit_if_none(var)
+ if os.environ.get(var) == "True":
+ config[var]=True
+ elif os.environ.get(var) =="False":
+ config[var]=False
+ else:
+ print('%s is not True or False' % var)
# Rsync commands
-
rsync_list_command="rsync -a --no-motd --list-only "
-rsync_update_command="rsync -av --delay-updates --exclude='*.{abs|db}.tar.*' "
-rsync_post_command="rsync -av --delete --exclude='*.abs.tar.*' "
+
+def printf(text,output=config["output"]):
+ """Guarda el texto en la variable log y puede imprimir en pantalla."""
+ log_file = open(config["logname"], 'a')
+ log_file.write("\n" + str(text) + "\n")
+ log_file.close()
+ if output:
+ print (str(text) + "\n")
+
+del exit_if_none
# Classes and Exceptions
-class NonValidFile(ValueError): pass
-class NonValidDir(ValueError): pass
-class NonValidCommand(ValueError): pass
+class NonValidFile(ValueError):
+ def __init__(self):
+ ValueError.__init__(self)
+ printf(self.message)
+class NonValidDir(ValueError):
+ def __init__(self):
+ ValueError.__init__(self)
+ printf(self.message)
+class NonValidCommand(ValueError):
+ def __init__(self):
+ ValueError.__init__(self)
+ printf(self.message)
class Package:
""" An object that has information about a package. """
@@ -91,3 +102,6 @@ class Package:
else:
return True
+if __name__=="__main__":
+ for key in config.keys():
+ print("%s : %s" % (key,config[key]))