Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import os
- import pygtk
- pygtk.require('2.0')
- import gtk
- import gtk.glade
- import time
- import traceback
- home = os.environ['HOME']
- __version__ = "2.0.1.0"
- help_message = """
- Rockdome is gtk frontend for aria2c designed for linux users
- Version = %s
- Usage:
- rd <options><arguments>
- where otions include:
- Rockdome options:
- <no options> run Rockdome if not run.
- --alive Is rockdome running or not ??
- --id print the id of the running Rockdome instance. or None
- --disable-clipboard disable clipboard integration
- --quit Quit the running Rockdome instance.
- -h
- --help print this message "How to run rockdome??".
- If you want document about "How to use Rockdome??":
- 1. Search in menu >> help >> content (Will be available soon).
- 2. Try to press "Help" button in each window. (Will be available soon).
- 3. Read tips.
- --url Url to be added to Rockdome,
- Values : valid web link or existed torrent, meta or input file
- -v
- --version print version.
- --opt exclussively run Rockdome from /opt/rockdome/ path
- --bf run rockdome from custom installation path
- """%__version__
- def get_args():
- try:
- args = sys.argv[1:]
- for i in args:
- if i == "":
- continue
- except:
- args = []
- return args
- def get_dict_args(list_):
- dict_ ={}
- for arg in list_:
- if "=" in arg:
- k,v = arg.split("=",1)
- dict_[k] = v
- else:
- dict_[arg] = ""
- return dict_
- class rd():
- def __init__(self, args):
- self.args = get_dict_args(args)
- def run(self):
- run = self.getstate()
- print "is rockdome running?? " , run
- if run == False :
- self.initiate()
- print "rd finish is work"
- os._exit(0)
- def get_id(self):
- p = ''
- try :
- with open('%s/.aria2/pid'%home) as r:
- p = r.readline().strip()
- if p == "":
- return False
- else:
- return p
- except :
- return False
- def getstate(self):
- p = self.get_id()
- if not p :
- return False
- p = os.path.join("/" , "proc" , p )
- if os.path.exists(p):
- return True
- else :
- return False
- def get_executeble_path(self):
- opt_path = None
- bf_path = None
- if os.path.exists("/opt/rockdome/bin/mainwin.py") :
- opt_path = "/opt/rockdome"
- try:
- r = open('%s/.aria2/.bf'%home)
- bf_path = r.read().strip()
- r.close()
- except Exception as e:
- if e[0] == 2:
- bf_path = None
- if bf_path == "/opt/rockdome":
- return bf_path
- if not bf_path and opt_path:
- return opt_path
- if not opt_path and bf_path:
- return bf_path
- if opt_path and bf_path and "--opt" in self.args:
- return opt_path
- if opt_path and bf_path and "--bf" in self.args:
- if opt_path == bf_path :
- x = raw_input("Write the executeble path >> \n")
- return x
- else:
- return bf_path
- if not bf_path and not opt_path :
- return
- return opt_path
- def initiate(self):
- rock_path = self.get_executeble_path()
- if not rock_path:
- print "can't found valid executeble path"
- print "use the --bf option or edit the $HOME/.aria2/.bf file"
- return
- sys.path.append(os.path.join(rock_path,"bin"))
- os.chdir(os.path.join(rock_path,"bin"))
- try:
- import mainwin
- except ImportError :
- print traceback.format_exc()
- print "ImportError: \n\
- Possibilities:\n\
- 1.corrupted installation,\n\
- 2.missed dependency\n\
- 3.fatal bug\n\
- \n\
- action : exit\
- "
- return
- m = mainwin.main_()
- m.main()
- def send_cmd(self, cmd):
- wfPath = os.path.join(home , ".aria2" , ".p" )
- wp = open(wfPath, 'a')
- wp.write(cmd)
- wp.write("\n")
- wp.close()
- if __name__ == '__main__':
- args = get_args()
- rd = rd(args=args)
- if args == ["--help"] or args == ["-h"]:
- print help_message
- os._exit(0)
- if args == ["-v"] or args == ["--version"]:
- print __version__
- os._exit(0)
- if "--alive" in args :
- print rd.getstate()
- os._exit(0)
- if "--id" in args :
- print rd.get_id()
- os._exit(0)
- elif args == ["--disable-clipboard"]:
- rd.send_cmd("--disable-clipboard")
- os._exit(0)
- elif args == ["--quit"]:
- rd.send_cmd(args)
- os._exit(0)
- #dict_ = get_dict_args(args)
- if len(args) == 0:
- rd.run()
- elif len(args) == 1:
- rd.send_cmd(args[0])
- rd.run()
- else:
- for i in args :
- if i.startswith("--url") or i.startswith("url"):
- x = 0
- break
- else :
- x =1
- if x == 1 :
- url = "url="
- for i in args:
- url = url+i
- rd.send_cmd(realargs)
- rd.run()
- elif x == 0:
- realargs = ""
- j = " "
- for i in args :
- i = j+i
- realargs += i
- rd.send_cmd(realargs)
- rd.run()
- os._exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement