litex/mibuild/tools.py

42 lines
859 B
Python
Raw Normal View History

import os, struct
from distutils.version import StrictVersion
2013-02-07 16:07:30 -05:00
2015-04-13 14:45:35 -04:00
2013-02-07 16:07:30 -05:00
def mkdir_noerror(d):
try:
os.mkdir(d)
except OSError:
pass
2013-02-07 16:07:30 -05:00
2015-04-13 14:45:35 -04:00
2013-02-08 14:25:20 -05:00
def language_by_filename(name):
extension = name.rsplit(".")[-1]
if extension in ["v", "vh", "vo"]:
return "verilog"
if extension in ["vhd", "vhdl", "vho"]:
return "vhdl"
return None
2013-02-08 14:25:20 -05:00
2015-04-13 14:45:35 -04:00
def write_to_file(filename, contents, force_unix=False):
newline = None
if force_unix:
newline = "\n"
with open(filename, "w", newline=newline) as f:
f.write(contents)
2015-04-13 14:45:35 -04:00
def arch_bits():
return struct.calcsize("P")*8
2015-04-13 14:45:35 -04:00
def versions(path):
for n in os.listdir(path):
full = os.path.join(path, n)
if not os.path.isdir(full):
continue
try:
yield StrictVersion(n)
except ValueError:
continue