CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
fff_deletion.FileDeleter Class Reference
Inheritance diagram for fff_deletion.FileDeleter:

Public Member Functions

def __init__
 
def delete
 
def rename
 
def run
 
def send_smg
 

Public Attributes

 email_to
 
 fake
 
 hostname
 
 last_email
 
 min_interval
 
 thresholds
 
 top
 

Detailed Description

Definition at line 75 of file fff_deletion.py.

Constructor & Destructor Documentation

def fff_deletion.FileDeleter.__init__ (   self,
  top,
  thresholds,
  email_to,
  fake = True 
)

Definition at line 76 of file fff_deletion.py.

76 
77  def __init__(self, top, thresholds, email_to, fake=True, ):
78  self.top = top
79  self.fake = fake
80  self.email_to = email_to
81  self.thresholds = thresholds
82 
83  self.last_email = None
84  self.min_interval = datetime.timedelta(seconds=60*10)
85  self.hostname = socket.gethostname()

Member Function Documentation

def fff_deletion.FileDeleter.delete (   self,
  f 
)

Definition at line 101 of file fff_deletion.py.

References fff_deletion.FileDeleter.fake, and ValidationMisalignedTracker.fake.

Referenced by Vispa.Gui.PortConnection.PointToPointConnection.keyPressEvent(), Vispa.Views.LineDecayView.LineDecayContainer.keyPressEvent(), Vispa.Gui.VispaWidget.VispaWidget.keyPressEvent(), and fff_deletion.FileDeleter.run().

102  def delete(self, f):
103  if not f.endswith(".deleted"):
104  return
105 
106  if self.fake:
107  log.warning("Truncating file (fake): %s", f)
108  else:
109  log.warning("Truncating file: %s", f)
110  open(f, "w").close()
def fff_deletion.FileDeleter.rename (   self,
  f 
)

Definition at line 86 of file fff_deletion.py.

References fff_deletion.FileDeleter.fake, and ValidationMisalignedTracker.fake.

Referenced by fff_deletion.FileDeleter.run().

86 
87  def rename(self, f):
88  if f.endswith(".deleted"):
89  return
90 
91  fn = f + ".deleted"
92 
93  if self.fake:
94  log.warning("Renaming file (fake): %s -> %s", f,
95  os.path.relpath(fn, os.path.dirname(f)))
96  else:
97  log.warning("Renaming file: %s -> %s", f,
98  os.path.relpath(fn, os.path.dirname(f)))
99 
100  os.rename(f, fn)
def fff_deletion.FileDeleter.run (   self)

Definition at line 133 of file fff_deletion.py.

References fff_deletion.cleanup_threshold(), fff_deletion.FileDeleter.delete(), fff_deletion.diskusage(), fff_deletion.FileDeleter.rename(), fff_deletion.FileDeleter.thresholds, and fff_deletion.FileDeleter.top.

Referenced by Types.EventID.cppID(), and Types.LuminosityBlockID.cppID().

134  def run(self):
135  cleanup_threshold(self.top, self.thresholds['rename'], self.rename, "rename")
136  cleanup_threshold(self.top, self.thresholds['delete'], self.delete, "delete")
137 
138  du = diskusage(self.top)
139  if du > self.thresholds['email']:
140  deleter.send_smg(du)
141 
142 # use a named socket check if we are running
143 # this is very clean and atomic and leave no files
# from: http://stackoverflow.com/a/7758075
def cleanup_threshold
Definition: fff_deletion.py:51
def fff_deletion.FileDeleter.send_smg (   self,
  used_pc 
)

Definition at line 111 of file fff_deletion.py.

References fff_deletion.FileDeleter.email_to, fff_deletion.FileDeleter.hostname, fff_deletion.FileDeleter.last_email, and fff_deletion.FileDeleter.min_interval.

112  def send_smg(self, used_pc):
113  now = datetime.datetime.now()
114 
115  if (self.last_email is not None):
116  if (now - self.last_email) < self.min_interval:
117  return
118 
119  self.last_email = now
120 
121  # sms service does not accept an email with a several recipients
122  # so we send one-by-one
123  for email in self.email_to:
124  subject = "Disk out of space (%.02f%%) on %s." % (used_pc, self.hostname)
125  if "mail2sms" in email:
126  text = ""
127  else:
128  text = subject
129 
130  log.info("Sending email: %s", repr(["/bin/mail", "-s", subject, email]))
131  p = subprocess.Popen(["/bin/mail", "-s", subject, email], stdin=subprocess.PIPE, shell=False)
132  p.communicate(input=text)

Member Data Documentation

fff_deletion.FileDeleter.email_to

Definition at line 79 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.send_smg().

fff_deletion.FileDeleter.fake

Definition at line 78 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.delete(), and fff_deletion.FileDeleter.rename().

fff_deletion.FileDeleter.hostname

Definition at line 84 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.send_smg().

fff_deletion.FileDeleter.last_email

Definition at line 82 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.send_smg().

fff_deletion.FileDeleter.min_interval

Definition at line 83 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.send_smg().

fff_deletion.FileDeleter.thresholds

Definition at line 80 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.run().

fff_deletion.FileDeleter.top

Definition at line 77 of file fff_deletion.py.

Referenced by fff_deletion.FileDeleter.run().