Skip to content

Commit 06183d9

Browse files
committed
nothing
1 parent 1986e5a commit 06183d9

File tree

4 files changed

+50
-104
lines changed

4 files changed

+50
-104
lines changed

imagepy/menus/Plugins/Install/installplg_plgs.py

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from imagepy import root_dir
33
from sciapp.action import Free
4-
import os, subprocess, zipfile, shutil
5-
6-
import zipfile, sys, urllib
7-
path = 'https://github.com/Image-Py/imagepy/archive/main.zip'
8-
9-
from urllib.request import urlretrieve
10-
import urllib
11-
from io import BytesIO as StringIO
4+
import os, shutil, sys, subprocess
5+
from dulwich import porcelain
126

137
path_plgs = os.path.join(root_dir, 'plugins')
14-
path_cache = os.path.join(path_plgs, 'cache')
15-
if not os.path.exists(path_plgs):
16-
os.mkdir(path_plgs)
17-
if not os.path.exists(path_cache):
18-
os.mkdir(path_cache)
8+
if not os.path.exists(path_plgs): os.mkdir(path_plgs)
199

2010
def Schedule(a,b,c, plg):
2111
per = 100.0 * a * b / c
@@ -25,50 +15,16 @@ def Schedule(a,b,c, plg):
2515

2616
class Install(Free):
2717
title = 'Install Plugins'
28-
para = {'repo':'https://github.com/Image-Py/IBook', 'proxy': False, 'Protocol': 'https', 'IP': '127.0.0.1', 'Port': '1080'}
29-
view = [('lab', None, 'input a zipfile url or github url as http://github.com/username/project'),
30-
(str, 'repo', 'package', ''),
31-
(bool, 'proxy', 'Use proxy'),
32-
(list, 'Protocol', ['socks5', 'http', 'https'], str, 'Protocol', ''),
33-
(str, 'IP', 'IP Address', ''),
34-
(str, 'Port', 'Port', '')]
18+
para = {'repo':'https://github.com/Image-Py/IBook'}
19+
view = [('lab', None, 'input git url as http://github.com/username/project'),
20+
(str, 'repo', 'package', '')]
3521

3622
def run(self, para=None):
37-
url = para['repo']
38-
if 'github.com' in url:
39-
if url[-4:] == '.git':
40-
url = url.replace('.git', '/archive/main.zip')
41-
elif url[-4:] != '.zip':
42-
url = url + '/archive/main.zip'
43-
domain, name = url.split('/')[-4:-2]
44-
else:
45-
domain, name = (url[:-4].replace('.','-')).split('/')[-2:]
46-
domain, name = domain.replace('_', '-'), name.replace('_', '-')
47-
48-
self.app.info('downloading plugin from %s'%para['repo'])
49-
50-
if True == para['proxy']:
51-
proxy=para['Protocol']+"://"+para['IP']+":"+para['Port']
52-
print("proxy = ", proxy)
53-
# Build ProxyHandler object by given proxy
54-
proxy_support=urllib.request.ProxyHandler({para['Protocol']:proxy})
55-
# Build opener with ProxyHandler object
56-
opener = urllib.request.build_opener(proxy_support)
57-
# Install opener to request
58-
urllib.request.install_opener(opener)
59-
60-
urlretrieve(url, os.path.join(path_cache, domain+'_'+name+'.zip'),
61-
lambda a,b,c, p=self: Schedule(a,b,c,p))
62-
zipf = zipfile.ZipFile(os.path.join(path_cache, domain+'_'+name+'.zip'))
63-
folder = zipf.namelist()[0]
64-
zipf.extractall(path_cache)
65-
destpath = os.path.join(path_plgs, domain+'_'+folder.replace('-main',''))
66-
if os.path.exists(destpath): shutil.rmtree(destpath)
67-
os.rename(os.path.join(path_cache, folder), destpath)
68-
zipf.close()
23+
path = os.path.join(path_plgs, os.path.split(para['repo'])[-1])
24+
porcelain.clone(para['repo'], path, depth=1).close()
25+
shutil.rmtree(os.path.join(path, '.git'))
6926
self.app.info('installing requirement liberies')
70-
self.prgs = None
71-
cmds = [sys.executable, '-m', 'pip', 'install', '-r', '%s/requirements.txt'%destpath]
27+
cmds = [sys.executable, '-m', 'pip', 'install', '-r', '%s/requirements.txt'%path]
7228
subprocess.call(cmds)
7329
self.app.load_all()
7430

