Module: PasteHub

Defined in:
lib/pastehub/util.rb,
lib/pastehub/client.rb,
lib/pastehub/config.rb,
lib/pastehub/clipboard.rb,
lib/pastehub/syncentry.rb,
lib/pastehub/clientsync.rb

Defined Under Namespace

Classes: AbstractClipboard, ClientSync, Config, Entry, EntryBase, Status, Util

Class Method Summary collapse

Class Method Details

.hostnameObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/pastehub/client.rb', line 60

def self.hostname( )
  hostname = open( "|hostname" ) { |f| 
    f.read.chomp
  }
  if 0 < hostname.size()
    hostname
  else
    raise RuntimeError, "Can't resolve hostname"
  end
end

.loadPidObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pastehub/client.rb', line 78

def self.loadPid
  pidFile = PasteHub::Config.instance.localDbPath + "pid"
  pid = 0
  begin
    pid = open( pidFile ) {|f|
      f.readline.chomp.to_i
    }
  rescue Exception => e
    STDERR.puts( "Warning: can't load #{pidFile}: #{e.to_s}" )
    pid = 0
  end
  return pid
end

.savePid(pid) ⇒ Object



71
72
73
74
75
76
# File 'lib/pastehub/client.rb', line 71

def self.savePid( pid )
  pidFile = PasteHub::Config.instance.localDbPath + "pid"
  open( pidFile, "w" ) {|f|
    f.puts pid
  }
end

.setupDirectoryObject

setup user’s directory and sync directory

result: true ... success / false ... fail


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pastehub/client.rb', line 45

def self.setupDirectory
  localdb_path   = PasteHub::Config.instance.localDbPath
  localsync_path = PasteHub::Config.instance.localSyncPath
  # Create directory
  if not File.exist?(  localdb_path )
    FileUtils.mkdir_p( localdb_path, { :mode => 0700 } )
  end

  # Create directory for Sync
  if not File.exist?(  localsync_path )
    FileUtils.mkdir_p( localsync_path, { :mode => 0700 } )
  end
  return true
end