|
12 | 12 |
|
13 | 13 | home = os.path.expanduser('~') |
14 | 14 | here = os.path.dirname(os.path.abspath(__file__)) |
| 15 | +config_dir = home + '/.config/clid' |
15 | 16 |
|
16 | 17 | long_des = """Clid is a command line app written in Python3 to manage your mp3 files' ID3 tags. |
17 | 18 | Unlike other tools, clid provides a graphical interface in the terminal to edit |
|
21 | 22 | See the `homepage <https://github.com/GokulSoumya/clid>`_ for more details. |
22 | 23 | """ |
23 | 24 |
|
| 25 | +def set_up_pref_file(): |
| 26 | + import configobj |
| 27 | + try: |
| 28 | + os.makedirs(config_dir) |
| 29 | + except FileExistsError: |
| 30 | + pass |
| 31 | + |
| 32 | + default = configobj.ConfigObj(here + '/clid/config.ini') # get the ini file with default settings |
| 33 | + try: |
| 34 | + # get user's config file if app is already installed |
| 35 | + user = configobj.ConfigObj(config_dir + '/clid.ini', file_error=True) |
| 36 | + except OSError: |
| 37 | + # expand `~/Music` if app is being installed for the first time |
| 38 | + user = configobj.ConfigObj(config_dir + '/clid.ini') |
| 39 | + user['music_dir'] = home + '/Music/' |
| 40 | + |
| 41 | + default.update(user) # save user's settings and add new settings options |
| 42 | + default.write(outfile=open(config_dir + '/clid.ini', 'wb')) # will raise error if outfile is filename |
| 43 | + |
| 44 | +def make_whats_new(): |
| 45 | + with open(here + '/clid/NEW.txt', 'r') as file: |
| 46 | + to_write = file.read() |
| 47 | + with open(config_dir +'/NEW', 'w') as file: |
| 48 | + file.write(to_write) |
| 49 | + |
| 50 | + |
24 | 51 | class PostInstall(install): |
25 | 52 | def run(self): |
26 | | - import configobj |
27 | | - |
28 | | - default = configobj.ConfigObj(here + '/clid/config.ini') # get the ini file with default settings |
29 | | - try: |
30 | | - # get user's config file if app is already installed |
31 | | - user = configobj.ConfigObj(home + '/.clid.ini', file_error=True) |
32 | | - except OSError: |
33 | | - # expand `~/Music` if app is being installed for the first time |
34 | | - user = configobj.ConfigObj(home + '/.clid.ini') |
35 | | - user['music_dir'] = home + '/Music/' |
36 | | - |
37 | | - default.update(user) # save user's settings and add new settings options |
38 | | - default.write(outfile=open(home + '/.clid.ini', 'wb')) # will raise error if outfile is filename |
| 53 | + set_up_pref_file() |
| 54 | + make_whats_new() |
| 55 | + with open(config_dir + '/first', 'w') as file: |
| 56 | + # used to display What's New popup(if true) |
| 57 | + file.write('true') |
39 | 58 |
|
40 | 59 | install.run(self) |
41 | 60 |
|
|
0 commit comments