~manxi-david/pyeffect/pyeffect

« back to all changes in this revision

Viewing changes to files.py

  • Committer: dvspeed
  • Date: 2011-12-26 13:18:36 UTC
  • Revision ID: manxi.david@gmail.com-20111226131836-mvoy9y32z0ujxvm1
-Change of folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011 David Manzanares <manxi.david@gmail.com>
2
 
#This file is part of PyEffect.
3
 
#
4
 
# PyEffect is free software: you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation, either version 3 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# PyEffect is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with PyEffect. If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
#This is the PyEffect file manager, this module contains all the functions that reads, writes  and delete external files
18
 
 
19
 
#Purpose:
20
 
#Read the source (.3) and write the output of the stages in .3p, and .s
21
 
 
22
 
#Third party libraries:
23
 
import os
24
 
 
25
 
#Own libraries:
26
 
import args
27
 
import out
28
 
import s1
29
 
import s3
30
 
 
31
 
def getSource():
32
 
        """Open and read the source code in .3 format"""
33
 
        tg = args.target
34
 
        if tg[len(tg) - 2:len(tg)] != ".3":
35
 
                out.error("Source file <<"+tg+">> must have .3 extension")
36
 
        inputFile = open(tg, "r")
37
 
        source = inputFile.read()
38
 
        return source
39
 
 
40
 
def putStage1():
41
 
        """Write the STAGE1 into the .3p file"""
42
 
        outputFileS1 = open(args.target[0:(len(args.target) - 1)] + "3p", "w")
43
 
        outputFileS1.write(s1.all)
44
 
        outputFileS1.close()
45
 
 
46
 
def putStage3():
47
 
        """Write the STAGE3 into the .3s file"""
48
 
        outputFileS1 = open(args.target[0:(len(args.target) - 1)] + "3s", "w")
49
 
        outputFileS1.write(s3.lns.getStrVerbose())
50
 
        outputFileS1.close()
51
 
 
52
 
def putStage4():
53
 
        """Write the STAGE3 into the .s file"""
54
 
        from s4 import s4
55
 
        outputFileS3 = open(args.target[0:(len(args.target) - 1)] + "s", "w")
56
 
        outputFileS3.write(s4.asm)
57
 
        outputFileS3.close()
58
 
 
59
 
def cleanDir(Dir):
60
 
        """Clean the directory, remove all *.s *.3p and *.o files"""
61
 
        os.system("rm -f " + Dir + "*.s " + Dir + "*.3p " + Dir + "*.3s " + Dir + "*.o " + Dir + "*.log")
62
 
 
63
 
def clean():
64
 
        """Clean the directory wich contains the args.target if args.keep ==False"""
65
 
        if args.keep == False:
66
 
                i = len(args.target) - 1
67
 
                while args.target[i] != "/" and i > 0:
68
 
                        i = i - 1
69
 
                if i > 0:
70
 
                        cleanDir(args.target[:i + 1])
71
 
                else:
72
 
                        cleanDir("")