imagepy/menus/Plugins/update_plg.py

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,44 @@
11
from sciapp.action import Free
22
import os, sys, os.path as osp
3-
import zipfile, urllib
4-
from io import BytesIO
53
from imagepy import root_dir
4+
from dulwich import porcelain
65
import shutil
76

8-
if sys.version_info[0]==2:
9-
from urllib import urlretrieve
10-
else:
11-
from urllib.request import urlretrieve
12-
13-
def Schedule(a,b,c, plg):
14-
per = 100.0 * a * b / c
15-
if per > 100 : per = 100
16-
print('%-3d%%'%per)
17-
plg.prgs = (int(per), 100)
18-
197
class Update(Free):
208
title = 'Update Software'
219

2210
def run(self, para=None):
2311
self.app.info('update now, waiting...')
24-
self.download_zip()
25-
self.deal_file()
26-
#self.delete_cache()
27-
self.app.alert('imagepy update done!')
28-
29-
def download_zip(self):
30-
url='https://github.com/Image-Py/imagepy/archive/master.zip'
31-
path=osp.dirname(root_dir)
32-
zipname = osp.join(path, 'imagepy_cache.zip')
33-
print('downloading from %s'%url)
34-
urlretrieve(url, zipname,
35-
lambda a,b,c, p=self: Schedule(a,b,c,p))
36-
37-
def deal_file(self):
38-
path = osp.dirname(root_dir)
39-
#remove
12+
url = 'https://gitee.com/mirrors/imagepy'
13+
path = osp.dirname(root_dir); rpath = osp.dirname(path)
14+
newpath = osp.join(rpath, 'imagepy_new')
15+
if osp.exists(newpath): shutil.rmtree(newpath)
16+
porcelain.clone(url, os.path.join(rpath, 'imagepy_new'), depth=1).close()
17+
shutil.rmtree(os.path.join(os.path.join(rpath, 'imagepy_new'), '.git'))
18+
shutil.copytree(osp.join(path, 'imagepy/plugins'),
19+
osp.join(rpath, 'imagepy_new/imagepy/plugins'))
20+
shutil.copyfile(osp.join(path, 'imagepy/data/config.json'),
21+
osp.join(rpath, 'imagepy_new/imagepy/data/config.json'))
22+
shutil.copyfile(osp.join(path, 'imagepy/data/shortcut.json'),
23+
osp.join(rpath, 'imagepy_new/imagepy/data/shortcut.json'))
24+
newpath = os.path.join(rpath, 'imagepy_new')
25+
fs = os.listdir(os.path.join(rpath, 'imagepy_new'))
26+
fs = [i for i in fs if osp.isdir(osp.join(newpath, i))]
27+
fs = [i for i in fs if osp.exists(osp.join(path, i))]
28+
for i in [j for j in fs if j!='imagepy']: shutil.rmtree(osp.join(path, i))
29+
for i in [j for j in fs if j!='imagepy']:
30+
shutil.copytree(osp.join(newpath, i), osp.join(path, i))
4031
for i in os.listdir(root_dir):
41-
if i in ['plugins', 'ilastik', 'preference.cfg', '.gitignore']: continue
42-
if osp.isdir(osp.join(root_dir,i)): shutil.rmtree(osp.join(root_dir, i))
32+
if osp.isdir(osp.join(root_dir,i)):
33+
shutil.rmtree(osp.join(root_dir, i))
4334
else : os.remove(osp.join(root_dir,i))
44-
45-
source = zipfile.ZipFile(osp.join(path, 'imagepy_cache.zip'), 'r')
46-
target = zipfile.ZipFile(BytesIO(), 'w')
47-
for i in source.namelist()[1:]: target.writestr(i[15:], source.read(i))
48-
target.extractall(path)
49-
target.close()
50-
source.close()
51-
os.remove(osp.join(path,'imagepy_cache.zip'))
35+
newdir = os.path.join(newpath, 'imagepy')
36+
for i in os.listdir(newdir):
37+
if osp.isdir(osp.join(newdir, i)):
38+
shutil.copytree(osp.join(newdir, i), osp.join(root_dir, i))
39+
else: shutil.copyfile(osp.join(newdir, i), osp.join(root_dir, i))
40+
shutil.rmtree(newpath)
41+
self.app.alert('imagepy update done!')
5242

