ya2 · news · projects · code · about

buttons' images
[pmachines.git] / pmachines / pmachines.py
1 import argparse
2 from sys import platform, argv
3 from logging import info
4 from os.path import exists
5 from os import makedirs
6 from panda3d.core import Filename, load_prc_file_data
7 from direct.showbase.ShowBase import ShowBase
8
9
10 class Pmachines:
11
12 def __init__(self):
13 self._configure()
14 self.base = ShowBase()
15 info('platform: %s' % platform)
16 info('exists main.py: %s' % exists('main.py'))
17 self._prepare_windows()
18 args = self._parse_args()
19 self.updating = args.update
20 self.version = args.version
21 if args.update:
22 return
23
24 def _configure(self):
25 load_prc_file_data('', 'window-title pmachines')
26
27 def _parse_args(self):
28 parser = argparse.ArgumentParser()
29 parser.add_argument('--update', action='store_true')
30 parser.add_argument('--version', action='store_true')
31 cmd_line = [arg for arg in iter(argv[1:]) if not arg.startswith('-psn_')]
32 args = parser.parse_args(cmd_line)
33 return args
34
35 def _prepare_windows(self):
36 data_path = ''
37 if (platform.startswith('win') or platform.startswith('linux')) and (
38 not exists('main.py') or __file__.startswith('/app/bin/')):
39 # it is the deployed version for windows
40 data_path = str(Filename.get_user_appdata_directory()) + '/pmachines'
41 home = '/home/flavio' # we must force this for wine
42 if data_path.startswith('/c/users/') and exists(home + '/.wine/'):
43 data_path = home + '/.wine/drive_' + data_path[1:]
44 info('creating dirs: %s' % data_path)
45 makedirs(data_path, exist_ok=True)