| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2015 Gefasoft AG |
|---|
| 4 | # Copyright (C) 2015 Franz Mayer <franz.mayer@gefasoft.de> |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # |
|---|
| 7 | # This software is licensed as described in the file COPYING, which |
|---|
| 8 | # you should have received as part of this distribution. |
|---|
| 9 | # |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | import StringIO |
|---|
| 13 | from operator import eq |
|---|
| 14 | import os.path |
|---|
| 15 | import re |
|---|
| 16 | from time import localtime |
|---|
| 17 | |
|---|
| 18 | from babel.core import Locale |
|---|
| 19 | from genshi.builder import tag |
|---|
| 20 | import pkg_resources |
|---|
| 21 | import pysvn |
|---|
| 22 | from trac.config import ListOption, Option |
|---|
| 23 | from trac.core import Component, implements |
|---|
| 24 | from trac.versioncontrol.api import * |
|---|
| 25 | from trac.web import IRequestHandler |
|---|
| 26 | from trac.web.api import RequestDone |
|---|
| 27 | from trac.web.chrome import INavigationContributor, ITemplateProvider, add_warning, Chrome,\ |
|---|
| 28 | add_notice, add_script |
|---|
| 29 | |
|---|
| 30 | import Permissions |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | class Translationmanager_Plugin(Component): |
|---|
| 34 | """Main view for translation manager. |
|---|
| 35 | |
|---|
| 36 | Translation manager plugin needs `pysvn` in order to submit changes to |
|---|
| 37 | Subversion. Unfortunately `pysvn` cannot be installed using `easy_install`. |
|---|
| 38 | Thus you need to install `pysvn` manually; on debian-based systems this |
|---|
| 39 | can be done by `apt-get`: |
|---|
| 40 | |
|---|
| 41 | {{{#!sh |
|---|
| 42 | sudo apt-get install python-svn |
|---|
| 43 | }}} |
|---|
| 44 | |
|---|
| 45 | @author: barbara.streppel |
|---|
| 46 | """ |
|---|
| 47 | implements(INavigationContributor, IRequestHandler, ITemplateProvider) |
|---|
| 48 | __up="" |
|---|
| 49 | __keys = {} |
|---|
| 50 | __lang_dict = {} |
|---|
| 51 | __propdict = {} |
|---|
| 52 | # {birt: [propdest_birt, checkout_folder_birt, /Legato], webapp: [...]} |
|---|
| 53 | __dest_dict = {} |
|---|
| 54 | |
|---|
| 55 | # Importieren |
|---|
| 56 | __up = "" |
|---|
| 57 | __upload_content = [] |
|---|
| 58 | __dict_all_neu = {} |
|---|
| 59 | __propdict_import = {} |
|---|
| 60 | __error_dict = {} |
|---|
| 61 | |
|---|
| 62 | __target_folder = "" |
|---|
| 63 | __double = [] |
|---|
| 64 | |
|---|
| 65 | def __init__(self): |
|---|
| 66 | self.dict1 = Diction(self.log, self._dest_desc, self._prop_dest, |
|---|
| 67 | self._checkout_folder, self.env,self._repository,self._checkout); |
|---|
| 68 | self.dict1.get_Diction() |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | # Configuration options |
|---|
| 72 | # Subversion options |
|---|
| 73 | _repository = Option("translationmanager", "svn_repository", "/Legato") |
|---|
| 74 | _checkout = Option( |
|---|
| 75 | "translationmanager", "svn_url", "http://av-devdata-test/svn") |
|---|
| 76 | _svn_register = Option("translationmanager", "svn_username", "barstr") |
|---|
| 77 | _svn_password = Option("translationmanager", "svn_password", "bar#str") |
|---|
| 78 | _comment = Option("translationmanager", "default_comment", |
|---|
| 79 | "{function} von Trac Translationmanager") |
|---|
| 80 | |
|---|
| 81 | # options for translation file destination |
|---|
| 82 | _prop_dest = ListOption("translationmanager", "destination_folders", |
|---|
| 83 | "/WebApp/trunk/web/uploads/reports/birt, \ |
|---|
| 84 | /WebApp/trunk/src/de/gefasoft/legato/webapp") |
|---|
| 85 | _dest_desc = ListOption("translationmanager", "destination_descriptions", |
|---|
| 86 | "Birt, Webapp") |
|---|
| 87 | _checkout_folder = ListOption("translationmanager", "checkout_folder", |
|---|
| 88 | "/var/local/transman/checkout_birt, \ |
|---|
| 89 | /var/local/transman/checkout") |
|---|
| 90 | |
|---|
| 91 | # INavigationContributor methods |
|---|
| 92 | def get_active_navigation_item(self, req): |
|---|
| 93 | if Permissions.checkPermissionsView(self, req): |
|---|
| 94 | return "Translationmanager" |
|---|
| 95 | |
|---|
| 96 | def get_navigation_items(self, req): |
|---|
| 97 | if Permissions.checkPermissionsView(self, req): |
|---|
| 98 | yield ("mainnav", "Translationmanager", |
|---|
| 99 | tag.a("Translationmanager", href=req.href.transmgr())) |
|---|
| 100 | |
|---|
| 101 | # IRequestHandler methods |
|---|
| 102 | def match_request(self, req): |
|---|
| 103 | return re.match(r'/transmgr' + '(?:/.*)?$', req.path_info) |
|---|
| 104 | |
|---|
| 105 | def process_request(self, req): |
|---|
| 106 | self.log.info("main: %s" %(req.args)) |
|---|
| 107 | add_script(req, 'hw/js/transmgr.js') |
|---|
| 108 | Chrome(self.env).add_jquery_ui(req) |
|---|
| 109 | |
|---|
| 110 | perm = Permissions.whatPermission(self, req) |
|---|
| 111 | self.log.info("permissions: %s" % perm) |
|---|
| 112 | |
|---|
| 113 | def svn_login(realm, username, may_save): |
|---|
| 114 | # Muss Rechte haben, um auf das SVN zugreifen zu können |
|---|
| 115 | return True, self._svn_register, self._svn_password, False |
|---|
| 116 | |
|---|
| 117 | # sql = "SELECT DISTINCT username FROM permission" Für import durch aktuellen user |
|---|
| 118 | # result = self.env.db_query(sql) |
|---|
| 119 | # self.log.info(result) |
|---|
| 120 | client = pysvn.Client() |
|---|
| 121 | client.callback_get_login = svn_login |
|---|
| 122 | |
|---|
| 123 | self.log.info("path: %s" % req.path_info) |
|---|
| 124 | self.log.info("up: %s" % self.__up) |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | if req.path_info=="/transmgr": |
|---|
| 128 | self.clearall(req) |
|---|
| 129 | data = {"perm": perm, |
|---|
| 130 | "dest_desc": self.dict1._dest_desc, |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | return "tm-first.html",data ,None |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | if req.path_info == "/transmgr/tm-start.html": |
|---|
| 138 | self.log.info("tm-start") |
|---|
| 139 | #Weiter nach erster seite |
|---|
| 140 | if Permissions.checkPermissionsView(self, req): |
|---|
| 141 | if req.args.has_key("ort"): |
|---|
| 142 | path = req.args["ort"] |
|---|
| 143 | req.session["path"] = path |
|---|
| 144 | else: |
|---|
| 145 | path=req.session["path"] |
|---|
| 146 | nodes = self.dict1.nodes[path] |
|---|
| 147 | |
|---|
| 148 | self.__lang_dict = dict(self.dict1.dict_languages[path]) |
|---|
| 149 | |
|---|
| 150 | data = {"lang_dict": self.__lang_dict, |
|---|
| 151 | "perm": perm} |
|---|
| 152 | |
|---|
| 153 | return"tm-start.html",data,None |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | if req.args.has_key("Datei")\ |
|---|
| 161 | and req.path_info != "/transmgr/import-export.html" \ |
|---|
| 162 | and req.path_info != "/transmgr/extra.html": |
|---|
| 163 | self.log.info("Datei") |
|---|
| 164 | upload = req.args["Datei"] |
|---|
| 165 | upload_content = [] |
|---|
| 166 | try: |
|---|
| 167 | upload_content = upload.file.readlines() |
|---|
| 168 | help_list = [] |
|---|
| 169 | for a in upload_content: |
|---|
| 170 | b = a.replace("\\", "\\\\") |
|---|
| 171 | # self.log.info("content before coding: %s" % b) |
|---|
| 172 | help_list.append(b.decode("utf8")) |
|---|
| 173 | self.__upload_content = help_list |
|---|
| 174 | # self.log.info("upload_content: %s" % self.__upload_content) |
|---|
| 175 | self.__up = "durchsuchen" |
|---|
| 176 | except Exception, e: |
|---|
| 177 | self.log.error("Es wurde keine Datei ausgewählt: %s" % (e)) |
|---|
| 178 | msg = "Es wurde keine Datei ausgewählt oder der Dateityp wird nicht akzeptiert! Wählen Sie eine .txt- oder .csv-Datei" |
|---|
| 179 | add_warning(req, msg.decode("utf-8")) |
|---|
| 180 | |
|---|
| 181 | elif req.args.has_key("coding") and req.path_info != "/transmgr/import-export.html" and req.path_info != "/transmgr/extra.html": |
|---|
| 182 | self.log.info("coding") |
|---|
| 183 | self.__dict_all_neu = self.read_csv(self.__upload_content, req.args["coding"], int( |
|---|
| 184 | req.args["start_import"]), req.args["seperator"], req.args["qualifier"]) |
|---|
| 185 | self.__up = "import_dialog" |
|---|
| 186 | req.session["show"] = req.args["showing"] |
|---|
| 187 | self.log.info("session show vorher: %s" % req.session["show"]) |
|---|
| 188 | elif self.__up == "break": |
|---|
| 189 | None |
|---|
| 190 | elif req.path_info != "/transmgr/import-export.html" and req.path_info != "/transmgr/extra.html": |
|---|
| 191 | self.__up = "" |
|---|
| 192 | |
|---|
| 193 | req.session["comment"] = "" |
|---|
| 194 | if req.args.has_key("comment"): |
|---|
| 195 | req.session["comment"] = req.args["comment"] |
|---|
| 196 | |
|---|
| 197 | if req.path_info =="/transmgr/tm-main.html": |
|---|
| 198 | self.log.info("tm-main") |
|---|
| 199 | if Permissions.checkPermissionsView(self, req): |
|---|
| 200 | double = [] |
|---|
| 201 | Herkunft = {} |
|---|
| 202 | fuzzy = [] |
|---|
| 203 | readable = [] # liste mit allen keys, die readable sind |
|---|
| 204 | |
|---|
| 205 | if req.args.has_key("ort"): |
|---|
| 206 | |
|---|
| 207 | path = req.args["ort"] |
|---|
| 208 | req.session["path"] = path |
|---|
| 209 | else: |
|---|
| 210 | path = req.session["path"] |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | if req.args.has_key("exist"): |
|---|
| 214 | req.session["exist"] = req.args["exist"] |
|---|
| 215 | |
|---|
| 216 | if req.args.has_key("ready"): # von import kommend |
|---|
| 217 | |
|---|
| 218 | req.session["exist"] = "" |
|---|
| 219 | req.session["main"] = "import" |
|---|
| 220 | Sprachen_im = [] |
|---|
| 221 | self.__propdict = {} |
|---|
| 222 | |
|---|
| 223 | all = self.__dict_all_neu |
|---|
| 224 | self.log.info("all: %s" %(all)) |
|---|
| 225 | # zeilen wird listen in liste: [[1.Spalte], [2.Spalte],...] |
|---|
| 226 | zeilen = [] |
|---|
| 227 | Err=False |
|---|
| 228 | try: |
|---|
| 229 | Test=[] |
|---|
| 230 | for a in range(0, len(all[0])): # a ist spalte |
|---|
| 231 | for i in all: # i ist zeile |
|---|
| 232 | Test.append(all[i][a]) |
|---|
| 233 | zeilen.append(Test) |
|---|
| 234 | except Exception, e: |
|---|
| 235 | msg="Die Importdatei ist Fehlerhaft bitte Zeile %s prüfen" %(i) |
|---|
| 236 | self.log.info("Err: %s" %(e)) |
|---|
| 237 | Err=True |
|---|
| 238 | add_warning(req, msg.decode("utf-8")) |
|---|
| 239 | data = {"perm": perm, |
|---|
| 240 | "dest_desc": self.dict1._dest_desc} |
|---|
| 241 | return "tm-first.html",data,None |
|---|
| 242 | zeilen = [] |
|---|
| 243 | for a in range(0, len(all[0])): # a ist spalte |
|---|
| 244 | spalten = [] |
|---|
| 245 | for i in all: # i ist zeile |
|---|
| 246 | spalten.append(all[i][a]) |
|---|
| 247 | zeilen.append(spalten) |
|---|
| 248 | help_list = [] |
|---|
| 249 | self.log.info( |
|---|
| 250 | "length import dict line 1: %s" % len(all[0])) |
|---|
| 251 | |
|---|
| 252 | # zeilenumbrüche werden entfernt: |
|---|
| 253 | # zeilen[len(all[0])-1] ist letzte Spalte |
|---|
| 254 | for a in zeilen[len(all[0]) - 1]: |
|---|
| 255 | clear = re.search(r"(\S*)", a) |
|---|
| 256 | help_list.append(clear.group(1)) |
|---|
| 257 | del zeilen[len(all[0]) - 1] |
|---|
| 258 | zeilen.append(help_list) |
|---|
| 259 | |
|---|
| 260 | index_key = 0 |
|---|
| 261 | index_im = [] |
|---|
| 262 | |
|---|
| 263 | if isinstance(req.args["lang"], list): # dups ist immer da |
|---|
| 264 | for a in req.args["lang"]: |
|---|
| 265 | lang = re.search(r"(\S*)", a) |
|---|
| 266 | Sprachen_im.append(lang.group(1)) |
|---|
| 267 | self.log.info("Sprachen_im: %s" % Sprachen_im) |
|---|
| 268 | for i in range(1, len(zeilen)): |
|---|
| 269 | if zeilen[i][0] == "Key": |
|---|
| 270 | index_key = i |
|---|
| 271 | # ausgewaehlte Sprachen und dups (dups wird beim |
|---|
| 272 | # einchecken nicht beachtet) |
|---|
| 273 | if zeilen[i][0] in Sprachen_im: |
|---|
| 274 | index_im.append(i) |
|---|
| 275 | |
|---|
| 276 | self.__target_folder = self.dict1.targetfolder[path] |
|---|
| 277 | path_to_folder = self.dict1._prop_dict["path"][path] |
|---|
| 278 | for a in Sprachen_im: |
|---|
| 279 | if a != "dups": |
|---|
| 280 | if re.search("birt", zeilen[0][1]): |
|---|
| 281 | b = "gefasoft_" + a + ".properties" |
|---|
| 282 | Sprachen_im[Sprachen_im.index(a)] = b |
|---|
| 283 | elif re.search("webapp", zeilen[0][1]): |
|---|
| 284 | b = "messages_" + a + ".properties" |
|---|
| 285 | Sprachen_im[Sprachen_im.index(a)] = b |
|---|
| 286 | |
|---|
| 287 | self.__propdict_import = {} |
|---|
| 288 | for i in range(1, len(zeilen)): |
|---|
| 289 | if i != index_key and i in index_im: |
|---|
| 290 | y = zip(zeilen[index_key], zeilen[i]) |
|---|
| 291 | dict_help = dict(y) |
|---|
| 292 | if dict_help.has_key("Key"): |
|---|
| 293 | # da komplett mit erster Zeile eingelesen |
|---|
| 294 | # -> erste zeile gelöscht |
|---|
| 295 | del dict_help["Key"] |
|---|
| 296 | # bleibt noch drinnen für double, darf deswegen |
|---|
| 297 | # nicht umbenannt werden |
|---|
| 298 | if zeilen[i][0] == "dups": |
|---|
| 299 | self.__propdict_import[ |
|---|
| 300 | zeilen[i][0]] = dict_help |
|---|
| 301 | else: |
|---|
| 302 | if re.search("birt", zeilen[0][1]): |
|---|
| 303 | # zeilen[i][0] ist nur de, en,... nicht |
|---|
| 304 | # gefasoft_de.prop |
|---|
| 305 | self.__propdict_import[ |
|---|
| 306 | "gefasoft_" + zeilen[i][0] + ".properties"] = dict_help |
|---|
| 307 | elif re.search("webapp", zeilen[0][1]): |
|---|
| 308 | self.__propdict_import[ |
|---|
| 309 | "messages_" + zeilen[i][0] + ".properties"] = dict_help |
|---|
| 310 | try: |
|---|
| 311 | # i ist welche spalte, 0 de, 0:2 die ersten |
|---|
| 312 | # beiden Buchstaben |
|---|
| 313 | loc = Locale.parse(zeilen[i][0][0:2]) |
|---|
| 314 | if re.search("birt", zeilen[0][1]): |
|---|
| 315 | self.__lang_dict[ |
|---|
| 316 | "gefasoft_" + zeilen[i][0] + ".properties"] = loc.get_display_name("de") |
|---|
| 317 | elif re.search("webapp", zeilen[0][1]): |
|---|
| 318 | self.__lang_dict[ |
|---|
| 319 | "messages_" + zeilen[i][0] + ".properties"] = loc.get_display_name("de") |
|---|
| 320 | self.log.info( |
|---|
| 321 | "lang_dict: %s" % self.__lang_dict) |
|---|
| 322 | except: |
|---|
| 323 | None |
|---|
| 324 | |
|---|
| 325 | nodes = self.dict1.nodes[path] |
|---|
| 326 | if req.session.has_key("show"): |
|---|
| 327 | self.log.info("session: %s" % req.session["show"]) |
|---|
| 328 | # propdict_import nur neue; propdict abgeglichen mit |
|---|
| 329 | # svn |
|---|
| 330 | self.__propdict = self.update_with_svn( |
|---|
| 331 | self.__propdict_import, nodes, Sprachen_im,path) |
|---|
| 332 | keys_exist = [] |
|---|
| 333 | keys_new = [] |
|---|
| 334 | keys_no_value = [] |
|---|
| 335 | |
|---|
| 336 | for a in self.__propdict_import: |
|---|
| 337 | for i in self.__propdict_import[a]: |
|---|
| 338 | if self.__propdict_import[a][i] == "": |
|---|
| 339 | if i not in keys_no_value: |
|---|
| 340 | keys_no_value.append(i) |
|---|
| 341 | |
|---|
| 342 | if req.session["show"] == "new": |
|---|
| 343 | keys_import = [] |
|---|
| 344 | for a in zeilen[index_key][1:]: |
|---|
| 345 | self.log.info("a: %s" % a) |
|---|
| 346 | if a not in keys_import: |
|---|
| 347 | keys_import.append(a) |
|---|
| 348 | if a in self.__keys: |
|---|
| 349 | keys_exist.append(a) |
|---|
| 350 | else: |
|---|
| 351 | keys_new.append(a) |
|---|
| 352 | self.__keys = keys_import |
|---|
| 353 | self.log.info("self.keys: %s" % self.__keys) |
|---|
| 354 | elif req.session["show"] == "all": |
|---|
| 355 | # in self.propdict ist noch dups mit drinnen |
|---|
| 356 | for a in self.__propdict_import: |
|---|
| 357 | self.log.info("a: %s" % a) |
|---|
| 358 | if a != "dups": |
|---|
| 359 | for i in self.__propdict[a]: |
|---|
| 360 | if i not in self.__keys: |
|---|
| 361 | self.__keys.append(i) |
|---|
| 362 | keys_new.append(i) |
|---|
| 363 | else: |
|---|
| 364 | keys_exist.append(i) |
|---|
| 365 | |
|---|
| 366 | self.__error_dict["warning_exist"] = keys_exist |
|---|
| 367 | self.__error_dict["warning_new"] = keys_new |
|---|
| 368 | self.__error_dict["warning_no_value"] = keys_no_value |
|---|
| 369 | self.log.info("range: %s"%(zeilen[0])) |
|---|
| 370 | for a in range(1, len(zeilen[0])-1): |
|---|
| 371 | |
|---|
| 372 | # self.log.info("zeile a: %s zeile:%s"%(a,(zeilen[0][a]))) |
|---|
| 373 | # self.log.info("indexkey: %s" %index_key) |
|---|
| 374 | help_zeile = zeilen[0][a] |
|---|
| 375 | # self.log.info("help: %s"%help_zeile) |
|---|
| 376 | Herkunft[zeilen[index_key][a]] = help_zeile |
|---|
| 377 | |
|---|
| 378 | msg = "Um die importierten Daten endgültig ins SVN zu übertragen, müssen Sie noch auf 'Einchecken' klicken. \n " |
|---|
| 379 | add_warning(req, msg.decode("utf-8")) |
|---|
| 380 | else: |
|---|
| 381 | msg = "Sie haben keine Spalte ausgewählt!" |
|---|
| 382 | add_warning(req, msg.decode("utf-8")) |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | if req.args.has_key("warning"): # von warnung kommend |
|---|
| 386 | req.session["main"] = "import" |
|---|
| 387 | msg = "Um die importierten Daten endgültig ins SVN zu übertragen, müssen Sie noch auf 'Einchecken' klicken. \n " |
|---|
| 388 | add_warning(req, msg.decode("utf-8")) |
|---|
| 389 | warning = req.args["warning"] |
|---|
| 390 | #self.log.info("error_dict vor aenderung: %s" % |
|---|
| 391 | # self.__error_dict) |
|---|
| 392 | for i in self.__error_dict[warning]: |
|---|
| 393 | if req.args.has_key(warning): |
|---|
| 394 | # req.args sind die ausgewählten, error_dict alle |
|---|
| 395 | if i not in req.args[warning]: |
|---|
| 396 | for u in self.__propdict_import: |
|---|
| 397 | del self.__propdict[u][i] |
|---|
| 398 | self.__keys.remove(i) |
|---|
| 399 | if self.__up == "break": |
|---|
| 400 | req.session["error"] = "" |
|---|
| 401 | self.__error_dict = {} |
|---|
| 402 | self.log.info("error_dict geloescht") |
|---|
| 403 | self.__up == "" |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | if req.args.has_key("main_to_main"): # nach einchecken |
|---|
| 407 | |
|---|
| 408 | nodes = self.dict1.nodes[path] |
|---|
| 409 | |
|---|
| 410 | if os.path.exists(self.__target_folder): |
|---|
| 411 | |
|---|
| 412 | client.update(self.__target_folder) |
|---|
| 413 | rev = client.info(self.__target_folder).revision.number |
|---|
| 414 | self.log.info("update to rev: %s" % rev) |
|---|
| 415 | else: |
|---|
| 416 | |
|---|
| 417 | checkout = self._checkout + self._repository |
|---|
| 418 | self.log.info("checkout: %s"%(checkout)) |
|---|
| 419 | # path falsch meiner Meinung!!!!!!!!!!!!! |
|---|
| 420 | client.checkout(checkout, self.__target_folder) |
|---|
| 421 | |
|---|
| 422 | change_dict = {} |
|---|
| 423 | Sprachen_change = [] |
|---|
| 424 | for key in req.args: |
|---|
| 425 | # key = key_from_properties bzw auch formtoken,... |
|---|
| 426 | change_dict[key] = req.args[key] |
|---|
| 427 | self.log.info("key: %s" % key) |
|---|
| 428 | if "_from_" in key: |
|---|
| 429 | x = key.split("_from_") |
|---|
| 430 | if x[1] not in Sprachen_change: |
|---|
| 431 | Sprachen_change.append(x[1]) |
|---|
| 432 | self.log.info("Sprachen_change: %s" %Sprachen_change) |
|---|
| 433 | |
|---|
| 434 | if req.session["main"] == "manuell": |
|---|
| 435 | self.__propdict = self.update_dict( |
|---|
| 436 | self.__propdict, change_dict) |
|---|
| 437 | msg = "Die Änderungen wurden erfolgreich eingecheckt" |
|---|
| 438 | add_notice(req, msg.decode("utf-8")) |
|---|
| 439 | elif req.session["main"] == "import": |
|---|
| 440 | helpdict = self.update_dict( |
|---|
| 441 | self.__propdict, change_dict) |
|---|
| 442 | # self.__keys werden auch akualisiert |
|---|
| 443 | self.__propdict = self.update_with_svn( |
|---|
| 444 | helpdict, nodes, Sprachen_change,path) |
|---|
| 445 | add_notice( |
|---|
| 446 | req, "Der Import wurde erfolgreich eingecheckt") |
|---|
| 447 | |
|---|
| 448 | b = "" |
|---|
| 449 | for a in self.__propdict: |
|---|
| 450 | self.log.info("einzucheckende Sprache: %s" %(a)) |
|---|
| 451 | # kommt es von Import? Brauche ich das noch? |
|---|
| 452 | if ".properties" not in a: |
|---|
| 453 | # fr wird zu gefasoft_fr.properties |
|---|
| 454 | name2 = re.search("(\w*)", a) |
|---|
| 455 | if "birt" in self.__target_folder: |
|---|
| 456 | b = "gefasoft_" + \ |
|---|
| 457 | name2.group(1) + ".properties" |
|---|
| 458 | else: |
|---|
| 459 | b = "messages_" + \ |
|---|
| 460 | name2.group(1) + ".properties" |
|---|
| 461 | else: |
|---|
| 462 | # propdict hat einmal als key nur fr, einmal |
|---|
| 463 | # gefasoft_fr.properties |
|---|
| 464 | b = a |
|---|
| 465 | |
|---|
| 466 | help_var = "" |
|---|
| 467 | if not os.path.isfile(self.__target_folder + "//" + b): |
|---|
| 468 | help_var = "no" |
|---|
| 469 | |
|---|
| 470 | # file wird geschrieben, ob es vorher existiert hat |
|---|
| 471 | # oder nicht |
|---|
| 472 | self.log.info("Write: %s"%(self.dict1.write_folder)) |
|---|
| 473 | self.write_prop( |
|---|
| 474 | self.__propdict[a], b, self.__target_folder) |
|---|
| 475 | if help_var == "no": |
|---|
| 476 | client.add(self.__target_folder + "//" + b) |
|---|
| 477 | self.log.info("File added: %s" % b) |
|---|
| 478 | if req.session["comment"] != "": |
|---|
| 479 | self.log.info("target:%s"%([self.__target_folder])) |
|---|
| 480 | client.checkin( |
|---|
| 481 | [self.__target_folder], req.session["comment"]) |
|---|
| 482 | self.log.info("Eingecheckt!") |
|---|
| 483 | dict1 = Diction(self.log, self._dest_desc, self._prop_dest, |
|---|
| 484 | self._checkout_folder, self.env,self._repository,self._checkout) |
|---|
| 485 | if "download" in req.args: # Export |
|---|
| 486 | buf = StringIO.StringIO() |
|---|
| 487 | complete_first = [] |
|---|
| 488 | all = [] |
|---|
| 489 | m = len(self.__propdict) |
|---|
| 490 | |
|---|
| 491 | for a in self.__propdict: # 1.Zeile |
|---|
| 492 | e = re.search(r"_(.*)\.", a) |
|---|
| 493 | complete_first.append(e.group(1)) |
|---|
| 494 | |
|---|
| 495 | for i in self.__keys: # Rest |
|---|
| 496 | complete = [i] |
|---|
| 497 | for e in self.__propdict: |
|---|
| 498 | for u in self.__propdict[e]: |
|---|
| 499 | if i == u: |
|---|
| 500 | complete.append(self.__propdict[e][i]) |
|---|
| 501 | if i not in self.__propdict[e]: |
|---|
| 502 | complete.append("") |
|---|
| 503 | all.append(complete) |
|---|
| 504 | self.log.info("all: %s" % all) |
|---|
| 505 | for i in range(0, len(self.__keys) + 1): |
|---|
| 506 | if i == 0: |
|---|
| 507 | content = "Bundle;Key" |
|---|
| 508 | for e in range(m): |
|---|
| 509 | if e < m - 1: |
|---|
| 510 | content = content + ";" + complete_first[e] |
|---|
| 511 | elif e == m - 1: |
|---|
| 512 | content = content + ";" + "dups" + \ |
|---|
| 513 | ";" + complete_first[e] + "\r\n" |
|---|
| 514 | buf.write(content) |
|---|
| 515 | else: |
|---|
| 516 | content = self.dict1._prop_dest[path] |
|---|
| 517 | |
|---|
| 518 | for e in range(m + 1): |
|---|
| 519 | if e < m: |
|---|
| 520 | content = content + ";" + all[i - 1][e] |
|---|
| 521 | self.log.info("content: %s" % content) |
|---|
| 522 | elif e == m: |
|---|
| 523 | if all[i - 1][0] in self.__double: |
|---|
| 524 | content = content + ";d;" + \ |
|---|
| 525 | all[i - 1][e] + "\r\n" |
|---|
| 526 | else: |
|---|
| 527 | content = content + ";;" + \ |
|---|
| 528 | all[i - 1][e] + "\r\n" |
|---|
| 529 | self.log.info("content: %s" % content) |
|---|
| 530 | buf.write(content) |
|---|
| 531 | test_str = buf.getvalue() |
|---|
| 532 | req.send_header('Content-Type', 'text/plain') |
|---|
| 533 | req.send_header("Content-Length", len(test_str)) |
|---|
| 534 | req.send_header( |
|---|
| 535 | "Content-Disposition", 'attachment; filename=export.csv') |
|---|
| 536 | req.end_headers() |
|---|
| 537 | req.send( |
|---|
| 538 | test_str.encode("utf-8"), 'text/comma-separated-values') |
|---|
| 539 | buf.close() |
|---|
| 540 | raise RequestDone() |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | if req.session.has_key("path"): |
|---|
| 546 | |
|---|
| 547 | path = req.session["path"] # path = webapp oder birt |
|---|
| 548 | req.session.save() |
|---|
| 549 | path_to_folder = self.dict1._prop_dict["path"][path] |
|---|
| 550 | nodes = self.dict1.nodes |
|---|
| 551 | |
|---|
| 552 | # der "Rechtehalter" vom SVN muss auch die Rechte am |
|---|
| 553 | # Schreiben in dem Zielordner haben.. |
|---|
| 554 | self.__target_folder = self.dict1.targetfolder[path] |
|---|
| 555 | |
|---|
| 556 | if Permissions.checkPermissionsView(self, req): |
|---|
| 557 | # von tm-start kommend |
|---|
| 558 | if req.args.has_key("start_to_main"): |
|---|
| 559 | # Für CheckIn-Comment |
|---|
| 560 | req.session["main"] = "manuell" |
|---|
| 561 | miss = [] |
|---|
| 562 | Sprache = [] # Sprache definieren |
|---|
| 563 | if isinstance(req.args["Sprache"], basestring): |
|---|
| 564 | Sprache.append(req.args["Sprache"]) |
|---|
| 565 | else: |
|---|
| 566 | Sprache = req.args["Sprache"] |
|---|
| 567 | |
|---|
| 568 | self.log.info("sprache : %s"%(req.args["Sprache"])) |
|---|
| 569 | |
|---|
| 570 | # keys von allen in nodes, propdict nur für Sprache |
|---|
| 571 | self.__keys, self.__propdict = self.dict1.readout_all_info( |
|---|
| 572 | nodes, Sprache,path) |
|---|
| 573 | |
|---|
| 574 | double, miss = self.dict1.double_miss( |
|---|
| 575 | Sprache, self.__propdict,path) |
|---|
| 576 | self.log.info("miss %s"%miss) |
|---|
| 577 | self.log.info("double %s"%double) |
|---|
| 578 | if req.args["see"] == "all": |
|---|
| 579 | None |
|---|
| 580 | else: |
|---|
| 581 | self.__keys = [] |
|---|
| 582 | if "no_value" in req.args["see"]: |
|---|
| 583 | self.__keys = miss |
|---|
| 584 | self.log.info("miss: %s" % self.__keys) |
|---|
| 585 | if "double" in req.args["see"]: |
|---|
| 586 | for a in double: |
|---|
| 587 | self.__keys.append(a) |
|---|
| 588 | self.log.info("double: %s" % self.__keys) |
|---|
| 589 | |
|---|
| 590 | # neue Sprache hinzugefügt |
|---|
| 591 | elif req.args.has_key("add_lang"): |
|---|
| 592 | Sprache = [] |
|---|
| 593 | if isinstance(req.args["Sprache"], basestring): |
|---|
| 594 | Sprache.append(req.args["Sprache"]) |
|---|
| 595 | else: |
|---|
| 596 | Sprache = req.args["Sprache"] |
|---|
| 597 | for a in self.__propdict: |
|---|
| 598 | Sprache.append(a) |
|---|
| 599 | keys, new_propdict = self.dict1.readout_all_info( |
|---|
| 600 | nodes, Sprache,path) |
|---|
| 601 | self.__propdict.update(new_propdict) |
|---|
| 602 | double, miss = self.dict1.double_miss( |
|---|
| 603 | Sprache, self.__propdict,path) |
|---|
| 604 | |
|---|
| 605 | elif req.args.has_key("del_lang"): # Sprache löschen |
|---|
| 606 | Sprache = [] |
|---|
| 607 | if isinstance(req.args["Sprache"], basestring): |
|---|
| 608 | Sprache.append(req.args["Sprache"]) |
|---|
| 609 | else: |
|---|
| 610 | for a in req.args["Sprache"]: |
|---|
| 611 | Sprache.append(a) |
|---|
| 612 | for a in Sprache: |
|---|
| 613 | self.__propdict.pop(a, None) |
|---|
| 614 | Sprache_new = [] |
|---|
| 615 | for a in self.__propdict: |
|---|
| 616 | Sprache_new.append(a) |
|---|
| 617 | double, miss = self.dict1.double_miss( |
|---|
| 618 | Sprache_new, self.__propdict,path) |
|---|
| 619 | |
|---|
| 620 | elif req.args.has_key("filter"): # Filter setzen |
|---|
| 621 | Sprache = [] |
|---|
| 622 | for a in self.__propdict: |
|---|
| 623 | Sprache.append(a) |
|---|
| 624 | self.__keys, new_propdict = self.dict1.readout_all_info( |
|---|
| 625 | nodes, Sprache,path) |
|---|
| 626 | double, miss = self.dict1.double_miss( |
|---|
| 627 | Sprache, new_propdict,path) |
|---|
| 628 | if req.args["see"] == "all": |
|---|
| 629 | |
|---|
| 630 | self.__propdict.update(new_propdict) |
|---|
| 631 | else: |
|---|
| 632 | often = True |
|---|
| 633 | without = True |
|---|
| 634 | not_edit = False |
|---|
| 635 | if req.args["see"] == "own": |
|---|
| 636 | if req.args["often"] == "ignore": |
|---|
| 637 | often = False |
|---|
| 638 | elif req.args["without"] == "ignore": |
|---|
| 639 | without = False |
|---|
| 640 | elif req.args["not_edit"] == "show": |
|---|
| 641 | not_edit = True |
|---|
| 642 | |
|---|
| 643 | if often and not without: |
|---|
| 644 | self.log.info("nur doppelte") |
|---|
| 645 | self.__keys = double |
|---|
| 646 | elif not often and without: |
|---|
| 647 | self.log.info("nur miss") |
|---|
| 648 | self.__keys = miss |
|---|
| 649 | elif often and without: |
|---|
| 650 | self.log.info("beides") |
|---|
| 651 | self.__keys = double + miss |
|---|
| 652 | if not not_edit: |
|---|
| 653 | for a in self.__keys: |
|---|
| 654 | if "$" in a: |
|---|
| 655 | self.__keys.remove(a) |
|---|
| 656 | self.__propdict.update(new_propdict) |
|---|
| 657 | |
|---|
| 658 | elif req.args.has_key("search"): # suchen |
|---|
| 659 | y = [] |
|---|
| 660 | what = req.args["what"] |
|---|
| 661 | case_sensitive = False |
|---|
| 662 | if req.args.has_key("case_sensitive"): |
|---|
| 663 | case_sensitive = req.args["case_sensitive"] |
|---|
| 664 | self.log.info("Alles oder Teil: %s" % what) |
|---|
| 665 | if "Value" in what: |
|---|
| 666 | self.log.info("Value") |
|---|
| 667 | x = self.searching(req.args["much"], self.__propdict, req.args[ |
|---|
| 668 | "search_field"], "value", case_sensitive) # Liste |
|---|
| 669 | for a in x: |
|---|
| 670 | y.append(a) |
|---|
| 671 | if "Key" in what: |
|---|
| 672 | self.log.info("Key") |
|---|
| 673 | x = self.searching(req.args["much"], self.__keys, req.args[ |
|---|
| 674 | "search_field"], "key", case_sensitive) # liste |
|---|
| 675 | for a in x: |
|---|
| 676 | y.append(a) |
|---|
| 677 | self.log.info("gefunden: %s" % y) |
|---|
| 678 | self.__keys = y |
|---|
| 679 | |
|---|
| 680 | if "u\'dups \'" in self.__propdict: |
|---|
| 681 | for a in self.__propdict["u\'dups \'"]: |
|---|
| 682 | if req.args.has_key("lang"): |
|---|
| 683 | # dups und eine Sprache sind immer dabei |
|---|
| 684 | if len(req.args["lang"]) > 2: |
|---|
| 685 | if self.__propdict["u\'dups \'"][a] != "" and a != "dups": |
|---|
| 686 | double.append(a) |
|---|
| 687 | del self.__propdict["u\'dups \'"] |
|---|
| 688 | |
|---|
| 689 | for a in self.__keys: |
|---|
| 690 | if "$" in a: |
|---|
| 691 | readable.append(a) |
|---|
| 692 | |
|---|
| 693 | main = "" |
|---|
| 694 | if req.session["main"] == "import": |
|---|
| 695 | main = "Import" |
|---|
| 696 | elif req.session["main"] == "manuell": |
|---|
| 697 | main = "Manuelle Änderung" |
|---|
| 698 | msg = "Sie müssen auf 'Einchecken' klicken, damit die Änderungen an das SVN übergeben werden" |
|---|
| 699 | add_notice(req, msg.decode("utf-8")) |
|---|
| 700 | |
|---|
| 701 | self.__double = double |
|---|
| 702 | |
|---|
| 703 | percent = 100 / (len(self.__propdict) + 1) |
|---|
| 704 | |
|---|
| 705 | data = {"double": double, |
|---|
| 706 | "read": readable, |
|---|
| 707 | "fuzzy": fuzzy, |
|---|
| 708 | "key_list": self.__keys, |
|---|
| 709 | "propdict": self.__propdict, |
|---|
| 710 | "lang_dict": self.__lang_dict, |
|---|
| 711 | "main": main.decode("utf8"), |
|---|
| 712 | "perm": perm, |
|---|
| 713 | "origin": req.session["path"], |
|---|
| 714 | "percent": percent} |
|---|
| 715 | |
|---|
| 716 | return "tm-main.html", data, None |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | if req.path_info == "/transmgr/import-export.html": |
|---|
| 722 | for a in range(len(self._dest_desc)): |
|---|
| 723 | whole_dest = [] |
|---|
| 724 | whole_dest.append(self.dict1.keys[a]) |
|---|
| 725 | whole_dest.append(self._checkout_folder[a]) |
|---|
| 726 | whole_dest.append(self._repository) |
|---|
| 727 | # TODO: refactor, since it is not loaded when changed |
|---|
| 728 | self.__dest_dict[self._dest_desc[a]] = whole_dest |
|---|
| 729 | |
|---|
| 730 | dict_short = {} |
|---|
| 731 | for a in self.__dict_all_neu: |
|---|
| 732 | if a <= 2: |
|---|
| 733 | for u in self.__dict_all_neu[a]: |
|---|
| 734 | dict_short[a] = self.__dict_all_neu[a] |
|---|
| 735 | |
|---|
| 736 | data = {"up": self.__up, |
|---|
| 737 | "upload_content": self.__upload_content, |
|---|
| 738 | "dict_all_neu": dict_short, |
|---|
| 739 | "dest_dict": self.__dest_dict} |
|---|
| 740 | |
|---|
| 741 | return "import-export.html", data, None |
|---|
| 742 | |
|---|
| 743 | if req.path_info == "/transmgr/extra.html": |
|---|
| 744 | path = "" |
|---|
| 745 | if req.session.has_key("path"): |
|---|
| 746 | path = req.session["path"] |
|---|
| 747 | |
|---|
| 748 | keys_short = list() |
|---|
| 749 | if len(self.__keys) > 4: |
|---|
| 750 | i=0 |
|---|
| 751 | for d in self.__keys: |
|---|
| 752 | if i==4: |
|---|
| 753 | break |
|---|
| 754 | else: |
|---|
| 755 | keys_short.append(self.__keys[i]) |
|---|
| 756 | i+=1 |
|---|
| 757 | |
|---|
| 758 | lt = localtime() |
|---|
| 759 | jahr, monat, tag = lt[0:3] |
|---|
| 760 | datum = str(tag) + "." + str(monat) + "." + str(jahr) |
|---|
| 761 | |
|---|
| 762 | u = 0 |
|---|
| 763 | req.session["error"] = "" |
|---|
| 764 | #self.log.info("error_dict: %s" % self.__error_dict) |
|---|
| 765 | if self.__error_dict != {}: |
|---|
| 766 | if self.__error_dict["warning_exist"] != []: |
|---|
| 767 | self.log.info("warning_exist") |
|---|
| 768 | req.session["error"] = "keys_exist" |
|---|
| 769 | u += 1 |
|---|
| 770 | if req.session.has_key("exist"): |
|---|
| 771 | if req.session["exist"] == "first": |
|---|
| 772 | if self.__error_dict["warning_new"] != []: |
|---|
| 773 | req.session["error"] = "keys_new" |
|---|
| 774 | u += 1 |
|---|
| 775 | if req.session["exist"] == "second": |
|---|
| 776 | if self.__error_dict["warning_no_value"] != []: |
|---|
| 777 | req.session["error"] = "keys_no_value" |
|---|
| 778 | u += 1 |
|---|
| 779 | elif self.__error_dict["warning_no_value"] != []: |
|---|
| 780 | req.session["error"] = "keys_no_value" |
|---|
| 781 | u += 1 |
|---|
| 782 | elif self.__error_dict["warning_new"] != []: |
|---|
| 783 | self.log.info("warning_new") |
|---|
| 784 | req.session["error"] = "keys_new" |
|---|
| 785 | u += 1 |
|---|
| 786 | if req.session.has_key("exist"): |
|---|
| 787 | if req.session["exist"] == "second": |
|---|
| 788 | if self.__error_dict["warning_no_value"] != []: |
|---|
| 789 | req.session["error"] = "keys_no_value" |
|---|
| 790 | u += 1 |
|---|
| 791 | elif self.__error_dict["warning_no_value"] != []: |
|---|
| 792 | self.log.info("warning_no_value") |
|---|
| 793 | req.session["error"] = "keys_no_value" |
|---|
| 794 | u += 1 |
|---|
| 795 | req.session["main"] = "import" |
|---|
| 796 | self.log.info("sessionmain: %s" %(req.session["main"])) |
|---|
| 797 | |
|---|
| 798 | i = 0 |
|---|
| 799 | self.log.info("errdic: %s"%(self.__error_dict)) |
|---|
| 800 | for a in self.__error_dict: |
|---|
| 801 | if self.__error_dict[a] != []: |
|---|
| 802 | i += 1 |
|---|
| 803 | if i == u and u != 0: |
|---|
| 804 | self.__up = "break" |
|---|
| 805 | |
|---|
| 806 | Sprachen = ["foo"] |
|---|
| 807 | main = "" |
|---|
| 808 | comment=[] |
|---|
| 809 | if req.session.has_key("main"): |
|---|
| 810 | self.log.info("test") |
|---|
| 811 | |
|---|
| 812 | #self.log.info("propdict : %s" %(self.__propdict)) |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | for a in self.__propdict: |
|---|
| 816 | |
|---|
| 817 | if "foo" in Sprachen: |
|---|
| 818 | self.log.info("test2") |
|---|
| 819 | Sprachen.remove("foo") |
|---|
| 820 | if a not in Sprachen: |
|---|
| 821 | self.log.info("test3") |
|---|
| 822 | Sprachen.append(a) |
|---|
| 823 | |
|---|
| 824 | if req.session["main"] == "import": |
|---|
| 825 | main = "Import" |
|---|
| 826 | elif req.session["main"] == "manuell": |
|---|
| 827 | main = "Manuelle Änderung" |
|---|
| 828 | |
|---|
| 829 | comment = self._comment.format(function=main.decode("utf-8")) |
|---|
| 830 | |
|---|
| 831 | nodes = self.dict1.nodes |
|---|
| 832 | rest, propdict_svn = self.dict1.readout_all_info(nodes, Sprachen,path) |
|---|
| 833 | |
|---|
| 834 | user = req.authname |
|---|
| 835 | data = {"lang_dict": self.__lang_dict, |
|---|
| 836 | "propdict": self.__propdict, |
|---|
| 837 | "keys_short": keys_short, |
|---|
| 838 | "Sprachen": Sprachen, |
|---|
| 839 | "path": path, |
|---|
| 840 | "comment": comment, |
|---|
| 841 | "error_dict": self.__error_dict, |
|---|
| 842 | "error": req.session["error"], |
|---|
| 843 | "user": user, |
|---|
| 844 | "prop_svn": propdict_svn} |
|---|
| 845 | return "extra.html", data, None |
|---|
| 846 | |
|---|
| 847 | |
|---|
| 848 | |
|---|
| 849 | def searching(self, was, wo, string, was_genau, case_sensitive): |
|---|
| 850 | y = [] |
|---|
| 851 | self.log.info("String: %s" % string) |
|---|
| 852 | self.log.info("was: %s" % was) |
|---|
| 853 | self.log.info("was_genau: %s" % was_genau) |
|---|
| 854 | if was == "part": |
|---|
| 855 | if was_genau == "key": |
|---|
| 856 | for a in wo: |
|---|
| 857 | if case_sensitive: |
|---|
| 858 | if re.search(string, a): |
|---|
| 859 | y.append(a) |
|---|
| 860 | else: |
|---|
| 861 | if re.search(string, a, re.IGNORECASE): |
|---|
| 862 | y.append(a) |
|---|
| 863 | if was_genau == "value": |
|---|
| 864 | for a in wo: |
|---|
| 865 | for i in wo[a]: |
|---|
| 866 | if case_sensitive: |
|---|
| 867 | if re.search(string, wo[a][i]): |
|---|
| 868 | y.append(i) |
|---|
| 869 | else: |
|---|
| 870 | if re.search(string, wo[a][i], re.IGNORECASE): |
|---|
| 871 | y.append(i) |
|---|
| 872 | if was == "whole": |
|---|
| 873 | regex = r"\b" + re.escape(string) + r"\b" |
|---|
| 874 | if was_genau == "key": |
|---|
| 875 | for a in wo: |
|---|
| 876 | if case_sensitive: |
|---|
| 877 | if re.search(regex, a): |
|---|
| 878 | y.append(a) |
|---|
| 879 | else: |
|---|
| 880 | if re.search(regex, a, re.IGNORECASE): |
|---|
| 881 | y.append(a) |
|---|
| 882 | if was_genau == "value": |
|---|
| 883 | for a in wo: |
|---|
| 884 | for i in wo[a]: |
|---|
| 885 | if case_sensitive: |
|---|
| 886 | if re.search(regex, wo[a][i]): |
|---|
| 887 | y.append(i) |
|---|
| 888 | else: |
|---|
| 889 | if re.search(regex, wo[a][i], re.IGNORECASE): |
|---|
| 890 | y.append(i) |
|---|
| 891 | return y |
|---|
| 892 | |
|---|
| 893 | def clearall(self,req): |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | if req.session.has_key("up"): |
|---|
| 897 | del req.session["up"] |
|---|
| 898 | self.log.info("updel") |
|---|
| 899 | if req.session.has_key("Datei"): |
|---|
| 900 | del req.session["Datei"] |
|---|
| 901 | if req.session.has_key("show"): |
|---|
| 902 | del req.session["show"] |
|---|
| 903 | if req.session.has_key("comment"): |
|---|
| 904 | del req.session["comment"] |
|---|
| 905 | if req.session.has_key("path"): |
|---|
| 906 | del req.session["path"] |
|---|
| 907 | if req.session.has_key("main"): |
|---|
| 908 | del req.session["main"] |
|---|
| 909 | if req.session.has_key("error"): |
|---|
| 910 | del req.session["error"] |
|---|
| 911 | self.__up="" |
|---|
| 912 | if req.session.has_key("coding"): |
|---|
| 913 | del req.session["coding"] |
|---|
| 914 | self.log.info("ses: %s"%(req.session)) |
|---|
| 915 | self.__error_dict = dict() |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | # für checkout/checkin vom svn |
|---|
| 919 | def write_prop(self, propdict_single, name, target_folder): |
|---|
| 920 | words_help = {} |
|---|
| 921 | words = {} |
|---|
| 922 | |
|---|
| 923 | for a in propdict_single: |
|---|
| 924 | words_help[a] = propdict_single[a].encode("unicode_escape") |
|---|
| 925 | words[a] = words_help[a].replace("\\x", "\\u00") |
|---|
| 926 | prop_neu = open(target_folder + "/" + name, "w+") |
|---|
| 927 | self.log.info("try to write file for %s" % name) |
|---|
| 928 | for a in sorted(words): |
|---|
| 929 | prop_neu.write(a + " = " + words[a] + "\r\n") |
|---|
| 930 | prop_neu.close() |
|---|
| 931 | return True |
|---|
| 932 | |
|---|
| 933 | def update_dict(self, prop_dict, change_dict): |
|---|
| 934 | self.log.info("changedict: %s" % change_dict) |
|---|
| 935 | for a in change_dict: |
|---|
| 936 | if "_from_" in a: |
|---|
| 937 | x = a.split("_from_") |
|---|
| 938 | key = x[0] |
|---|
| 939 | origin = x[1] |
|---|
| 940 | for ur in prop_dict: |
|---|
| 941 | if ur == origin: |
|---|
| 942 | prop_dict[ur].update({key: change_dict[a]}) |
|---|
| 943 | return prop_dict |
|---|
| 944 | |
|---|
| 945 | def update_with_svn(self, change_dict, nodes, Sprache,path): |
|---|
| 946 | self.__keys, propdict_svn = self.dict1.readout_all_info(nodes, Sprache,path) |
|---|
| 947 | for a in propdict_svn: |
|---|
| 948 | self.log.info("propdict_svn: %s" % a) |
|---|
| 949 | for a in change_dict: |
|---|
| 950 | self.log.info("change_dict: %s" % a) |
|---|
| 951 | if a in propdict_svn: |
|---|
| 952 | # ist none -> nicht mit = mit etwas verbinden |
|---|
| 953 | propdict_svn[a].update(change_dict[a]) |
|---|
| 954 | elif "_from_" in a: |
|---|
| 955 | propdict_svn.update(change_dict) |
|---|
| 956 | return propdict_svn |
|---|
| 957 | |
|---|
| 958 | def read_csv(self, file, coding, start_import, seperator, qualifier): |
|---|
| 959 | content = file[start_import - 1:len(file)] |
|---|
| 960 | dict_all = {} |
|---|
| 961 | for a in range(0, len(content)): |
|---|
| 962 | if isinstance(seperator, basestring): |
|---|
| 963 | dict_all[a] = re.split(seperator, content[a]) |
|---|
| 964 | dict_all_neu = {} |
|---|
| 965 | for a in dict_all: # a ist Zahl, value ist liste |
|---|
| 966 | new_list = [] |
|---|
| 967 | for i in dict_all[a]: |
|---|
| 968 | if qualifier == "hochkomma": |
|---|
| 969 | neu = "".join(re.findall("[^']", i)) |
|---|
| 970 | new_list.append(neu) |
|---|
| 971 | elif qualifier == "double": |
|---|
| 972 | neu = "".join(re.findall("[^\"]", i)) |
|---|
| 973 | new_list.append(neu) |
|---|
| 974 | else: |
|---|
| 975 | neu = i |
|---|
| 976 | new_list.append(neu) |
|---|
| 977 | dict_all_neu[a] = new_list |
|---|
| 978 | return dict_all_neu |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | def svn_login(realm, username, may_save): |
|---|
| 983 | # Muss Rechte haben, um auf das SVN zugreifen zu können |
|---|
| 984 | return True, self._svn_register, self._svn_password, False |
|---|
| 985 | client = pysvn.Client() |
|---|
| 986 | client.callback_get_login = svn_login |
|---|
| 987 | |
|---|
| 988 | # self.log.info("path: %s" % req.path_info) |
|---|
| 989 | # self.log.info("up: %s" % self.__up) |
|---|
| 990 | |
|---|
| 991 | # Hintergrund bleibt, Import_dialog wird ausgefuehrt |
|---|
| 992 | |
|---|
| 993 | # ITemplateProvider methods |
|---|
| 994 | def get_htdocs_dirs(self): # for static resource directories |
|---|
| 995 | return [('hw', pkg_resources.resource_filename('transmgr', 'htdocs'))] |
|---|
| 996 | |
|---|
| 997 | def get_templates_dirs(self): # for template directories |
|---|
| 998 | return [pkg_resources.resource_filename("transmgr", "templates")] |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | |
|---|
| 1003 | |
|---|
| 1004 | class Diction: |
|---|
| 1005 | dict_languages={} |
|---|
| 1006 | _prop_dict = {} |
|---|
| 1007 | nodes = {} |
|---|
| 1008 | keys = [] |
|---|
| 1009 | path_key = {} |
|---|
| 1010 | _target_folder = {} |
|---|
| 1011 | targetfolder = {} |
|---|
| 1012 | dict_content = {} |
|---|
| 1013 | key_dict = {} |
|---|
| 1014 | double = [] |
|---|
| 1015 | miss = [] |
|---|
| 1016 | prop_dict_key=[] |
|---|
| 1017 | _prop_dest={} |
|---|
| 1018 | write_folder={} |
|---|
| 1019 | def __init__(self, log, _dest_desc, _prop_dest, _checkout_folder, env, repository,checkout): |
|---|
| 1020 | self.log = log |
|---|
| 1021 | self._dest_desc = _dest_desc |
|---|
| 1022 | for i in range(len(self._dest_desc)): |
|---|
| 1023 | self._prop_dest[self._dest_desc[i]] = _prop_dest[i] |
|---|
| 1024 | self.dic_env = env |
|---|
| 1025 | self.repository = repository |
|---|
| 1026 | self._target_folder=_checkout_folder |
|---|
| 1027 | self.checkout = checkout |
|---|
| 1028 | |
|---|
| 1029 | def get_Diction(self): |
|---|
| 1030 | self._prop_dict = self.read_propert() |
|---|
| 1031 | self.make_reposmang() |
|---|
| 1032 | self.languages(self.nodes) |
|---|
| 1033 | self.keys = self._prop_dict["path"].keys() |
|---|
| 1034 | |
|---|
| 1035 | def read_propert(self): |
|---|
| 1036 | |
|---|
| 1037 | self._prop_dict["path"]={} |
|---|
| 1038 | i=0 |
|---|
| 1039 | for ort in self._dest_desc: #path ist herkunf (Birt oder Webapp) |
|---|
| 1040 | |
|---|
| 1041 | self._prop_dict["path"][ort]= self._prop_dest[ort] |
|---|
| 1042 | self.targetfolder[ort]= self._target_folder[i] |
|---|
| 1043 | self.write_folder[ort]=self.checkout+self.repository+self._prop_dest[ort] |
|---|
| 1044 | i+=1 |
|---|
| 1045 | |
|---|
| 1046 | return self._prop_dict |
|---|
| 1047 | def make_reposmang(self): |
|---|
| 1048 | rm = RepositoryManager(self.dic_env) |
|---|
| 1049 | |
|---|
| 1050 | for paths in self._prop_dict["path"]: |
|---|
| 1051 | r_path = self._prop_dict["path"][paths] |
|---|
| 1052 | names , reposi, path2 = rm.get_repository_by_path(self.repository) |
|---|
| 1053 | display = reposi.get_node(r_path) |
|---|
| 1054 | self.nodes[paths] = display.get_entries() |
|---|
| 1055 | |
|---|
| 1056 | def languages(self,nodes): |
|---|
| 1057 | self.path_key = nodes |
|---|
| 1058 | |
|---|
| 1059 | |
|---|
| 1060 | |
|---|
| 1061 | |
|---|
| 1062 | ldict={} |
|---|
| 1063 | help_dict={} |
|---|
| 1064 | for key in self.path_key: |
|---|
| 1065 | help_list = []# messages_de.properties Liste |
|---|
| 1066 | languages = [] # deutsch Liste |
|---|
| 1067 | lang_list={} |
|---|
| 1068 | path = self.path_key[key] |
|---|
| 1069 | |
|---|
| 1070 | llist=[] |
|---|
| 1071 | |
|---|
| 1072 | for i in path: #d |
|---|
| 1073 | |
|---|
| 1074 | if re.search(r"_.*\.properties", getattr(i, "name")): |
|---|
| 1075 | llist.append(i) |
|---|
| 1076 | h = self.prop_to_languages(getattr(i, "name")) |
|---|
| 1077 | if h != None: |
|---|
| 1078 | help_list.append(h) |
|---|
| 1079 | languages.append(getattr(i, "name")) |
|---|
| 1080 | |
|---|
| 1081 | |
|---|
| 1082 | lang_list = zip(languages, help_list) |
|---|
| 1083 | help_dict[key] = lang_list |
|---|
| 1084 | |
|---|
| 1085 | |
|---|
| 1086 | ldict[key]=llist |
|---|
| 1087 | self.dict_languages=help_dict |
|---|
| 1088 | |
|---|
| 1089 | |
|---|
| 1090 | self.get_Dictcontent(ldict) |
|---|
| 1091 | |
|---|
| 1092 | |
|---|
| 1093 | def prop_to_languages(self, prop): |
|---|
| 1094 | self.log.info("prop open: %s" % prop) |
|---|
| 1095 | point = prop.find(".") |
|---|
| 1096 | uline = prop.find("_") |
|---|
| 1097 | |
|---|
| 1098 | if (point - uline) == 6: |
|---|
| 1099 | loc = Locale.parse(prop[uline + 1:point]) |
|---|
| 1100 | lang_name = loc.get_display_name("de") |
|---|
| 1101 | elif (point - uline) == 3: |
|---|
| 1102 | loc = Locale(prop[uline + 1:point]) |
|---|
| 1103 | lang_name = loc.get_display_name("de") |
|---|
| 1104 | else: |
|---|
| 1105 | None |
|---|
| 1106 | return lang_name |
|---|
| 1107 | |
|---|
| 1108 | def get_Dictcontent(self,nodes1): |
|---|
| 1109 | Sprache=self.dict_languages |
|---|
| 1110 | |
|---|
| 1111 | self.dict_content["key"]={} |
|---|
| 1112 | key_list=[] |
|---|
| 1113 | key_dict={} |
|---|
| 1114 | reposmang={} |
|---|
| 1115 | prop_dict = {} |
|---|
| 1116 | for key in nodes1: |
|---|
| 1117 | key_list_unicode=[] |
|---|
| 1118 | |
|---|
| 1119 | reposmang = nodes1[key] |
|---|
| 1120 | |
|---|
| 1121 | d=0 |
|---|
| 1122 | for i in reposmang: |
|---|
| 1123 | if re.search("\.properties$", getattr(i, "name")) and not re.search(r"_user_", getattr(i, "name")): |
|---|
| 1124 | l = Sprache[key][d] |
|---|
| 1125 | key_list_help, prop_dict_help = self.read_prop(i, l[0]) |
|---|
| 1126 | spr = Sprache[key] |
|---|
| 1127 | if getattr(i, "name") in spr[d]: |
|---|
| 1128 | prop_dict[getattr(i, "name")] = prop_dict_help |
|---|
| 1129 | self.key_dict=prop_dict |
|---|
| 1130 | for n in key_list_help: |
|---|
| 1131 | if n not in key_list: |
|---|
| 1132 | key_list.append(n) |
|---|
| 1133 | d+=1 |
|---|
| 1134 | for a in key_list: |
|---|
| 1135 | key_list_unicode.append(a.decode("unicode_escape")) |
|---|
| 1136 | key_list=[] |
|---|
| 1137 | self.dict_content["key"][key]= key_list_unicode |
|---|
| 1138 | |
|---|
| 1139 | |
|---|
| 1140 | def readout_all_info(self,node,Sprache,path): |
|---|
| 1141 | propdict={} |
|---|
| 1142 | keylist=[] |
|---|
| 1143 | if "dups" in Sprache: |
|---|
| 1144 | del Sprache[0] |
|---|
| 1145 | elif "foo" in Sprache: |
|---|
| 1146 | del Sprache[0] |
|---|
| 1147 | |
|---|
| 1148 | for lang in Sprache: |
|---|
| 1149 | if lang != "": |
|---|
| 1150 | propdict[lang]=self.key_dict[lang] |
|---|
| 1151 | keylist=self.dict_content["key"][path] |
|---|
| 1152 | |
|---|
| 1153 | return keylist,propdict |
|---|
| 1154 | |
|---|
| 1155 | |
|---|
| 1156 | def read_prop(self, n, Sprache): |
|---|
| 1157 | node = n.get_content().read() |
|---|
| 1158 | lines = [] |
|---|
| 1159 | if "\r\n" in node: |
|---|
| 1160 | lines = node.split("\r\n") |
|---|
| 1161 | else: |
|---|
| 1162 | lines = node.split("\n") |
|---|
| 1163 | keys = [] |
|---|
| 1164 | nach = [] |
|---|
| 1165 | prop_dict = {} |
|---|
| 1166 | for i in lines: |
|---|
| 1167 | if i == "\n": |
|---|
| 1168 | lines.remove(i) |
|---|
| 1169 | elif i == "": |
|---|
| 1170 | lines.remove(i) |
|---|
| 1171 | for i in lines: |
|---|
| 1172 | if not re.match("#", i): |
|---|
| 1173 | try: |
|---|
| 1174 | x = re.search(r"([\w\.-]*[^ ]) *= *(.*)", i) |
|---|
| 1175 | keys.append(x.group(1)) |
|---|
| 1176 | nach.append(x.group(2)) |
|---|
| 1177 | except: |
|---|
| 1178 | None |
|---|
| 1179 | for a in nach: |
|---|
| 1180 | if "\\:" in a or "\\=" in a or "\\ " in a or "\\\"" in a or "\\#" in a: |
|---|
| 1181 | b = "" |
|---|
| 1182 | if "\\:" in a: |
|---|
| 1183 | # lis[lis.index('one')] = 'replaced!' |
|---|
| 1184 | b = a.replace("\\:", ":") |
|---|
| 1185 | elif "\\=" in a: |
|---|
| 1186 | b = a.replace("\\=", "=") |
|---|
| 1187 | elif "\\ " in a: |
|---|
| 1188 | b = a.replace("\\ ", " ") |
|---|
| 1189 | elif "\\\"" in a: |
|---|
| 1190 | b = a.replace("\\\"", "\"") |
|---|
| 1191 | elif "\\#" in a: |
|---|
| 1192 | b = a.replace("\\#", "#") |
|---|
| 1193 | nach[nach.index(a)] = b |
|---|
| 1194 | if getattr(n, "name") in Sprache: |
|---|
| 1195 | y = zip(keys, nach) |
|---|
| 1196 | prop_dict_help = dict(y) |
|---|
| 1197 | prop_dict = {} |
|---|
| 1198 | for a in prop_dict_help: |
|---|
| 1199 | prop_dict[a] = prop_dict_help[a].decode("unicode_escape") |
|---|
| 1200 | return keys, prop_dict |
|---|
| 1201 | |
|---|
| 1202 | def double_miss(self, Sprache, propdict,path): |
|---|
| 1203 | for a in propdict.iterkeys(): |
|---|
| 1204 | self.log.info("Keys vom propdict: %s" % a) |
|---|
| 1205 | double = [] |
|---|
| 1206 | miss = [] |
|---|
| 1207 | |
|---|
| 1208 | |
|---|
| 1209 | self.log.info("In double_all mit Sprache: %s" % Sprache) |
|---|
| 1210 | for i in range(0, len(Sprache) - 1): |
|---|
| 1211 | self.log.info("i: %s" % i) |
|---|
| 1212 | for n in range(1, len(Sprache) - i): |
|---|
| 1213 | self.log.info("n: %s" % n) |
|---|
| 1214 | for a in self.dict_content['key'][path]: |
|---|
| 1215 | if a in propdict[Sprache[i]] and a in propdict[Sprache[i + n]]: |
|---|
| 1216 | if eq((propdict[Sprache[i]])[a], (propdict[Sprache[i + n]])[a]): |
|---|
| 1217 | if a not in double: |
|---|
| 1218 | double.append(a) |
|---|
| 1219 | else: |
|---|
| 1220 | if a not in miss: |
|---|
| 1221 | miss.append(a) |
|---|
| 1222 | |
|---|
| 1223 | if len(Sprache) == 1: |
|---|
| 1224 | for a in self.key_dict[Sprache[0]]: |
|---|
| 1225 | if a not in propdict[Sprache[0]]: |
|---|
| 1226 | miss.append(a) |
|---|
| 1227 | return double, miss |
|---|
| 1228 | |
|---|
| 1229 | |
|---|