Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import fnmatch
- def prog(sourcesPath):
- global pathed
- if nasm_check():
- if os.path.isdir(sourcesPath):
- print("Folder founded, compiling")
- asm_compiller(sourcesPath)
- else:
- print('"sources" folder not found. Please specify your asm files dir: ')
- userdir = input()
- if os.path.isdir(userdir):
- print('User folder founded, compiling')
- pathed = userdir
- asm_compiller(userdir)
- else:
- print('Folder not found')
- else: print('nasm not found')
- def asm_compiller(path):
- global errors
- global repeated
- for top, dirs, files in os.walk(path):
- for nm in files:
- if fnmatch.fnmatch(os.path.basename(os.path.join(top, nm)),'*.asm'):
- write_to_log('Comping ' + os.path.join(top, nm))
- if not nm in repeated:
- args = ['nasm', '-f', 'bin', os.path.join(top, nm), '-o', nm[:-3]+'com']
- else:
- args = ['nasm', '-f', 'bin', os.path.join(top, nm), '-o', nm[:-4]+'({}).com'.format(str(repeated.count(nm)))]
- p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- err = p.communicate()[0].decode("utf-8")
- if err:
- errors = errors + err + '\n'
- write_to_log(err)
- else:
- write_to_log('No errors')
- repeated.append(nm)
- def nasm_check():
- files = os.listdir(os.getcwd())
- for i in files:
- if i == 'nasm.exe':
- return True
- return False
- def make_log():
- f = open('compile.log','w')
- f.write('')
- f.close()
- def write_to_log(txt):
- f = open('compile.log','a')
- f.write(txt+'\n')
- f.close()
- pathed = os.getcwd() + '\\sources'
- repeated=[]
- while True:
- make_log()
- repeated=[]
- errors ='Error list:\n'
- prog(pathed)
- write_to_log('Totally compiled {} files.'.format(len(repeated)))
- errors = errors + 'Check compile.log for more'
- print (errors)
- print('Again? (Enter to repeat, anything to quit)')
- inp=input()
- if inp: break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement