1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
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
stringvars=("mirror", "mirrorpath", "logname", "tempdir", "archdb",
"repodir", "blacklist", "whitelist", "pending",
"rsync_blacklist",)
listvars=("repo_list", "dir_list", "arch_list", "other",)
boolvars=("output", "debug",)
config=dict()
def exit_if_none(var):
if os.environ.get(var) is None:
exit("%s is not defined" % var)
for var in stringvars:
exit_if_none(var)
config[var]=os.environ.get(var)
for var in listvars:
exit_if_none(var)
config[var]=tuple(os.environ.get(var).split(":"))
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 "
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):
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. """
package_info=dict()
def __init__(self):
self.package_info={ "name" : False,
"version" : False,
"release" : False,
"arch" : False,
"license" : False,
"location": False,
"depends" : False,}
def __setitem__(self, key, item):
if key in self.package_info.keys():
return self.package_info.__setitem__(key, item)
else:
raise ValueError("Package has no %s attribute" % key)
def __getitem__(self, key):
return self.package_info.__getitem__(key)
def __unicode__(self):
return str(self.package_info)
def __repr__(self):
return str(self.package_info)
def __eq__(self,x):
if not isinstance(x, Package):
return False
for key in self.package_info.keys():
if x[key] != self.package_info[key]:
return False
else:
return True
if __name__=="__main__":
for key in config.keys():
print("%s : %s" % (key,config[key]))
|