Permalink
Browse files

Ladies and Gentlemen, please welcome Trashman!

  • Loading branch information...
1 parent 550f323 commit ed480e986aa66029d244e2d754ed6739fe09dc01 @Kwpolska committed Aug 10, 2012
Showing with 293 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +30 −0 LICENSE
  3. +20 −0 PKGBUILD
  4. +45 −0 README.rst
  5. +47 −0 release
  6. +28 −0 setup.py
  7. +122 −0 trashman
View
@@ -0,0 +1 @@
+Kwpolska <kwpolska@kwpolska.tk>
View
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (C) 2011-2012, Kwpolska.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions, and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the author of this software nor the names of
+ contributors to this software may be used to endorse or promote
+ products derived from this software without specific prior written
+ consent.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,20 @@
+# Maintainer: Kwpolska <kwpolska@kwpolska.tk>
+pkgname=trashman
+pkgver=0.1
+pkgrel=1
+pkgdesc='A Python XDG trash manager. (built under py3k)'
+arch=('any')
+url='https://github.com/Kwpolska/pkgbuilder'
+license=('BSD')
+depends=('python')
+options=(!emptydirs)
+source=("http://pypi.python.org/packages/source/t/${pkgname}/${pkgname}-${pkgver}.tar.gz")
+md5sums=('57277dac6069785176c95cc818f7a8af')
+
+package() {
+ cd "${srcdir}/${pkgname}-${pkgver}"
+ python setup.py install --root="${pkgdir}/" --optimize=1
+ install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
+}
+
+# vim:set ts=2 sw=2 et:
View
@@ -0,0 +1,45 @@
+============================================
+Trashman. Removing files from console v2.0.
+============================================
+
+PURPOSE
+-------
+This is a simple trash script. It can move files to the trash, empty it and
+list its contents.
+
+INSTALLATION
+------------
+Run ./setup.py.
+
+COPYRIGHT
+---------
+Copyright (C) 2011-2012, Kwpolska.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions, and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the author of this software nor the names of
+ contributors to this software may be used to endorse or promote
+ products derived from this software without specific prior written
+ consent.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
47 release
@@ -0,0 +1,47 @@
+#!/bin/zsh
+project="trashman"
+aurcat="system"
+
+version=$1
+if [[ $version = '' ]]; then
+ echo 'Version number?'
+ echo -n '> '
+ read version
+fi
+
+date=$(date '+%Y-%m-%d')
+datel=$(date '+%Y-%m-%d %H:%M%z')
+
+sed "s/version=.*/version='$version',/" setup.py -i
+sed "s/__version__ = .*/__version__ = '$version'/" trashman -i
+sed "s/pkgver=.*/pkgver=$version/" PKGBUILD -i
+
+rm -rf trashman.egg-info __pycache__ trashman/__pycache__
+
+./setup.py sdist upload
+
+md5out=$(md5sum 'dist/'$project'-'$version'.tar.gz'|awk '{print $1}')
+sed "s/md5sums=.*/md5sums=('$md5out')/" PKGBUILD -i
+rm -rf MKPKGBUILD
+mkdir -p MKPKGBUILD/$project
+cp PKGBUILD MKPKGBUILD/$project
+cd MKPKGBUILD
+tar -czvf trashman.src.tar.gz trashman
+burp -u Kwpolska -c system trashman.src.tar.gz
+cd ..
+rm -rf MKPKGBUILD
+
+echo 'Commit message (sans the version?)'
+echo -n '> '
+read commitmsg
+
+rm -rf trashman.egg-info __pycache__ trashman/__pycache__
+
+git add *
+if [[ $2 = '-c' ]]; then
+ git commit -as
+else
+ git commit -asm "v$version: $commitmsg"
+fi
+git tag -a "v$version" -m "Version $version"
+git push --tags
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+#from distutils.core import setup
+
+setup(name='trashman',
+ version='0.1',
+ description='A python XDG trash manager.',
+ author='Kwpolska',
+ author_email='kwpolska@kwpolska.tk',
+ url='https://github.com/Kwpolska/trashman',
+ license='3-clause BSD',
+ long_description=open('README.rst').read(),
+ platforms='Arch Linux',
+ classifiers=['Development Status :: 5 - Production/Stable',
+ 'Environment :: Console',
+ 'Intended Audience :: End Users/Desktop',
+ 'License :: OSI Approved :: BSD License',
+ 'Natural Language :: English',
+ 'Operating System :: POSIX :: Linux',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 3',
+ 'Topic :: Utilities'],
+ scripts=['trashman'])
View
122 trashman
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+# Trashman
+# Copyright (C) 2011-2012, Kwpolska.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions, and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# 3. Neither the name of the author of this software nor the names of
+# contributors to this software may be used to endorse or promote
+# products derived from this software without specific prior written
+# consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import shutil
+import os
+import subprocess
+import datetime
+import sys
+import argparse
+
+ktdirectory = os.path.expanduser("~/.local/share/Trash")
+__title__ = 'Trashman'
+__version__ = '0.1'
+__author__ = 'Kwpolska'
+__license__ = '3-clause BSD'
+
+
+def createTrash():
+ if not os.path.exists(ktdirectory):
+ os.mkdir(ktdirectory)
+ os.mkdir(ktdirectory + '/files')
+ os.mkdir(ktdirectory + '/info')
+ infofile = '[Cached]\nSize=0'
+ open(ktdirectory + '/metadata', "w").write(infofile)
+
+
+def emptyTrash(verbose):
+ """Empties the trash."""
+ shutil.rmtree(ktdirectory + '/files')
+ shutil.rmtree(ktdirectory + '/info')
+ createTrash()
+ if verbose:
+ sys.stderr.write("emptied the trash\n")
+
+
+def listFiles():
+ """Lists the trash contents (using /bin/ls)."""
+ subprocess.call('/bin/ls -CF --color=auto ' + ktdirectory + '/files',
+ shell=True)
+
+
+def moveToTrash(filename, verbose):
+ """Moves specified files to trash."""
+ os.rename(filename, ktdirectory + '/files/' + os.path.basename(filename))
+ infofile = '[Trash \
+Info]\nPath={0}\nDeletionDate={1}'.format(os.path.realpath(filename),
+ (datetime.datetime.now()
+ .strftime('%Y-%m-%dT%H:%m:%S')))
+ open(ktdirectory + '/info/' + os.path.basename(filename) + '.trashinfo',
+ 'w').write(infofile)
+
+ if verbose:
+ sys.stderr.write("trashed ‘{0}\n".format(filename))
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description="Trashman – a simple \
+ trash script.")
+ parser.add_argument('-v', '--verbose', action='store_true', default=False,
+ dest='verbose', help="print more info")
+ parser.add_argument('-e', '--empty', action='store_true', default=False,
+ dest='empty', help="empty the trash and exit")
+ parser.add_argument('-l', '--list', action='store_true', default=False,
+ dest='flist', help="list the files in trash and exit")
+ parser.add_argument('-V', '--version', action='version',
+ version='Trashman v' + __version__)
+ parser.add_argument('files', metavar="FILE", action='store', nargs='*',
+ help="files to remove")
+ args = parser.parse_args()
+
+ shallExit = False
+
+ if not os.path.exists(ktdirectory):
+ sys.stderr.write("{0}” does not exist, creating...".format(
+ ktdirectory))
+ createTrash()
+
+ if args.flist:
+ listFiles()
+ shallExit = True
+
+ if args.empty:
+ emptyTrash(args.verbose)
+ shallExit = True
+
+ if shallExit:
+ exit()
+
+ # Did not exit? Let's trash the files, shan’t we?
+ for filename in args.files:
+ moveToTrash(filename, args.verbose)

0 comments on commit ed480e9

Please sign in to comment.