5343
class Refresh(Free):
5444
title = 'Reload Plugins'

imagepy/menus/Process/Classify/classify_wgt.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__( self, parent, app=None):
5353
self.Layout()
5454

5555
def LoadModel(self):
56-
fs = glob(osp.join(root_dir, 'data/ilastik/*.fcl'))
56+
fs = glob(osp.join(root_dir, 'plugins/ilastik/*.fcl'))
5757
self.models = [osp.split(i)[1] for i in fs]
5858
self.lst_model.SetItems(self.models)
5959

@@ -71,9 +71,9 @@ def on_save(self, event):
7171
return self.app.alert('you must train your model first!')
7272
para = {'name':'New Model'}
7373
if not self.app.show_para('name', para, [(str, 'name', 'model', 'name')]): return
74-
if not osp.exists(osp.join(root_dir, 'data/ilastik')):
75-
os.mkdir(osp.join(root_dir, 'data/ilastik'))
76-
joblib.dump( manager.model_para, osp.join(root_dir, 'data/ilastik/%s.fcl'%para['name']))
74+
if not osp.exists(osp.join(root_dir, 'plugins/ilastik')):
75+
os.mkdir(osp.join(root_dir, 'plugins/ilastik'))
76+
joblib.dump( manager.model_para, osp.join(root_dir, 'plugins/ilastik/%s.fcl'%para['name']))
7777
self.LoadModel()
7878

7979
def on_saveas(self, event):
@@ -91,7 +91,7 @@ def on_export(self, event):
9191
para = {'path':'', 'name':''}
9292
filt = ['fcl']
9393
para['path'] = self.app.get_path('Save..', filt, 'save', para['name'])
94-
oldname = osp.join(root_dir, 'data/ilastik/%s'%self.lst_model.GetStringSelection())
94+
oldname = osp.join(root_dir, 'plugins/ilastik/%s'%self.lst_model.GetStringSelection())
9595
print(para['path'])
9696
shutil.copyfile(oldname, para['path'])
9797
self.LoadModel()
@@ -101,14 +101,14 @@ def on_rename(self, event):
101101
if idx==-1: return self.app.alert('no model selected!')
102102
para = {'name':'New Model'}
103103
if not self.app.show_para('name', para, [(str, 'name', 'model', 'name')]): return
104-
oldname = osp.join(root_dir, 'data/ilastik/%s'%self.lst_model.GetStringSelection())
105-
os.rename(oldname, osp.join(root_dir, 'data/ilastik/%s.fcl'%para['name']))
104+
oldname = osp.join(root_dir, 'plugins/ilastik/%s'%self.lst_model.GetStringSelection())
105+
os.rename(oldname, osp.join(root_dir, 'plugins/ilastik/%s.fcl'%para['name']))
106106
self.LoadModel()
107107

108108
def on_remove(self, event):
109109
idx = self.lst_model.GetSelection()
110110
if idx==-1: return self.app.alert('no model selected!')
111-
os.remove(osp.join(root_dir, 'data/ilastik/%s'%self.lst_model.GetStringSelection()))
111+
os.remove(osp.join(root_dir, 'plugins/ilastik/%s'%self.lst_model.GetStringSelection()))
112112
self.LoadModel()
113113

114114
def on_run(self, event):

sciapp/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def __init__(self, asyn=True):
66
self.asyn = asyn
77
self.managers = {}
88
self.img_manager = self.manager('img')
9-
#self.wimg_manager = self.manager('wimg')
9+
self.wimg_manager = self.manager('wimg')
1010
self.tab_manager = self.manager('tab')
11-
#self.wtab_manager = self.manager('wtab')
11+
self.wtab_manager = self.manager('wtab')
1212
self.mesh_manager = self.manager('mesh')
13-
#self.wmesh_manager = self.manager('wmesh')
13+
self.wmesh_manager = self.manager('wmesh')
1414
self.task_manager = self.manager('task')
1515

1616
self.plugin_manager = self.manager('plugin')

0 commit comments

Comments
 (0)