Skip to content

Commit

Permalink
ignore hidden files, ignore data dir, dont close on startup error, cr…
Browse files Browse the repository at this point in the history
…eate necessary files and dirs on first start, start function to main.py, bad file solved log to info
  • Loading branch information
shortcutme committed Jan 12, 2015
1 parent e141a77 commit effa267
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ __pycache__/
*.py[cod]

# Log files
*.log
*.log

# Hidden files
.*
!/.gitignore


# Data dir
data/*
2 changes: 0 additions & 2 deletions data/sites.json

This file was deleted.

1 change: 0 additions & 1 deletion log/empty.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/Site/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def fileStarted(self):
def fileDone(self, inner_path):
# File downloaded, remove it from bad files
if inner_path in self.bad_files:
self.log.debug("Bad file solved: %s" % inner_path)
self.log.info("Bad file solved: %s" % inner_path)
del(self.bad_files[inner_path])

# Update content.json last downlad time
Expand Down
12 changes: 12 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os, sys
sys.path.append(os.path.dirname(__file__)) # Imports relative to main.py

# Create necessary files and dirs
if not os.path.isdir("log"): os.mkdir("log")
if not os.path.isdir("data"): os.mkdir("data")
if not os.path.isfile("data/sites.json"): open("data/sites.json", "w").write("{}")

# Load config
from Config import config

Expand Down Expand Up @@ -34,6 +39,13 @@

logging.debug("Starting... %s" % config)

# Starts here when running zeronet.py
def start():
action_func = globals()[config.action] # Function reference
action_kwargs = config.getActionArguments() # non-config arguments when calling zeronet.py

action_func(**action_kwargs)


# Start serving UiServer and PeerServer
def main():
Expand Down
14 changes: 8 additions & 6 deletions zeronet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from src import main

action_func = getattr(main, main.config.action)
action_kwargs = main.config.getActionArguments()

action_func(**action_kwargs)
#!/usr/bin/env python

try:
from src import main
main.start()
except Exception, err: # Prevent closing
import traceback
traceback.print_exc()
raw_input("-- Error happend, press enter to close --")

0 comments on commit effa267

Please sign in to comment.