home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.parl.clemson.edu
/
2015-02-07.ftp.parl.clemson.edu.tar
/
ftp.parl.clemson.edu
/
pub
/
fresh
/
scripts
/
process_collection_dir.py
next >
Wrap
Text File
|
2002-04-02
|
2KB
|
73 lines
#!/usr/bin/python
# Nathan DeBardeleben
# ndebard@parl.clemson.edu
# April 3, 2002
#
# A simple, very unclean script which takes a base directory
# and walks through its dir and subdirs looking for qualified
# MAME roms and spits out of stdout lines that look like
# base_path_offset_path:romname:"Some String - like a name"
# This can then be used with this scripts compliment to copy the roms
# from some dir based on a textfile (like that generated from this
# script). The point is that you can take a directory that you like
# and turn that into a 'collection' text file that you can hand to
# other people, they can then run the complementary script to make
# the same directory that you had
import sys, string, re, os, posixpath
mame_path = "/usr/local/bin/xmame.x11"
help = sys.argv[0] + " --basedir <dir w/ roms>"
if '-h' in sys.argv or '-help' in sys.argv or '--h' in sys.argv or '--help' \
in sys.argv:
print help
sys.exit(0)
if len(sys.argv) < 3:
print help
sys.exit(0)
basedir_set = 0
for i in range(len(sys.argv)):
if sys.argv[i] == "--basedir":
basedir = sys.argv[i+1]
basedir_set = 1
if basedir_set == 0:
print help
sys.exit(0)
def checkdir(direntry,base):
dir = base
if posixpath.isdir(base+"/"+direntry):
for file in os.listdir(dir+"/"+direntry):
checkdir(file,dir+"/"+direntry)
else:
# get rid of the end, incase it's got a .zip or something
possible_rom_tmp = string.split(direntry,'.')[0]
if string.find(possible_rom_tmp,'/') != -1:
possible_rom = possible_rom_tmp[string.rindex(possible_rom_tmp,'/')+1:]
else:
possible_rom = possible_rom_tmp
os.system(mame_path+" -nolcf -out /tmp/process_collection_dir.tmp -err /dev/null -lf "+possible_rom);
tmp_file = open("/tmp/process_collection_dir.tmp")
for line in tmp_file.readlines():
# the syntax says, only at start of line
if string.find(line, possible_rom) == 0:
tmpstr = string.lstrip(line[len(possible_rom):])
p = re.compile(r'\012')
str = p.split(tmpstr)[0]
tmp_dir = posixpath.normpath(dir)
if string.find(tmp_dir,posixpath.normpath(basedir)) == 0:
temp_dir = tmp_dir[len(posixpath.normpath(basedir))+1:]
else:
temp_dir = tmp_dir
print temp_dir+":"+possible_rom+":"+str
os.unlink("/tmp/process_collection_dir.tmp")
for file in os.listdir(basedir):
checkdir(file,basedir)