1
0

stov.py 22 KB

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