comparison roundup/admin.py @ 6739:00fe67eb8a91

Update locations templates and locale files are stored Installing on a new ubuntu 22.04 venv at /tmp/roundup, I found the locale and template files installed under /tmp/roundup2/lib/python3.10/site-packages/usr/local/share which was unexpected. /tmp/roundup2/lib/python3.10/site-packages/tmp/roundup2/share would be expected. Why sys.prefix (/tmp/roundup2) was not being used but sys.base_prefix (/usr) and 'local' were added in I have no idea. In any case, updated admin and i18n code to find the files in this location. Suggested building a venv for installation with commands in installation.txt. Removed search for templates top level directory. Was used for the old location of the tracker templates pre-2009 when they were moved under share/roundup/templates. left print statemts for debugging directory search in admin templates. They are disabled by a variable set to False. At some point will add pragma's to admin to set debugging and other options see issue 2551103.
author John Rouillard <rouilj@ieee.org>
date Tue, 28 Jun 2022 23:16:47 -0400
parents 408fd477761f
children b5e465646a7c
comparison
equal deleted inserted replaced
6738:966263ad45ea 6739:00fe67eb8a91
294 294
295 Look in the following places, where the later rules take precedence: 295 Look in the following places, where the later rules take precedence:
296 296
297 1. <roundup.admin.__file__>/../../share/roundup/templates/* 297 1. <roundup.admin.__file__>/../../share/roundup/templates/*
298 this is where they will be if we installed an egg via easy_install 298 this is where they will be if we installed an egg via easy_install
299 or we are in the source tree.
299 2. <prefix>/share/roundup/templates/* 300 2. <prefix>/share/roundup/templates/*
300 this should be the standard place to find them when Roundup is 301 this should be the standard place to find them when Roundup is
301 installed 302 installed using setup.py without a prefix
302 3. <roundup.admin.__file__>/../../<sys.prefix>/share/\ 303 3. <roundup.admin.__file__>/../../<sys.prefix>/share/\
303 roundup/templates/* which is where they will be found if 304 roundup/templates/* which is where they will be found if
304 roundup is installed as a wheel using pip install 305 roundup is installed as a wheel using pip install
305 4. <roundup.admin.__file__>/../templates/* 306 4. <current working dir>/*
306 this will be used if Roundup's run in the distro (aka. source)
307 directory
308 5. <current working dir>/*
309 this is for when someone unpacks a 3rd-party template 307 this is for when someone unpacks a 3rd-party template
310 6. <current working dir> 308 5. <current working dir>
311 this is for someone who "cd"s to the 3rd-party template dir 309 this is for someone who "cd"s to the 3rd-party template dir
312 """ 310 """
313 # OK, try <prefix>/share/roundup/templates 311 # OK, try <prefix>/share/roundup/templates
314 # and <egg-directory>/share/roundup/templates 312 # and <egg-directory>/share/roundup/templates
315 # -- this module (roundup.admin) will be installed in something 313 # -- this module (roundup.admin) will be installed in something
318 # c:\python25\lib\site-packages\roundup\admin.py (4 dirs up) 316 # c:\python25\lib\site-packages\roundup\admin.py (4 dirs up)
319 # /usr/lib/python2.5/site-packages/roundup-1.3.3-py2.5-egg/roundup/admin.py 317 # /usr/lib/python2.5/site-packages/roundup-1.3.3-py2.5-egg/roundup/admin.py
320 # (2 dirs up) 318 # (2 dirs up)
321 # 319 #
322 # we're interested in where the directory containing "share" is 320 # we're interested in where the directory containing "share" is
321 debug = False
323 templates = {} 322 templates = {}
323 if debug: print(__file__)
324 for N in 2, 4, 5, 6: 324 for N in 2, 4, 5, 6:
325 path = __file__ 325 path = __file__
326 # move up N elements in the path 326 # move up N elements in the path
327 for _i in range(N): 327 for _i in range(N):
328 path = os.path.dirname(path) 328 path = os.path.dirname(path)
329 tdir = os.path.join(path, 'share', 'roundup', 'templates') 329 tdir = os.path.join(path, 'share', 'roundup', 'templates')
330 if debug: print(tdir)
330 if os.path.isdir(tdir): 331 if os.path.isdir(tdir):
331 templates = init.listTemplates(tdir) 332 templates = init.listTemplates(tdir)
333 if debug: print(" Found templates breaking loop")
332 break 334 break
333 335
334 # search for data files parallel to the roundup 336 # search for data files parallel to the roundup
335 # install dir. E.G. a wheel install 337 # install dir. E.G. a wheel install
336 # use roundup.__path__ and go up a level then use sys.prefix 338 # use roundup.__path__ and go up a level then use sys.prefix
345 for _N in 1, 2: 347 for _N in 1, 2:
346 path = os.path.dirname(path) 348 path = os.path.dirname(path)
347 # path is /usr/local/lib/python3.10/site-packages 349 # path is /usr/local/lib/python3.10/site-packages
348 tdir = os.path.join(path, sys.prefix[1:], 'share', 350 tdir = os.path.join(path, sys.prefix[1:], 'share',
349 'roundup', 'templates') 351 'roundup', 'templates')
352 if debug: print(tdir)
350 if os.path.isdir(tdir): 353 if os.path.isdir(tdir):
351 templates.update(init.listTemplates(tdir)) 354 templates.update(init.listTemplates(tdir))
352 355
353 # OK, now try as if we're in the roundup source distribution 356 try:
354 # directory, so this module will be in .../roundup-*/roundup/admin.py 357 # sigh pip 3.10 in virtual env finds another place to bury them.
355 # and we're interested in the .../roundup-*/ part. 358 # why local and sys.base_prefix are in path I do not know.
356 path = __file__ 359 # path is /usr/local/lib/python3.10/site-packages
357 for _i in range(2): 360 tdir = os.path.join(path, sys.base_prefix[1:], 'local', 'share',
358 path = os.path.dirname(path) 361 'roundup', 'templates')
359 tdir = os.path.join(path, 'templates') 362 if debug: print(tdir)
360 if os.path.isdir(tdir): 363 if os.path.isdir(tdir):
361 templates.update(init.listTemplates(tdir)) 364 templates.update(init.listTemplates(tdir))
365 # path is /usr/local/lib/python3.10/site-packages
366
367
368 tdir = os.path.join(path, sys.base_prefix[1:], 'share',
369 'roundup', 'templates')
370 if debug: print(tdir)
371 if os.path.isdir(tdir):
372 templates.update(init.listTemplates(tdir))
373 except AttributeError:
374 pass # sys.base_prefix doesn't work under python2
362 375
363 # Try subdirs of the current dir 376 # Try subdirs of the current dir
364 templates.update(init.listTemplates(os.getcwd())) 377 templates.update(init.listTemplates(os.getcwd()))
365 378 if debug: print(os.getcwd() + '/*')
379
366 # Finally, try the current directory as a template 380 # Finally, try the current directory as a template
367 template = init.loadTemplateInfo(os.getcwd()) 381 template = init.loadTemplateInfo(os.getcwd())
382 if debug: print(os.getcwd() + '/*')
368 if template: 383 if template:
384 if debug: print(" Found template %s"%template['name'])
369 templates[template['name']] = template 385 templates[template['name']] = template
370 386
371 return templates 387 return templates
372 388
373 def help_initopts(self): 389 def help_initopts(self):

Roundup Issue Tracker: http://roundup-tracker.org/