Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cad254be6d
Fetching contributors…

Cannot retrieve contributors at this time

executable file 99 lines (78 sloc) 2.752 kb
#!/usr/bin/env python
# pastie - a simple clipboard manager
# Copyright (C) 2010 Felipe Morales <hel.sheep@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import getopt
import gettext
import os
import os.path
import shutil
import glib
import gtk
import pastielib.cli as cli
import pastielib.protector as protector
def migrate_data_to_xdg_dirs():
# migrate history
old_history_file = os.path.expanduser('~/.clipboard_history')
pastie_data_dir = os.path.join(glib.get_user_data_dir(), 'pastie/')
history_file = os.path.join(pastie_data_dir, 'clipboard_history')
if os.path.isdir(pastie_data_dir):
# XDG data dir already exists
return
if not os.path.isfile(old_history_file):
# old history file didn't exists, but the directory so the history file
# can be created
os.mkdir(pastie_data_dir)
return
os.mkdir(pastie_data_dir)
shutil.copy2(old_history_file, history_file)
def migrate_config_to_xdg_dirs():
# migrate icon
pastie_config_dir = os.path.join(glib.get_user_config_dir(), 'pastie/')
old_pastie_dir = os.path.expanduser('~/.pastie/')
# check if XDG dirs already exists
if os.path.isdir(pastie_config_dir):
return
if not os.path.isdir(old_pastie_dir):
# old pastie dir didn't exists
return
shutil.copytree(old_pastie_dir, pastie_config_dir)
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], 'p')
except:
sys.exit(2)
# if the argument "-p" is passed, print the current clipboard contents, and exit
for o, a in opts:
if o == "-p":
cli.print_current()
sys.exit()
else:
assert False, "unhandled option"
migrate_data_to_xdg_dirs()
migrate_config_to_xdg_dirs()
# if we pipe the output of another program to pastie, it sets it as the current clipboard
if not sys.stdin.isatty():
text = sys.stdin.read()
if text not in ("", None):
cli.add_to_history(text)
sys.stdout.write(text)
sys.exit()
# load translations
gettext.install("pastie", "/usr/share/locale")
# create clipboard protector (this is the core of the program)
clipboard_protector = protector.ClipboardProtector()
gtk.main()
Jump to Line
Something went wrong with that request. Please try again.