stov 22 KB

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