From 7feab564bbbfa7afc867446a1e56623f5f05e8e6 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 20 Jul 2002 13:56:05 +0000 Subject: [PATCH] Removed old files. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/Archive@1733 66de3db3-b00d-0410-b41b-f4738ad19bea --- v1/Archive.py | 309 ---------------------------------------------------------- v1/main.py | 13 --- v2/Archive.py | 304 --------------------------------------------------------- v2/main.py | 13 --- 4 files changed, 639 deletions(-) delete mode 100644 v1/Archive.py delete mode 100644 v1/main.py delete mode 100644 v2/Archive.py delete mode 100644 v2/main.py diff --git a/v1/Archive.py b/v1/Archive.py deleted file mode 100644 index 19fb829..0000000 --- a/v1/Archive.py +++ /dev/null @@ -1,309 +0,0 @@ -import os.path -import re -import stat -import os -import signal -import fcntl - -from gtk import * -from GDK import * - -from rox.SaveBox import SaveBox -from rox import support -from rox import choices -import string - -child_pid = None - -from formats import * - -def esc(text): - """Return text with \ and ' escaped""" - return re.sub("'", "'\"'\"'", text) - -def bg_system(command, out = None): - "system(command), but still process GUI events while waiting..." - "If 'out' is set then the child's stdout goes to that FD. 'out' is " - "closed in the parent process." - global child_pid - - (r, w) = os.pipe() - - child_pid = fork() - if child_pid == -1: - os.close(r) - os.close(w) - if out != None: - os.close(out) - support.report_error("fork() failed!") - return 127 - if child_pid == 0: - # Child - try: - if out != None: - os.dup2(out, 1) - - # Collect stderr... - if w != 2: - os.dup2(w, 2) - os.close(w) - - os.setpgid(0, 0) # Start a new process group - - os.close(r) - - error = os.system(command) != 0 - os._exit(error) - except: - pass - os._exit(127) - - if out != None: - os.close(out) - os.close(w) - - done = [""] - def cb(src, cond, done = done): - data = os.read(src, 100) - if data: - done[0] = done[0] + data - else: - done.append(1) - tag = input_add(r, INPUT_READ, cb) - - while len(done) < 2: - mainiteration() - - input_remove(tag) - - os.close(r) - (pid, status) = os.waitpid(child_pid, 0) - child_pid = None - - str = string.strip(done[0]) - if status or str: - if str: - support.report_error("Error: " + str) - else: - support.report_error("Operation failed") - - return status - -def make_archiver(path): - while path[-1:] == '/': - path = path[:-1] - if os.path.isdir(path): - window = ArchiveDir(path) - else: - window = None - f = get_format(path, archive_formats) - if f: - window = ExtractDir(path, f) - else: - f = get_format(path, compressed_formats) - if f: - window = ExtractFile(path, f) - else: - window = ArchiveFile(path) - - window.connect('destroy', lambda w: support.rox_toplevel_unref()) - support.rox_toplevel_ref() - window.show() - -def pull_up(dir): - "If dir contains only one subdir, move its contents into dir." - list = os.listdir(dir) - if len(list) != 1: - return - - subdir = os.path.join(dir, list[0]) - if not os.path.isdir(subdir): - return - - tmp = '' - try: - tmp = os.tempnam(dir) - os.rename(subdir, tmp) - subdir = tmp - except: - print "Warning: failed to rename(%s, %s)\n" % (subdir, tmp) - - for file in os.listdir(subdir): - bg_system("mv '%s' ." % esc(os.path.join(subdir, file))) - os.rmdir(subdir) - -def report_known(formats): - txt = "Allowed extensions are:\n" - for f in formats: - if f[2]: - txt = txt + f[0] + '\n' - support.report_error(txt) - -from os import _exit, fork, execvp, dup2 - -def child(*argv): - """Spawn a new process. Connect stderr to stdout.""" - child = fork() - if child == 0: - # We are the child - try: - dup2(1, 2) - execvp(argv[0], argv) - except: - pass - print "Warning: exec('%s') failed!" % argv[0] - _exit(1) - elif child == -1: - print "Error: fork() failed!" - -class Archive(SaveBox): - def __init__(self, win, type): - SaveBox.__init__(self, self, self.uri, type); - self.connect('destroy', self.destroyed) - - if not hasattr(self, 'changed'): - return - if hasattr(self, 'set_type'): - self.save_area.entry.connect('changed', self.changed) - else: - print "(a newer version of ROX-Lib would be nice)" - - def destroyed(self, widget): - global child_pid - - if child_pid: - os.kill(-child_pid, signal.SIGTERM) - - def save_as_file(self, path): - self.set_sensitive(FALSE) - success = FALSE - try: - success = self.do_save(path) - except: - success = FALSE - support.report_exception() - self.set_sensitive(TRUE); - return success - - def set_uri(self, uri): - path = support.get_local_path(uri) - if path: - child('rox', '-x', path) - pass - -# save_as(path) - write data to file, TRUE on success -# set_uri(uri) - data is safely saved to this location - -class ExtractDir(Archive): - def __init__(self, path, format): - self.path = path - ext = format[0] - self.extract = format[1] - uri = path[:-len(ext)] - import re - found = re.match(r'^(.*)-(\d+\.)*\d+$', uri) - if found: - self.uri = found.group(1) - else: - self.uri = uri - Archive.__init__(self, self, 'special/directory') - - def do_save(self, path): - os.mkdir(path) - os.chdir(path) - if bg_system(self.extract % esc(self.path)): - return FALSE - else: - pull_up(path) - return TRUE - -class ExtractFile(Archive): - def __init__(self, path, format): - self.path = path - ext = format[0] - self.extract = format[1] - self.uri = path[:-len(ext)] - Archive.__init__(self, self, 'text/plain') - - def do_save(self, path): - if os.path.exists(path): - support.report_error("File `%s' already exists!" % path) - return FALSE - stats = os.stat(self.path) - mode = stat.S_IMODE(stats[stat.ST_MODE]) & 0x1ff; - out = os.open(path, os.O_WRONLY | os.O_CREAT, mode) - return bg_system(self.extract % esc(self.path), out = out) == 0 - - def save_as_selection(self, selection_data): - (r, w) = os.pipe() - self.data = "" - - def cb(src, cond, self = self): - self.data = self.data + os.read(src, 1024) - input_add(r, INPUT_READ, cb) - - bg_system(self.extract % esc(self.path), out = w) - - while 1: - new = os.read(r, 1024) - if not new: - break - self.data = self.data + new - os.close(r) - selection_data.set(selection_data.target, 8, self.data) - self.data = "" - -class ArchiveFile(Archive): - def __init__(self, path): - self.path = path - self.uri = path + '.gz' - Archive.__init__(self, self, 'application/x-gzip') - - def do_save(self, path): - format = get_format(path, compressed_formats) - if not format or not format[2]: - report_known(compressed_formats) - return FALSE - - if os.path.exists(path): - support.report_error("File `%s' already exists!" % path) - return FALSE - stats = os.stat(self.path) - mode = stat.S_IMODE(stats[stat.ST_MODE]) & 0x1ff; - out = os.open(path, os.O_WRONLY | os.O_CREAT, mode) - return bg_system(format[2] % esc(self.path), out = out) == 0 - - def changed(self, entry): - path = entry.get_text() - format = get_format(path, compressed_formats) - if not format: - self.set_type('error/unknown') - return - self.set_type(format[3]) - -class ArchiveDir(Archive): - def __init__(self, path): - self.path = path - self.uri = path + '.tgz' - Archive.__init__(self, self, 'application/x-compressed-tar') - - def do_save(self, path): - format = get_format(path, archive_formats) - if not format or not format[2]: - report_known(archive_formats) - return FALSE - - os.chdir(os.path.dirname(self.uri)) - retval = bg_system(format[2] % { - 'src' : esc(os.path.basename(self.path)), - 'dst' : esc(path) - }) - return retval == 0 - - def changed(self, entry): - path = entry.get_text() - format = get_format(path, archive_formats) - if (not format) or not format[2]: - self.set_type('error/unknown') - return - self.set_type(format[3]) diff --git a/v1/main.py b/v1/main.py deleted file mode 100644 index 0b32a0e..0000000 --- a/v1/main.py +++ /dev/null @@ -1,13 +0,0 @@ -import sys, gtk -from rox import support - -if len(sys.argv) != 2: - support.report_error( - "Drag a file or directory onto Archive to archive it. " + - "Drag an archive onto it to extract.") -else: - import Archive - Archive.make_archiver(sys.argv[1]) - -support.rox_toplevel_unref() -support.rox_mainloop() diff --git a/v2/Archive.py b/v2/Archive.py deleted file mode 100644 index 722ce4c..0000000 --- a/v2/Archive.py +++ /dev/null @@ -1,304 +0,0 @@ -import os.path -import re -import stat -import os -import signal -import fcntl - -import gtk -from gtk import TRUE, FALSE - -from rox2.SaveBox import SaveBox -from rox2 import support -from rox2 import choices -import string - -child_pid = None - -from formats import * - -def esc(text): - """Return text with \ and ' escaped""" - return re.sub("'", "'\"'\"'", text) - -def bg_system(command, out = None): - "system(command), but still process GUI events while waiting..." - "If 'out' is set then the child's stdout goes to that FD. 'out' is " - "closed in the parent process." - global child_pid - - (r, w) = os.pipe() - - child_pid = fork() - if child_pid == -1: - os.close(r) - os.close(w) - if out != None: - os.close(out) - support.report_error("fork() failed!") - return 127 - if child_pid == 0: - # Child - try: - if out != None: - os.dup2(out, 1) - - # Collect stderr... - if w != 2: - os.dup2(w, 2) - os.close(w) - - os.setpgid(0, 0) # Start a new process group - - os.close(r) - - error = os.system(command) != 0 - os._exit(error) - except: - pass - os._exit(127) - - if out != None: - os.close(out) - os.close(w) - - done = [""] - def cb(src, cond, done = done): - data = os.read(src, 100) - if data: - done[0] = done[0] + data - else: - done.append(1) - tag = gtk.input_add_full(r, gtk.gdk.INPUT_READ, cb) - - while len(done) < 2: - gtk.mainiteration() - - gtk.input_remove(tag) - - os.close(r) - (pid, status) = os.waitpid(child_pid, 0) - child_pid = None - - str = string.strip(done[0]) - if status or str: - if str: - support.report_error("Error: " + str) - else: - support.report_error("Operation failed") - - return status - -def make_archiver(path): - while path[-1:] == '/': - path = path[:-1] - if os.path.isdir(path): - window = ArchiveDir(path) - else: - window = None - f = get_format(path, archive_formats) - if f: - window = ExtractDir(path, f) - else: - f = get_format(path, compressed_formats) - if f: - window = ExtractFile(path, f) - else: - window = ArchiveFile(path) - - window.show() - -def pull_up(dir): - "If dir contains only one subdir, move its contents into dir." - list = os.listdir(dir) - if len(list) != 1: - return - - subdir = os.path.join(dir, list[0]) - if not os.path.isdir(subdir): - return - - tmp = '' - try: - tmp = os.tempnam(dir) - os.rename(subdir, tmp) - subdir = tmp - except: - print "Warning: failed to rename(%s, %s)\n" % (subdir, tmp) - - for file in os.listdir(subdir): - bg_system("mv '%s' ." % esc(os.path.join(subdir, file))) - os.rmdir(subdir) - -def report_known(formats): - txt = "Allowed extensions are:\n" - for f in formats: - if f[2]: - txt = txt + f[0] + '\n' - support.report_error(txt) - -from os import _exit, fork, execvp, dup2 - -def child(*argv): - """Spawn a new process. Connect stderr to stdout.""" - child = fork() - if child == 0: - # We are the child - try: - dup2(1, 2) - execvp(argv[0], argv) - except: - pass - print "Warning: exec('%s') failed!" % argv[0] - _exit(1) - elif child == -1: - print "Error: fork() failed!" - -class Archive(SaveBox): - def __init__(self, win, type): - SaveBox.__init__(self, self, self.uri, type); - self.connect('destroy', self.destroyed) - - if not hasattr(self, 'changed'): - return - self.save_area.entry.connect('changed', self.changed) - - def destroyed(self, widget): - global child_pid - - if child_pid: - os.kill(-child_pid, signal.SIGTERM) - - def save_as_file(self, path): - self.set_sensitive(FALSE) - success = FALSE - try: - success = self.do_save(path) - except: - success = FALSE - support.report_exception() - self.set_sensitive(TRUE); - return success - - def set_uri(self, uri): - path = support.get_local_path(uri) - if path: - child('rox', '-x', path) - pass - -# save_as(path) - write data to file, TRUE on success -# set_uri(uri) - data is safely saved to this location - -class ExtractDir(Archive): - def __init__(self, path, format): - self.path = path - ext = format[0] - self.extract = format[1] - uri = path[:-len(ext)] - import re - found = re.match(r'^(.*)-(\d+\.)*\d+$', uri) - if found: - self.uri = found.group(1) - else: - self.uri = uri - Archive.__init__(self, self, 'special/directory') - - def do_save(self, path): - os.mkdir(path) - os.chdir(path) - if bg_system(self.extract % esc(self.path)): - return FALSE - else: - pull_up(path) - return TRUE - -class ExtractFile(Archive): - def __init__(self, path, format): - self.path = path - ext = format[0] - self.extract = format[1] - self.uri = path[:-len(ext)] - Archive.__init__(self, self, 'text/plain') - - def do_save(self, path): - if os.path.exists(path): - support.report_error("File `%s' already exists!" % path) - return FALSE - stats = os.stat(self.path) - mode = stat.S_IMODE(stats[stat.ST_MODE]) & 0x1ff; - out = os.open(path, os.O_WRONLY | os.O_CREAT, mode) - return bg_system(self.extract % esc(self.path), out = out) == 0 - - def save_as_selection(self, selection_data): - (r, w) = os.pipe() - self.data = "" - - def cb(src, cond, self = self): - self.data = self.data + os.read(src, 1024) - gtk.input_add_full(r, gtk.gdk.INPUT_READ, cb) - - bg_system(self.extract % esc(self.path), out = w) - - while 1: - new = os.read(r, 1024) - if not new: - break - self.data = self.data + new - os.close(r) - selection_data.set(selection_data.target, 8, self.data) - self.data = "" - -class ArchiveFile(Archive): - def __init__(self, path): - self.path = path - self.uri = path + '.gz' - Archive.__init__(self, self, 'application/x-gzip') - - def do_save(self, path): - format = get_format(path, compressed_formats) - if not format or not format[2]: - report_known(compressed_formats) - return FALSE - - if os.path.exists(path): - support.report_error("File `%s' already exists!" % path) - return FALSE - stats = os.stat(self.path) - mode = stat.S_IMODE(stats[stat.ST_MODE]) & 0x1ff; - out = os.open(path, os.O_WRONLY | os.O_CREAT, mode) - return bg_system(format[2] % esc(self.path), out = out) == 0 - - def changed(self, entry): - path = entry.get_text() - format = get_format(path, compressed_formats) - if not format: - self.set_type('error/unknown') - return - self.set_type(format[3]) - -class ArchiveDir(Archive): - def __init__(self, path): - self.path = path - self.uri = path + '.tgz' - Archive.__init__(self, self, 'application/x-compressed-tar') - - def do_save(self, path): - format = get_format(path, archive_formats) - if not format or not format[2]: - report_known(archive_formats) - return FALSE - - os.chdir(os.path.dirname(self.uri)) - retval = bg_system(format[2] % { - 'src' : esc(os.path.basename(self.path)), - 'dst' : esc(path) - }) - return retval == 0 - - def changed(self, entry): - path = entry.get_text() - format = get_format(path, archive_formats) - if (not format) or not format[2]: - self.set_type('error/unknown') - return - self.set_type(format[3]) diff --git a/v2/main.py b/v2/main.py deleted file mode 100644 index 125531e..0000000 --- a/v2/main.py +++ /dev/null @@ -1,13 +0,0 @@ -import sys, gtk -from rox2 import support - -if len(sys.argv) != 2: - support.alert( - "Drag a file or directory onto Archive to archive it. " + - "Drag an archive onto it to extract.", - type = gtk.MESSAGE_INFO) -else: - import Archive - Archive.make_archiver(sys.argv[1]) - -support.mainloop_with_refcount() -- 2.11.4.GIT