bug lancement windows
[iramuteq] / iracmd.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2010 Pierre Ratinaud
5 #Lisense: GNU/GPL
6
7 import os
8 from optparse import OptionParser
9 import sys
10 reload(sys)
11 import locale
12 import codecs
13 sys.setdefaultencoding(locale.getpreferredencoding())
14 from chemins import ConstructConfigPath, ConstructDicoPath, ConstructRscriptsPath
15 from functions import ReadLexique, DoConf, History
16 from ConfigParser import *
17 #######################################
18 #from textchdalc import AnalyseAlceste
19 #from textdist import PamTxt
20 #from textafcuci import AfcUci
21 from textaslexico import Lexico
22 from textstat import Stat
23 import tempfile
24 ######################################
25 print '#######LOGGING TEST###########'
26 import logging
27 log = logging.getLogger('iramuteq')
28 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
29 ch = logging.StreamHandler()
30 ch.setFormatter(formatter)
31 log.addHandler(ch)
32 log.setLevel(logging.DEBUG)
33 #######################################
34
35 log.debug('----------TEST corpusNG-----------------')
36 from analysetxt import Alceste,  gramact, gramsup
37 from corpusNG import *
38
39
40
41 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
42 if os.getenv('HOME') != None:
43     user_home = os.getenv('HOME')
44 else:
45     user_home = os.getenv('HOMEPATH')
46 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
47
48 class CmdLine :
49     def __init__(self) :
50         self.DictPath = ConstructDicoPath(AppliPath)
51         self.ConfigPath = ConstructConfigPath(UserConfigPath)
52         self.syscoding = sys.getdefaultencoding()
53         parser = OptionParser()
54     
55         parser.add_option("-f", "--file", dest="filename", help="chemin du corpus", metavar="FILE", default=False)
56         parser.add_option("-t", "--type", dest="type_analyse", help="type d'analyse", metavar="TYPE D'ANALYSE", default='False')
57
58         parser.add_option("-c", "--conf", dest="configfile", help="chemin du fichier de configuration", metavar="CONF", default=False)
59         parser.add_option("-e", "--enc", dest="encodage", help="encodage du corpus", metavar="ENC", default=locale.getpreferredencoding())
60         parser.add_option("-l", "--lang", dest="language", help="langue du corpus", metavar="LANG", default='french')
61         parser.add_option("-r", "--read", dest="read", help="lire un corpus", metavar="READ", default = False)
62
63         (options, args) = parser.parse_args()
64         print args
65         print options
66         if options.configfile :
67             self.ConfigPath[options.type_analyse] = os.path.abspath(options.configfile)
68         self.TEMPDIR = tempfile.mkdtemp('iramuteq') 
69         self.RscriptsPath = ConstructRscriptsPath(AppliPath)
70         self.PathPath = ConfigParser()
71         self.PathPath.read(self.ConfigPath['path'])        
72         self.RPath = self.PathPath.get('PATHS', 'rpath')
73         self.pref = RawConfigParser()
74         self.pref.read(self.ConfigPath['preferences'])
75         self.history = History(self.ConfigPath['history'])
76         #self.history.write()
77         if options.filename or options.read or options.build:
78             self.corpus_encodage = options.encodage
79             self.corpus_lang = options.language
80                 
81
82             #print 'PAS DE CODECS POUR CABLE'
83             ReadLexique(self, lang = options.language)
84             self.expressions = ReadDicoAsDico(self.DictPath.get(options.language + '_exp', 'french_exp'))
85             if options.filename :
86                 self.filename = os.path.abspath(options.filename)
87                 corpus_parametres = DoConf('/home/pierre/.iramuteq/corpus.cfg').getoptions('corpus')
88                 corpus_parametres['filename'] = self.filename
89                 corpus_parametres['encoding'] = self.corpus_encodage
90                 corpus_parametres['syscoding'] = 'utf8'
91                 corpus_parametres['pathout'] = PathOut(options.filename, 'corpus').dirout
92                 corpus = BuildFromAlceste(self.filename, corpus_parametres, self.lexique, self.expressions).corpus
93                 self.history.add(corpus.parametres)
94
95                 #with codecs.open(self.filename, 'r', self.corpus_encodage) as f:
96             elif options.read :
97                 corpus = Corpus(self, parametres = DoConf(options.read).getoptions('corpus'), read = options.read)
98                 corpus.parametres['path'] = os.path.abspath(options.read)
99                 pathout = os.path.dirname(os.path.dirname(os.path.abspath(options.read)))
100
101
102             corpus.conn_all()
103             corpus.parse_active(gramact, gramsup)
104                 #    self.content = f.read()
105                 #self.content = self.content.replace('\r','')
106             if options.type_analyse == 'alceste' :
107                 log.debug('ATTENTION : ANALYSE NG')
108                     #print corpus.make_etoiles()
109                     #zerzre
110                 #corpus.read_corpus()
111                 #corpus.parse_active(gramact, gramsup)
112                 Alceste(self, corpus)
113             #    self.Text = AnalyseAlceste(self, cmd = True, big = True)
114                 #self.Text = AnalyseAlceste(self, cmd = True)
115             elif options.type_analyse == 'pam' :
116                 self.Text = PamTxt(self, cmd = True)
117             elif options.type_analyse == 'afcuci' :
118                 self.Text = AfcUci(self, cmd = True)
119             elif options.type_analyse == 'stat' :
120                 self.Text = Stat(self, corpus, config = {'type' : 'stat'})
121             elif options.type_analyse == 'spec' :
122                 self.Text = Lexico(self, corpus, config = {'type' : 'spec'})
123             #print self.Text.corpus.hours, 'h', self.Text.corpus.minutes,'min', self.Text.corpus.seconds, 's'
124 #            self.Text.corpus.make_colored_corpus('colored.html')
125
126 if __name__ == '__main__':
127     __name__ = 'Main'
128     CmdLine()
129