#!/usr/bin/env python
# vim: set ts=4 sts=4 sw=4 textwidth=92:
+"""
+Module holding all of the common functions used throughout the rarslave project
+"""
+
__author__ = "Ira W. Snyder (devel@irasnyder.com)"
__copyright__ = "Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)"
__license__ = "GNU GPL v2 (or, at your option, any later version)"
-# This module holds all of the common functions used throughout the rarslave project.
+# common.py -- holds all of the common functions used throughout the rarslave project
+#
+# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com)
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
import os
import re
import logging
+import subprocess
+import exceptions
import rsutil.globals
import rsutil.par2parser
-# Global constants
-(SUCCESS, ECHECK, EEXTRACT, EDELETE, ECREATE, EDETECT, EPARSE) = range(7)
-
def find_matches (regex, li, ignorecase=True):
if ignorecase:
# Runs the specified command-line in the directory given (or, in the current directory
# if none is given). It returns the status code given by the application.
- pwd = os.getcwd ()
-
- if indir != None:
+ if indir == None:
+ indir = os.getcwd()
+ else:
assert os.path.isdir (indir) # MUST be a directory!
- os.chdir (indir)
- ret = os.system (cmd)
- os.chdir (pwd)
+ print 'RUNNING COMMAND'
+ print 'Directory: %s' % indir
+ print 'Command: %s' % cmd[0]
+ for f in cmd[1:]:
+ print '-> %s' % f
+
+ ret = subprocess.Popen(cmd, cwd=indir).wait()
+
+ if ret != 0:
+ raise RuntimeError
+
return ret
def full_abspath (p):
if len(l1) != len(l2):
return False
- for e in l1:
- if e not in l2:
- return False
-
- return True
+ return set(l1) == set(l2)
# Convience functions for the config
def options_get_value (name):
return getattr (rsutil.globals.options, name)
-def main ():
- pass
-
-if __name__ == '__main__':
- main ()
-