Example #1
0
def main(par):

    f_nm = par.string('file') # Name of file to process
    preserve_t = par.bool('preserve_t', True) # Whether to preserve timestamp
    verb = par.bool('verb', False) # Say if file was converted or unchanged

    ivlad.chk_file_r(f_nm)
    
    if file_is_not_old_seplib_cmplx(f_nm):
        ivlad.msg(f_nm + ': Conversion not necessary', verb)
        return ivlad.unix_success

    if not os.access(f_nm, os.W_OK):
        # Not using an exception because this program may be called on long
        # lists of files
        ivlad.msg(f_nm + ': NEED WRITE PERMISSION', True)
        return ivlad.unix_error

    if preserve_t: 
        tstamp = get_timestamp(f_nm)

    bptr = sf.get(f_nm, 'in') # Pointer to binary

    if bptr == 'stdin': # Header and binary in a single file
        __replace_last_dataformat_statement(f_nm)
    else:
        f = open(f_nm, 'a')
        f.write('\n'+ooio.first_line_rsf_hdr_entry()) 
        f.write('\tdata_format="xdr_complex"\n')
        f.close()

    if preserve_t:
        os.utime(f_nm, tstamp)

    ivlad.msg(f_nm + ': Converted', verb)

    return ivlad.unix_success
Example #2
0
# (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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import rsf.user.ivlad as ivlad
import os, sys, string

if not hasattr(' ', 'partition'):
    ivlad.msg('Please get Python 2.5 or greater')
    sys.exit(ivlad.unix_error)

try:
    import subprocess
except:
    print 'Please get Python 2.4 or greater, or just the subprocess module'
    sys.exit(unix_error)

###############################################################################

def grep_from_py(filename, string):
    'Runs "grep string filename", and returns the result'
    proc = subprocess.Popen('grep ' + string + ' ' + filename,
                            shell=True,
                            stdout=subprocess.PIPE)