return os.fsencode(tmpdir) # XXX
def get_file_type(self, tmpdir):
+ errno = 0
# check the file type
inst = ninix.home.read_install_txt(tmpdir)
if not inst:
elif filetype == 'kinoko':
pass
else:
- fatal('unsupported file type({0})'.format(filetype))
+ errno = 2
+ #fatal('unsupported file type({0})'.format(filetype))
if filetype in ['shell.inverse', 'ghost.inverse']:
- fatal('unsupported file type({0})'.format(filetype))
- return filetype
+ errno = 2
+ #fatal('unsupported file type({0})'.format(filetype))
+ return filetype, errno
def install(self, filename, homedir):
+ errno = 0
homedir = os.fsencode(homedir) # XXX
- tmpdir = self.extract_files(filename)
- filetype = self.get_file_type(tmpdir)
try:
- func = getattr(self, 'install_{0}'.format(filetype))
- target_dirs = func(filename, tmpdir, homedir)
+ tmpdir = self.extract_files(filename)
+ except:
+ errno = 1
+ if errno != 0:
+ return None, None, None, errno
+ try:
+ filetype, errno = self.get_file_type(tmpdir)
+ except:
+ errno = 4
+ filetype = None
+ if errno != 0:
+ shutil.rmtree(tmpdir)
+ return filetype, None, None, errno
+ func = getattr(self, 'install_{0}'.format(filetype))
+ try:
+ target_dirs, names, errno = func(filename, tmpdir, homedir)
+ except:
+ target_dirs = None
+ names = None
+ errno = 5
finally:
shutil.rmtree(tmpdir)
- return filetype, target_dirs
+ return filetype, target_dirs, names, errno
def download(self, url, basedir):
for path in self.list_all_files(ghost_src, b''):
filelist.append((os.path.join(ghost_src, path),
os.path.join(ghost_dst, path)))
+ ghost_name = inst.get('name')
# find shell
for path in self.list_all_files(shell_src, b''):
filelist.append((os.path.join(shell_src, path),
os.path.join(shell_dst, path)))
# find balloon
balloon_dir = inst and inst.get('balloon.directory')
+ balloon_name = None
if balloon_dir:
balloon_dir = ninix.home.get_normalized_path(balloon_dir)
balloon_dst = os.path.join(homedir, b'balloon', balloon_dir)
balloon_src = ninix.home.get_normalized_path(balloon_src)
else:
balloon_src = balloon_dir
+ inst_balloon = ninix.home.read_install_txt(
+ os.path.join(tmpdir, balloon_src))
if os.path.exists(balloon_dst) and \
not self. confirm_removal(balloon_dst, 'balloon'):
pass # don't install balloon
balloon_list.append((os.path.join(tmpdir, balloon_src, path),
os.path.join(balloon_dst, path)))
self.install_files(balloon_list)
+ balloon_name = inst_balloon.get('name')
if os.path.exists(prefix):
inst_dst = ninix.home.read_install_txt(prefix)
if inst.get_with_type('refresh', int, 0):
mask.append('HISTORY')
self.remove_files_and_dirs(prefix, mask)
else:
- return
+ return None, None, 3
else:
if not self.confirm_overwrite(prefix, 'ghost'):
- return
+ return None, None, 3
# install files
logging.info('installing {0} (ghost)'.format(archive))
self.install_files(filelist)
logging.error('cannot write {0}'.format(path))
if balloon_dir is None: # XXX
balloon_dir = ''
- return (os.fsdecode(target_dir), os.fsdecode(balloon_dir))
+ return (os.fsdecode(target_dir), os.fsdecode(balloon_dir)), \
+ (ghost_name, balloon_name), 0
def install_supplement(self, archive, tmpdir, homedir):
inst = ninix.home.read_install_txt(tmpdir)
candidates.append(dirname)
if not candidates:
logging.info('not found')
+ return None, None, 4
else:
target = self.select(candidates)
if target is None:
- return
+ return None, None, 4
path = os.path.join(homedir, b'ghost', target)
if 'directory' in inst:
if inst.get('type') == 'shell':
logging.error('supplement type not specified')
else:
logging.error('unsupported supplement type: {0}'.format(inst['type']))
- return
+ return None, None, 4
logging.info('found')
if not os.path.exists(path):
os.makedirs(path)
os.remove(os.path.join(tmpdir, b'install.txt'))
distutils.dir_util.copy_tree(os.fsdecode(tmpdir), os.fsdecode(path))
- return os.fsdecode(target)
+ return os.fsdecode(target), inst.get('name'), 0
def install_balloon(self, archive, srcdir, homedir):
# find install.txt
inst.get('refreshundeletemask', '').split(':')]
self.remove_files_and_dirs(dstdir, mask)
else:
- return
+ return None, None, 3
else:
if not self.confirm_overwrite(dstdir, 'balloon'):
- return
+ return None, None, 3
# install files
logging.info('installing {0} (balloon)'.format(archive))
self.install_files(filelist)
- return os.fsdecode(target_dir)
+ return os.fsdecode(target_dir), inst.get('name'), 0
def uninstall_plugin(self, homedir, name):
try:
# install files
print('installing {0} (plugin)'.format(archive))
self.install_files(filelist)
- return plugin_dir
+ return plugin_dir, plugin_name, 0
def uninstall_kinoko(self, homedir, name):
try:
# install files
logging.info('installing {0} (kinoko)'.format(archive))
self.install_files(filelist)
- return dstdir
+ return dstdir, (kinoko_name, kinoko['ghost'], kinoko['category']), 0
def uninstall_nekoninni(self, homedir, dir):
nekoninni_dir = os.path.join(homedir, b'nekodorif', b'skin', dir)
# install files
logging.info('installing {0} (nekodorif skin)'.format(archive))
self.install_files(filelist)
- return target_dir
+ return target_dir, inst.get('name'), 0
def uninstall_katochan(self, homedir, target_dir):
katochan_dir = os.path.join(
# install files
logging.info('installing {0} (nekodorif katochan)'.format(archive))
self.install_files(filelist)
- return target_dir
+ return target_dir, inst.get('name'), 0
def list_all_files(self, top, target_dir):
filelist = []
self.notify_preference_changed()
def do_install(self, filename):
+ self.communicate.notify_all('OnInstallBegin', [])
try:
- filetype, target_dirs = self.installer.install(
+ filetype, target_dirs, names, errno = self.installer.install(
filename, ninix.home.get_ninix_home())
except:
target_dirs = None
+ if errno != 0:
+ error_reason = {
+ 1: 'extraction',
+ 2: 'invalid type',
+ 3: 'artificial',
+ 4: 'unsupported',
+ }
+ self.communicate.notify_all('OnInstallFailure',
+ [error_reason.get(errno, 'unkown')])
+ # XXX: ninix-ayaでは発生しない.
+ ##self.communicate.notify_all('OnInstallRefuse', [])
+ else:
+ ##self.communicate.notify_all('OnInstallCompleteEx', []) # FIXME
+ if filetype != 'kinoko':
+ if filetype == 'ghost':
+ if target_dirs[1]:
+ id = 'ghost with balloon'
+ name2 = names[1]
+ else:
+ id = filetype
+ name2 = None
+ name = names[0]
+ else:
+ id = filetype
+ name2 = None
+ name = names
+ self.communicate.notify_all('OnInstallComplete',
+ [id, name, name2])
if target_dirs:
if filetype == 'ghost':
self.add_sakura(target_dirs[0])
self.katochan = ninix.home.search_katochan()
elif filetype == 'kinoko':
self.kinoko = ninix.home.search_kinoko()
+ self.communicate.notify_all('OnKinokoObjectInstalled', names)
def notify_installedghostname(self, key=None):
installed = []