stov.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. #! /usr/bin/env python
  2. # -*- coding: utf8 -*-
  3. #stov - a program to subscribe to channels and users from youtube
  4. # and download the videos automatically
  5. #
  6. # written by Helmut Pozimski 2012-2013
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; version 2
  11. # of the License.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. # Boston, MA 02110-1301, USA.
  22. from __future__ import unicode_literals
  23. import sys
  24. import gettext
  25. import os
  26. import sqlite3
  27. import email
  28. import smtplib
  29. import subprocess
  30. import signal
  31. from email.mime.multipart import MIMEMultipart
  32. from email.mime.text import MIMEText
  33. from optparse import OptionParser
  34. import subscription
  35. import youtube
  36. import configuration
  37. from outputhelper import printf
  38. """Determine the path where the stov files are for localization"""
  39. locale_path = sys.path[0] + "/locale"
  40. """Initialize gettext to support translation of the program"""
  41. try:
  42. trans = gettext.translation("stov", locale_path)
  43. except IOError:
  44. gettext.install("stov")
  45. printf(_("Translation files could not be found, localization "
  46. "won't be available"), outputlevel="default",
  47. descriptor="stderr")
  48. else:
  49. if sys.version_info >= (3, 0):
  50. trans.install()
  51. else:
  52. trans.install(unicode=True)
  53. """Define a handler for signals sent to the program"""
  54. def sighandler(signum, frame):
  55. if signum == 2:
  56. printf(_("STRG+C has been pressed, quitting..."),
  57. outputlevel="default", descriptor="stderr")
  58. elif signum == 15:
  59. printf(_("Received SIGTERM, quitting..."),
  60. outputlevel="default", descriptor="stderr")
  61. os.killpg(os.getpid(), 1)
  62. os.remove("/tmp/stov.lock")
  63. sys.exit(0)
  64. signal.signal(signal.SIGTERM, sighandler)
  65. signal.signal(signal.SIGINT, sighandler)
  66. """Overwrite the default OptionParser class so error messages
  67. can be localized
  68. """
  69. class MyOptionParser(OptionParser):
  70. def error(self, msg):
  71. if "invalid integer" in msg:
  72. printf(_("option %s requires an integer value")
  73. % msg.split()[1],
  74. outputlevel="default", descriptor="stderr")
  75. self.exit()
  76. elif "an argument" in msg:
  77. printf(_("option %s requires an argument") % msg.split()[0],
  78. outputlevel="default", descriptor="stderr")
  79. self.exit()
  80. elif "no such" in msg:
  81. printf(_("invalid option %s") % msg.split()[3],
  82. outputlevel="default", descriptor="stderr")
  83. self.exit()
  84. else:
  85. printf(msg, outputlevel="default", descriptor="stderr")
  86. self.exit()
  87. """Process the given options and parameters,
  88. add: Add a new subscription (which can be a search, channel or playlist)
  89. channel: with add, specify the name of the channel or user
  90. lssubs: List the currently available subscriptions
  91. remove: remove a subscription
  92. update: update the information about the available videos
  93. download: download all available videos which haven't already been downloaded
  94. search: optionally add a search string to a new subscription or create a
  95. search subscription with add
  96. playlist: with add, subscribe to a youtube playlist
  97. catchup: Mark all videos in a subscription as downloaded
  98. version: Print version number
  99. quiet: Suppress all output
  100. verbose: Print normal output + diagnostical messages
  101. clean-database: Clean the database of old entries, meaning videos that
  102. are no longer present in the current API response of youtube
  103. """
  104. parser = MyOptionParser(usage=_("Usage: %prog [options]"), prog="stov",
  105. add_help_option=True, conflict_handler="resolve")
  106. parser.add_option("-h", "--help", action="store_true", dest="help",
  107. help=_("show this help message and exit"))
  108. parser.add_option("-a", "--add", dest="add", action="store_true",
  109. help=_("Add a new subscription (requires either --search, \
  110. --channel or --playlist)"))
  111. parser.add_option("-p", "--playlist", dest="playlist",
  112. help=_("Add a new Playlist subscription (requires add)"))
  113. parser.add_option("-l", "--lssubs", action="store_true", dest="list",
  114. help=_("List the currently available subscriptions"))
  115. parser.add_option("-r", "--remove", type="int", dest="deleteid",
  116. help=_("remove a subscription"))
  117. parser.add_option("-u", "--update", action="store_true", dest="update",
  118. help=_("update the information about the available videos"))
  119. parser.add_option("-d", "--download", action="store_true", dest="download",
  120. help=_("download all available videos which haven't already been downloaded"))
  121. parser.add_option("-s", "--search", dest="searchparameter",
  122. help=_("optionally add a search string to a new channel subscription or \
  123. create a new search subscription (requires --add)"))
  124. parser.add_option("-l", "--lsvids", type="int", dest="subscriptionid",
  125. help=_("Print all videos from a subscription"))
  126. parser.add_option("-c", "--catchup", dest="catchup",
  127. help=_("Mark all videos from one channel as read \
  128. (requires subscription-id as argument)"))
  129. parser.add_option("-c", "--channel", dest="channel",
  130. help=_("specify a channel for a new subscription (requires --add)"))
  131. parser.add_option("-l", "--license", dest="license", action="store_true",
  132. help=_("show the license of the program"))
  133. parser.add_option("-v", "--version", dest="version", action="store_true",
  134. help=_("show the current running version number"))
  135. parser.add_option("-q", "--quiet", dest="quiet", action="store_true",
  136. help=_("Suppress all output"))
  137. parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
  138. help=_("Be verbose and print also diagnostical messages"))
  139. parser.add_option("-c", "--clean-database", dest="cleanup",
  140. action="store_true", help=_("Clean the database of entries no longer listed "
  141. "in the current API response"))
  142. (options, arguments) = parser.parse_args()
  143. """Check if stov is run directly from command line since it shouldn't be
  144. loaded as a module
  145. """
  146. if __name__ != "__main__":
  147. print >> sys.stderr, """This file should not be imported as a module
  148. please run it directly from command line"""
  149. sys.exit(1)
  150. """Variable to determine if the exit code should be success or not"""
  151. exit_status = True
  152. """Check which outputlevel is defined and save it to a temporary variable
  153. accordingly. Output generated before this will be printed to stdout regardless
  154. of the user defined setting
  155. """
  156. if options.verbose is True and options.quiet is True:
  157. printf(_("--quiet and --verbose can't be defined at the same time, "
  158. "exiting."), outputlevel="default")
  159. sys.exit(1)
  160. elif options.verbose is True:
  161. outputlevel = "verbose"
  162. elif options.quiet is True:
  163. outputlevel = "quiet"
  164. else:
  165. outputlevel = "default"
  166. """Create the lock file which is used to determine if another instance is
  167. already running by chance, the program shouldn't be run in this case since
  168. we want to prevent concurent access to the database.
  169. """
  170. if os.access("/tmp/stov.lock", os.F_OK):
  171. try:
  172. lockfile = open("/tmp/stov.lock", "r")
  173. except IOError:
  174. printf(_("Lock file could not be opened, please check that "
  175. "it exists and is readable, quitting now"),
  176. outputlevel="default", level=outputlevel, descriptor="stderr")
  177. sys.exit(1)
  178. oldpid = lockfile.read().strip()
  179. if os.access("/proc/" + oldpid, os.F_OK):
  180. printf(_("The lock file already exists, probably another"
  181. "instance of this program is already running\n"
  182. "if you are sure this is not the case, delete it"
  183. " manually and try again!"),
  184. outputlevel="default", level=outputlevel, descriptor="stderr")
  185. sys.exit(1)
  186. lockfile.close()
  187. if os.access("/proc/" + oldpid, os.F_OK) is not True:
  188. try:
  189. os.remove("/tmp/stov.lock")
  190. except os.error:
  191. printf(_("Old lock file could not be deleted!"),
  192. outputlevel="default", level=outputlevel, descriptor="stderr")
  193. try:
  194. lockfile = open("/tmp/stov.lock", "w")
  195. lockfile.write(str(os.getpid()))
  196. lockfile.close()
  197. except IOError:
  198. printf(_("Lock file could not be created, please check that /tmp is "
  199. "writable and properly configured, quitting now"),
  200. outputlevel="default", level=outputlevel, descriptor="stderr")
  201. sys.exit(1)
  202. """Check if the configuration directory exists and is writeable. If it \
  203. doesnt, create it using the configuration class.
  204. """
  205. if os.access(os.environ['HOME'] + "/.stov", os.F_OK & os.W_OK) is not True:
  206. printf(_("This seems to be the first time you run the programm, do you"
  207. " want to run the interactive assistant? (yes/no)"),
  208. outputlevel="default", level=outputlevel, descriptor="stdout")
  209. conf = configuration.conf()
  210. temp_input = raw_input()
  211. if temp_input == "yes":
  212. conf.assist()
  213. else:
  214. printf(_("Writing initial configuration according to default values"),
  215. outputlevel="default", level=outputlevel, descriptor="stdout")
  216. conf.Initialize()
  217. else:
  218. conf = configuration.conf()
  219. if conf.CheckConfig() is not True:
  220. printf(_("Your configuration needs to be updated, performing"
  221. " update now."), outputlevel="default", level=outputlevel,
  222. descriptor="stdout")
  223. conf.UpdateConfig()
  224. if conf.CheckDB() is not True:
  225. printf(_("Your database needs to be updated, performing"
  226. " update now."), outputlevel="default", level=outputlevel,
  227. descriptor="stdout")
  228. conf.UpdateDB()
  229. conf.ReadConfig()
  230. """Check which outputlevel is defined and update the configuration object
  231. accordingly.
  232. """
  233. conf.outputlevel = outputlevel
  234. """youtube-dl is really a dependency but the program will run with limited\
  235. functionality without it so we need to check that here
  236. """
  237. if conf.values["youtube-dl"] == "":
  238. conf.values["youtube-dl"] = subprocess.Popen(["which", "youtube-dl"],
  239. stdout=subprocess.PIPE).communicate()[0].strip()
  240. if os.access(conf.values["youtube-dl"], os.F_OK & os.R_OK & os.X_OK):
  241. printf(_("Found youtube-dl, writing to configuration file."),
  242. outputlevel="default", level=conf.outputlevel, descriptor="stdout")
  243. conf.WriteConfig()
  244. else:
  245. printf(_("Could not find youtube-dl, it either does not exist, "
  246. "is not readable or not executable. Please note that "
  247. "youtube-dl is not needed for the program to run but is"
  248. " needed to use the download option which won't work otherwise."
  249. " If youtube-dl isn't found automatically, you may also enter "
  250. "the path to it in the configuration file."),
  251. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  252. """Variable to save the text that is later sent as e-mail"""
  253. mailcontent = []
  254. """Check which options are given on the command line and
  255. run the corresponding code
  256. """
  257. if options.add is True:
  258. AddSub = True
  259. if options.channel is not None and options.searchparameter is None:
  260. NewSubscription = subscription.sub(type="channel",
  261. name=options.channel, conf=conf)
  262. elif options.channel is not None and options.searchparameter is not None:
  263. NewSubscription = subscription.sub(type="channel",
  264. name=options.channel, search=options.searchparameter, conf=conf)
  265. elif options.channel is None and options.searchparameter is not None:
  266. NewSubscription = subscription.sub(type="search",
  267. name=_("Search_"), search=options.searchparameter, conf=conf)
  268. elif options.playlist is not None:
  269. if options.searchparameter is not None:
  270. printf(_("Playlists do not support searching, search option will "
  271. "be ignored!"), outputlevel="default", level=conf.outputlevel,
  272. descriptor="stderr")
  273. NewSubscription = subscription.sub(type="playlist",
  274. name=options.playlist, conf=conf)
  275. else:
  276. printf(_("No valid subscription options given, "
  277. "subscription could not be added"),
  278. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  279. AddSub = False
  280. if AddSub is True:
  281. NewSubscription.AddSub()
  282. NewSubscription.UpdateVideos()
  283. printf(_("New subscription ") + NewSubscription.GetTitle()
  284. + _(" successfully added"), outputlevel="default", level=conf.outputlevel,
  285. descriptor="stdout")
  286. elif options.list is True:
  287. try:
  288. database = sqlite3.connect(conf.dbpath)
  289. cursor = database.cursor()
  290. except sqlite3.OperationalError:
  291. printf(_("Could not access the database, please check path "
  292. "and permissions and try again!"), outputlevel="default",
  293. level=conf.outputlevel, descriptor="stderr")
  294. else:
  295. cursor.execute("SELECT id, title FROM subscriptions")
  296. Listofsubscriptions = cursor.fetchall()
  297. if len(Listofsubscriptions) != 0:
  298. printf(_("ID Title"), outputlevel="default", level=conf.outputlevel,
  299. descriptor="stdout")
  300. for subscription in Listofsubscriptions:
  301. if subscription[0] is not None:
  302. printf(str(subscription[0]) + " " + subscription[1],
  303. outputlevel="default", level=conf.outputlevel, descriptor="stdout")
  304. else:
  305. printf(_("No subscriptions added yet, add one!"), outputlevel="default",
  306. level=conf.outputlevel, descriptor="stdout")
  307. database.close()
  308. elif options.deleteid is not None:
  309. try:
  310. DeleteId = int(options.deleteid)
  311. Subscription = subscription.sub(type="", name="delete",
  312. id=DeleteId, conf=conf)
  313. except ValueError:
  314. printf(_("Invalid Option, please use the ID of the subscription"
  315. "you want to delete as parameter for the remove option"),
  316. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  317. exit_status = Subscription.Delete()
  318. elif options.update is True:
  319. listofsubscriptions = []
  320. try:
  321. database = sqlite3.connect(conf.dbpath)
  322. cursor = database.cursor()
  323. except sqlite3.OperationalError:
  324. printf(_("Could not access the database, please check path and "
  325. "permissions and try again!"), outputlevel="default",
  326. level=conf.outputlevel, descriptor="stderr")
  327. else:
  328. cursor.execute("SELECT id,title,type,name,searchstring,directory \
  329. FROM subscriptions")
  330. subscriptions = cursor.fetchall()
  331. database.close()
  332. for element in subscriptions:
  333. listofsubscriptions.append(subscription.sub(id=element[0],
  334. title=element[1], type=element[2], name=element[3],
  335. search=element[4], directory=element[5], conf=conf))
  336. for element in listofsubscriptions:
  337. element.UpdateVideos()
  338. elif options.download is True:
  339. listofsubscriptions = []
  340. try:
  341. database = sqlite3.connect(conf.dbpath)
  342. cursor = database.cursor()
  343. except sqlite3.OperationalError:
  344. printf(_("Could not access the database, please check path"
  345. "and permissions and try again!"), outputlevel="default",
  346. level=conf.outputlevel, descriptor="stderr")
  347. else:
  348. cursor.execute("SELECT id,title,type,name,searchstring,directory \
  349. FROM subscriptions")
  350. subscriptions = cursor.fetchall()
  351. itag_value = conf.GetYoutubeParameter()
  352. if itag_value == 0:
  353. printf(_("Codec and resolution could not be determined, using maximum "
  354. "possible value"), outputlevel="verbose",
  355. level=conf.outputlevel, descriptor="stderr")
  356. itag_value = 38
  357. for element in subscriptions:
  358. listofsubscriptions.append(subscription.sub(id=element[0],
  359. title=element[1], type=element[2], name=element[3],
  360. search=element[4], directory=element[5], conf=conf))
  361. videosdownloaded = 0
  362. videosfailed = 0
  363. for element in listofsubscriptions:
  364. element.GetVideos()
  365. element.DownloadVideos(itag_value)
  366. for entry in element.DownloadedVideos:
  367. mailcontent.append(entry)
  368. videosdownloaded = len(mailcontent)
  369. videosfailed = videosfailed + element.FailedVideos
  370. if videosdownloaded > 0 and conf.values["notify"] == "yes":
  371. MailText = ""
  372. msg = MIMEMultipart()
  373. if videosdownloaded == 1:
  374. msg["Subject"] = _("Downloaded %i new video") % videosdownloaded
  375. MailText = _("The following episode has been downloaded by stov: \n\n")
  376. else:
  377. msg["Subject"] = _("Downloaded %i new videos") % videosdownloaded
  378. MailText = _("The following episodes have been downloaded by stov: \n\n")
  379. msg["From"] = "stov <%s>" % conf.values["mailfrom"]
  380. msg["To"] = "<%s>" % conf.values["mailto"]
  381. for line in mailcontent:
  382. MailText += line + "\n"
  383. msgtext = MIMEText(MailText.encode("utf8"), _charset="utf8")
  384. msg.attach(msgtext)
  385. serverconnection = smtplib.SMTP()
  386. try:
  387. if sys.version_info >= (3, 0):
  388. serverconnection.connect(conf.values["mailhost"], conf.values["smtpport"])
  389. else:
  390. serverconnection.connect(str(conf.values["mailhost"]),
  391. str(conf.values["smtpport"]))
  392. except smtplib.SMTPConnectError:
  393. printf(sys.stderr, _("Could not connect to the smtp server, please"
  394. " check your settings!"), outputlevel="default",
  395. level=conf.outputlevel, descriptor="stderr")
  396. try:
  397. serverconnection.starttls()
  398. except smtplib.SMTPException:
  399. printf(_("TLS not available, proceeding unencrypted"),
  400. outputlevel="default", level=conf.outputlevel, descriptor="stdout")
  401. if conf.values["auth_needed"] == "yes":
  402. try:
  403. serverconnection.login(conf.values["user_name"], conf.values["password"])
  404. except smtplib.SMTPAuthenticationError:
  405. printf(_("Authentication failed, please check user name"
  406. "and password!"), outputlevel="default", level=conf.outputlevel,
  407. descriptor="stderr")
  408. except smtplib.SMTPException:
  409. printf(_("Could not authenticate, server probably does not"
  410. " support authentication!"), outputlevel="default",
  411. level=conf.outputlevel, descriptor="stderr")
  412. try:
  413. serverconnection.sendmail(conf.values["mailfrom"], conf.values["mailto"],
  414. msg.as_string())
  415. except smtplib.SMTPRecipientsRefused:
  416. printf(_("The server refused the recipient address, "
  417. "please check your settings"),
  418. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  419. except smtplib.SMTPSenderRefused:
  420. printf(_("The server refused the sender address, "
  421. "please check your settings"), outputlevel="default",
  422. level=conf.outputlevel, descriptor="stderr")
  423. serverconnection.quit()
  424. elif videosdownloaded == 0 and videosfailed == 0:
  425. if conf.values["notify"] == "no":
  426. printf(_("No videos to be downloaded."), outputlevel="default",
  427. level=conf.outputlevel, descriptor="stdout")
  428. elif conf.values["notify"] == "no":
  429. if videosfailed == 0:
  430. printf(_("The following videos have been downloaded:\n"),
  431. outputlevel="default", level=conf.outputlevel, descriptor="stdout")
  432. for i in mailcontent:
  433. printf(i, outputlevel="default", level=conf.outputlevel,
  434. descriptor="stdout")
  435. else:
  436. printf(_("Could not determine how you want to be informed "
  437. "about new videos, please check the notify parameter "
  438. "in your configuration"), outputlevel="default",
  439. level=conf.outputlevel, descriptor="stderr")
  440. elif options.subscriptionid is not None:
  441. try:
  442. database = sqlite3.connect(conf.dbpath)
  443. cursor = database.cursor()
  444. except sqlite3.OperationalError:
  445. printf(_("Could not access the database, please check"
  446. "path and permissions and try again!"),
  447. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  448. else:
  449. subscription_video_select = "SELECT id,title,type,name,searchstring,\
  450. directory FROM subscriptions where id=?"
  451. cursor.execute(subscription_video_select, (options.subscriptionid,))
  452. Data = cursor.fetchall()
  453. if Data != []:
  454. Subscription = subscription.sub(id=Data[0][0], title=Data[0][1],
  455. type=Data[0][2], name=Data[0][3], search=Data[0][4],
  456. directory=Data[0][5], conf=conf)
  457. Subscription.GetVideos()
  458. Subscription.PrintVideos()
  459. else:
  460. printf(_("Invalid subscription, please check the list and try again"),
  461. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  462. elif options.catchup is not None:
  463. try:
  464. database = sqlite3.connect(conf.dbpath)
  465. cursor = database.cursor()
  466. except sqlite3.OperationalError:
  467. printf(_("Could not access the database, please check "
  468. "path and permissions and try again!"),
  469. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  470. else:
  471. subscriptionselect = "SELECT title from subscriptions where id=?"
  472. cursor.execute(subscriptionselect, (options.catchup,))
  473. sub_data = cursor.fetchall()
  474. if sub_data != []:
  475. catchup_sql = "UPDATE videos SET downloaded = 1 WHERE subscription_id =?"
  476. cursor.execute(catchup_sql, (options.catchup,))
  477. database.commit()
  478. database.close()
  479. else:
  480. printf(_("Subscription could not be updated, "
  481. "please check if the ID given is correct"),
  482. outputlevel="default", level=conf.outputlevel, descriptor="stderr")
  483. elif options.cleanup is True:
  484. subscriptions_list = []
  485. try:
  486. database = sqlite3.connect(conf.dbpath)
  487. cursor = database.cursor()
  488. except sqlite3.OperationalError:
  489. printf(_("Could not access the database, please check path and "
  490. "permissions and try again!"), outputlevel="default",
  491. level=conf.outputlevel, descriptor="stderr")
  492. else:
  493. cursor.execute("SELECT id,title,type,name,searchstring,directory \
  494. FROM subscriptions")
  495. subscriptions = cursor.fetchall()
  496. database.close()
  497. for element in subscriptions:
  498. subscriptions_list.append(subscription.sub(id=element[0],
  499. title=element[1], type=element[2], name=element[3],
  500. search=element[4], directory=element[5], conf=conf))
  501. for element in subscriptions_list:
  502. element.CheckAndDelete()
  503. try:
  504. database = sqlite3.connect(conf.dbpath)
  505. cursor = database.cursor()
  506. except sqlite3.OperationalError:
  507. printf(_("Could not access the database, please check path and "
  508. "permissions and try again!"), outputlevel="default",
  509. level=conf.outputlevel, descriptor="stderr")
  510. else:
  511. cursor.execute("VACUUM")
  512. database.close()
  513. elif options.license is True:
  514. printf("""
  515. stov is free software: you can redistribute it and/or modify
  516. it under the terms of the GNU General Public License as published by
  517. the Free Software Foundation, version 2 of the License.
  518. stov is distributed in the hope that it will be useful,
  519. but WITHOUT ANY WARRANTY; without even the implied warranty of
  520. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  521. GNU General Public License for more details.
  522. You should have received a copy of the GNU General Public License
  523. along with stov. If not, see <http://www.gnu.org/licenses/>.
  524. """, outputlevel="default", level=conf.outputlevel, descriptor="stdout")
  525. elif options.version is True:
  526. printf("0.4wip", outputlevel="default", level=conf.outputlevel,
  527. descriptor="stdout")
  528. else:
  529. parser.print_help()
  530. """Remove the lock file and end the program so it can be run again"""
  531. try:
  532. os.remove("/tmp/stov.lock")
  533. if exit_status is True:
  534. sys.exit(0)
  535. else:
  536. sys.exit(1)
  537. except os.error:
  538. printf(_("Could not delete the lock file. Please check what "
  539. "went wrong and clean up manually!"),
  540. outputlevel="default", level=conf.outputlevel, descriptor="stderr")