Split some code into a utils.py module.
This commit is contained in:
parent
4fb9e1e003
commit
a84966cf9b
|
|
@ -14,32 +14,13 @@ from dulwich.errors import NotGitRepository
|
|||
from dulwich.repo import Repo
|
||||
|
||||
from joy.gui.textwidget import TextViewerWidget, tk, get_font, TEXT_BINDINGS
|
||||
from joy.gui.utils import init_home, FileFaker
|
||||
from joy.gui.world import World
|
||||
from joy.library import initialize
|
||||
from joy.utils.stack import stack_to_string
|
||||
|
||||
|
||||
JOY_HOME = os.environ.get('JOY_HOME')
|
||||
if JOY_HOME is None:
|
||||
JOY_HOME = os.path.expanduser('~/.joypy')
|
||||
if not os.path.isabs(JOY_HOME):
|
||||
JOY_HOME = os.path.abspath('./JOY_HOME')
|
||||
#print 'JOY_HOME=' + JOY_HOME
|
||||
|
||||
if not os.path.exists(JOY_HOME):
|
||||
#print 'creating...'
|
||||
os.makedirs(JOY_HOME, 0700)
|
||||
#print 'initializing git repository...'
|
||||
repo = Repo.init(JOY_HOME)
|
||||
|
||||
else: # path does exist
|
||||
try:
|
||||
repo = Repo(JOY_HOME)
|
||||
except NotGitRepository:
|
||||
#print 'initializing git repository...'
|
||||
repo = Repo.init(JOY_HOME)
|
||||
#else:
|
||||
#print 'opened git repository.'
|
||||
JOY_HOME, repo = init_home()
|
||||
|
||||
|
||||
def repo_relative_path(path):
|
||||
|
|
@ -229,19 +210,6 @@ for event, command in GLOBAL_COMMANDS.items():
|
|||
t.bind_all(event, lambda _, _command=command: w.interpret(_command))
|
||||
|
||||
|
||||
class FileFaker(object):
|
||||
|
||||
def __init__(self, T):
|
||||
self.T = T
|
||||
|
||||
def write(self, text):
|
||||
self.T.insert('end', text)
|
||||
self.T.see('end')
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
sys.stdout, old_stdout = FileFaker(log), sys.stdout
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
import os
|
||||
|
||||
from dulwich.errors import NotGitRepository
|
||||
from dulwich.repo import Repo
|
||||
|
||||
|
||||
def init_home():
|
||||
'''
|
||||
Find and initialize the Joy home directory and repository.
|
||||
'''
|
||||
JOY_HOME = os.environ.get('JOY_HOME')
|
||||
if JOY_HOME is None:
|
||||
JOY_HOME = os.path.expanduser('~/.joypy')
|
||||
if not os.path.isabs(JOY_HOME):
|
||||
JOY_HOME = os.path.abspath('./JOY_HOME')
|
||||
#print 'JOY_HOME=' + JOY_HOME
|
||||
|
||||
if not os.path.exists(JOY_HOME):
|
||||
#print 'creating...'
|
||||
os.makedirs(JOY_HOME, 0700)
|
||||
#print 'initializing git repository...'
|
||||
repo = Repo.init(JOY_HOME)
|
||||
|
||||
else: # path does exist
|
||||
try:
|
||||
repo = Repo(JOY_HOME)
|
||||
except NotGitRepository:
|
||||
#print 'initializing git repository...'
|
||||
repo = Repo.init(JOY_HOME)
|
||||
#else:
|
||||
#print 'opened git repository.'
|
||||
return JOY_HOME, repo
|
||||
|
||||
|
||||
class FileFaker(object):
|
||||
|
||||
def __init__(self, T):
|
||||
self.T = T
|
||||
|
||||
def write(self, text):
|
||||
self.T.insert('end', text)
|
||||
self.T.see('end')
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
Loading…
Reference in New Issue